aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/external-auth.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/plugins/external-auth.ts')
-rw-r--r--server/tests/plugins/external-auth.ts57
1 files changed, 29 insertions, 28 deletions
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index f7cee588a..e421fd224 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -9,14 +9,10 @@ import {
9 decodeQueryString, 9 decodeQueryString,
10 flushAndRunServer, 10 flushAndRunServer,
11 getMyUserInformation, 11 getMyUserInformation,
12 loginUsingExternalToken,
13 logout,
14 PluginsCommand, 12 PluginsCommand,
15 refreshToken,
16 ServerInfo, 13 ServerInfo,
17 setAccessTokensToServers, 14 setAccessTokensToServers,
18 updateMyUser, 15 updateMyUser,
19 userLogin,
20 wait 16 wait
21} from '@shared/extra-utils' 17} from '@shared/extra-utils'
22import { User, UserRole } from '@shared/models' 18import { User, UserRole } from '@shared/models'
@@ -43,12 +39,11 @@ async function loginExternal (options: {
43 const location = res.header.location 39 const location = res.header.location
44 const { externalAuthToken } = decodeQueryString(location) 40 const { externalAuthToken } = decodeQueryString(location)
45 41
46 const resLogin = await loginUsingExternalToken( 42 const resLogin = await options.server.loginCommand.loginUsingExternalToken({
47 options.server, 43 username: options.username,
48 options.username, 44 externalAuthToken: externalAuthToken as string,
49 externalAuthToken as string, 45 expectedStatus: options.statusCodeExpectedStep2
50 options.statusCodeExpectedStep2 46 })
51 )
52 47
53 return resLogin.body 48 return resLogin.body
54} 49}
@@ -110,13 +105,17 @@ describe('Test external auth plugins', function () {
110 }) 105 })
111 106
112 it('Should reject auto external login with a missing or invalid token', async function () { 107 it('Should reject auto external login with a missing or invalid token', async function () {
113 await loginUsingExternalToken(server, 'cyan', '', HttpStatusCode.BAD_REQUEST_400) 108 const command = server.loginCommand
114 await loginUsingExternalToken(server, 'cyan', 'blabla', HttpStatusCode.BAD_REQUEST_400) 109
110 await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
111 await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
115 }) 112 })
116 113
117 it('Should reject auto external login with a missing or invalid username', async function () { 114 it('Should reject auto external login with a missing or invalid username', async function () {
118 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) 115 const command = server.loginCommand
119 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) 116
117 await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
118 await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
120 }) 119 })
121 120
122 it('Should reject auto external login with an expired token', async function () { 121 it('Should reject auto external login with an expired token', async function () {
@@ -124,7 +123,11 @@ describe('Test external auth plugins', function () {
124 123
125 await wait(5000) 124 await wait(5000)
126 125
127 await loginUsingExternalToken(server, 'cyan', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) 126 await server.loginCommand.loginUsingExternalToken({
127 username: 'cyan',
128 externalAuthToken,
129 expectedStatus: HttpStatusCode.BAD_REQUEST_400
130 })
128 131
129 await server.serversCommand.waitUntilLog('expired external auth token', 2) 132 await server.serversCommand.waitUntilLog('expired external auth token', 2)
130 }) 133 })
@@ -182,7 +185,7 @@ describe('Test external auth plugins', function () {
182 185
183 it('Should refresh Cyan token, but not Kefka token', async function () { 186 it('Should refresh Cyan token, but not Kefka token', async function () {
184 { 187 {
185 const resRefresh = await refreshToken(server, cyanRefreshToken) 188 const resRefresh = await server.loginCommand.refreshToken({ refreshToken: cyanRefreshToken })
186 cyanAccessToken = resRefresh.body.access_token 189 cyanAccessToken = resRefresh.body.access_token
187 cyanRefreshToken = resRefresh.body.refresh_token 190 cyanRefreshToken = resRefresh.body.refresh_token
188 191
@@ -192,7 +195,7 @@ describe('Test external auth plugins', function () {
192 } 195 }
193 196
194 { 197 {
195 await refreshToken(server, kefkaRefreshToken, HttpStatusCode.BAD_REQUEST_400) 198 await server.loginCommand.refreshToken({ refreshToken: kefkaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
196 } 199 }
197 }) 200 })
198 201
@@ -212,7 +215,7 @@ describe('Test external auth plugins', function () {
212 }) 215 })
213 216
214 it('Should logout Cyan', async function () { 217 it('Should logout Cyan', async function () {
215 await logout(server.url, cyanAccessToken) 218 await server.loginCommand.logout({ token: cyanAccessToken })
216 }) 219 })
217 220
218 it('Should have logged out Cyan', async function () { 221 it('Should have logged out Cyan', async function () {
@@ -269,7 +272,7 @@ describe('Test external auth plugins', function () {
269 settings: { disableKefka: true } 272 settings: { disableKefka: true }
270 }) 273 })
271 274
272 await userLogin(server, { username: 'kefka', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400) 275 await server.loginCommand.login({ user: { username: 'kefka', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
273 276
274 await loginExternal({ 277 await loginExternal({
275 server, 278 server,
@@ -307,9 +310,9 @@ describe('Test external auth plugins', function () {
307 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 310 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
308 }) 311 })
309 312
310 await userLogin(server, { username: 'cyan', password: null }, HttpStatusCode.BAD_REQUEST_400) 313 await server.loginCommand.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
311 await userLogin(server, { username: 'cyan', password: '' }, HttpStatusCode.BAD_REQUEST_400) 314 await server.loginCommand.login({ user: { username: 'cyan', password: '' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
312 await userLogin(server, { username: 'cyan', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400) 315 await server.loginCommand.login({ user: { username: 'cyan', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
313 }) 316 })
314 317
315 it('Should not login kefka with another plugin', async function () { 318 it('Should not login kefka with another plugin', async function () {
@@ -369,9 +372,8 @@ describe('Test external auth plugins', function () {
369 username: 'cid' 372 username: 'cid'
370 }) 373 })
371 374
372 const resLogout = await logout(server.url, resLogin.access_token) 375 const { redirectUrl } = await server.loginCommand.logout({ token: resLogin.access_token })
373 376 expect(redirectUrl).to.equal('https://example.com/redirectUrl')
374 expect(resLogout.body.redirectUrl).to.equal('https://example.com/redirectUrl')
375 }) 377 })
376 378
377 it('Should call the plugin\'s onLogout method with the request', async function () { 379 it('Should call the plugin\'s onLogout method with the request', async function () {
@@ -382,8 +384,7 @@ describe('Test external auth plugins', function () {
382 username: 'cid' 384 username: 'cid'
383 }) 385 })
384 386
385 const resLogout = await logout(server.url, resLogin.access_token) 387 const { redirectUrl } = await server.loginCommand.logout({ token: resLogin.access_token })
386 388 expect(redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token)
387 expect(resLogout.body.redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token)
388 }) 389 })
389}) 390})