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.ts66
1 files changed, 33 insertions, 33 deletions
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index 3e8305611..48f942f7f 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -23,7 +23,7 @@ async function loginExternal (options: {
23 statusCodeExpected?: HttpStatusCode 23 statusCodeExpected?: HttpStatusCode
24 statusCodeExpectedStep2?: HttpStatusCode 24 statusCodeExpectedStep2?: HttpStatusCode
25}) { 25}) {
26 const res = await options.server.pluginsCommand.getExternalAuth({ 26 const res = await options.server.plugins.getExternalAuth({
27 npmName: options.npmName, 27 npmName: options.npmName,
28 npmVersion: '0.0.1', 28 npmVersion: '0.0.1',
29 authName: options.authName, 29 authName: options.authName,
@@ -36,7 +36,7 @@ async function loginExternal (options: {
36 const location = res.header.location 36 const location = res.header.location
37 const { externalAuthToken } = decodeQueryString(location) 37 const { externalAuthToken } = decodeQueryString(location)
38 38
39 const resLogin = await options.server.loginCommand.loginUsingExternalToken({ 39 const resLogin = await options.server.login.loginUsingExternalToken({
40 username: options.username, 40 username: options.username,
41 externalAuthToken: externalAuthToken as string, 41 externalAuthToken: externalAuthToken as string,
42 expectedStatus: options.statusCodeExpectedStep2 42 expectedStatus: options.statusCodeExpectedStep2
@@ -63,12 +63,12 @@ describe('Test external auth plugins', function () {
63 await setAccessTokensToServers([ server ]) 63 await setAccessTokensToServers([ server ])
64 64
65 for (const suffix of [ 'one', 'two', 'three' ]) { 65 for (const suffix of [ 'one', 'two', 'three' ]) {
66 await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-external-auth-' + suffix) }) 66 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-external-auth-' + suffix) })
67 } 67 }
68 }) 68 })
69 69
70 it('Should display the correct configuration', async function () { 70 it('Should display the correct configuration', async function () {
71 const config = await server.configCommand.getConfig() 71 const config = await server.config.getConfig()
72 72
73 const auths = config.plugin.registeredExternalAuths 73 const auths = config.plugin.registeredExternalAuths
74 expect(auths).to.have.lengthOf(8) 74 expect(auths).to.have.lengthOf(8)
@@ -80,7 +80,7 @@ describe('Test external auth plugins', function () {
80 }) 80 })
81 81
82 it('Should redirect for a Cyan login', async function () { 82 it('Should redirect for a Cyan login', async function () {
83 const res = await server.pluginsCommand.getExternalAuth({ 83 const res = await server.plugins.getExternalAuth({
84 npmName: 'test-external-auth-one', 84 npmName: 'test-external-auth-one',
85 npmVersion: '0.0.1', 85 npmVersion: '0.0.1',
86 authName: 'external-auth-1', 86 authName: 'external-auth-1',
@@ -102,14 +102,14 @@ describe('Test external auth plugins', function () {
102 }) 102 })
103 103
104 it('Should reject auto external login with a missing or invalid token', async function () { 104 it('Should reject auto external login with a missing or invalid token', async function () {
105 const command = server.loginCommand 105 const command = server.login
106 106
107 await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 107 await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
108 await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 108 await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
109 }) 109 })
110 110
111 it('Should reject auto external login with a missing or invalid username', async function () { 111 it('Should reject auto external login with a missing or invalid username', async function () {
112 const command = server.loginCommand 112 const command = server.login
113 113
114 await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 114 await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
115 await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 115 await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
@@ -120,13 +120,13 @@ describe('Test external auth plugins', function () {
120 120
121 await wait(5000) 121 await wait(5000)
122 122
123 await server.loginCommand.loginUsingExternalToken({ 123 await server.login.loginUsingExternalToken({
124 username: 'cyan', 124 username: 'cyan',
125 externalAuthToken, 125 externalAuthToken,
126 expectedStatus: HttpStatusCode.BAD_REQUEST_400 126 expectedStatus: HttpStatusCode.BAD_REQUEST_400
127 }) 127 })
128 128
129 await server.serversCommand.waitUntilLog('expired external auth token', 2) 129 await server.servers.waitUntilLog('expired external auth token', 2)
130 }) 130 })
131 131
132 it('Should auto login Cyan, create the user and use the token', async function () { 132 it('Should auto login Cyan, create the user and use the token', async function () {
@@ -146,7 +146,7 @@ describe('Test external auth plugins', function () {
146 } 146 }
147 147
148 { 148 {
149 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) 149 const body = await server.users.getMyInfo({ token: cyanAccessToken })
150 expect(body.username).to.equal('cyan') 150 expect(body.username).to.equal('cyan')
151 expect(body.account.displayName).to.equal('cyan') 151 expect(body.account.displayName).to.equal('cyan')
152 expect(body.email).to.equal('cyan@example.com') 152 expect(body.email).to.equal('cyan@example.com')
@@ -168,7 +168,7 @@ describe('Test external auth plugins', function () {
168 } 168 }
169 169
170 { 170 {
171 const body = await server.usersCommand.getMyInfo({ token: kefkaAccessToken }) 171 const body = await server.users.getMyInfo({ token: kefkaAccessToken })
172 expect(body.username).to.equal('kefka') 172 expect(body.username).to.equal('kefka')
173 expect(body.account.displayName).to.equal('Kefka Palazzo') 173 expect(body.account.displayName).to.equal('Kefka Palazzo')
174 expect(body.email).to.equal('kefka@example.com') 174 expect(body.email).to.equal('kefka@example.com')
@@ -178,39 +178,39 @@ describe('Test external auth plugins', function () {
178 178
179 it('Should refresh Cyan token, but not Kefka token', async function () { 179 it('Should refresh Cyan token, but not Kefka token', async function () {
180 { 180 {
181 const resRefresh = await server.loginCommand.refreshToken({ refreshToken: cyanRefreshToken }) 181 const resRefresh = await server.login.refreshToken({ refreshToken: cyanRefreshToken })
182 cyanAccessToken = resRefresh.body.access_token 182 cyanAccessToken = resRefresh.body.access_token
183 cyanRefreshToken = resRefresh.body.refresh_token 183 cyanRefreshToken = resRefresh.body.refresh_token
184 184
185 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) 185 const body = await server.users.getMyInfo({ token: cyanAccessToken })
186 expect(body.username).to.equal('cyan') 186 expect(body.username).to.equal('cyan')
187 } 187 }
188 188
189 { 189 {
190 await server.loginCommand.refreshToken({ refreshToken: kefkaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 190 await server.login.refreshToken({ refreshToken: kefkaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
191 } 191 }
192 }) 192 })
193 193
194 it('Should update Cyan profile', async function () { 194 it('Should update Cyan profile', async function () {
195 await server.usersCommand.updateMe({ 195 await server.users.updateMe({
196 token: cyanAccessToken, 196 token: cyanAccessToken,
197 displayName: 'Cyan Garamonde', 197 displayName: 'Cyan Garamonde',
198 description: 'Retainer to the king of Doma' 198 description: 'Retainer to the king of Doma'
199 }) 199 })
200 200
201 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) 201 const body = await server.users.getMyInfo({ token: cyanAccessToken })
202 expect(body.account.displayName).to.equal('Cyan Garamonde') 202 expect(body.account.displayName).to.equal('Cyan Garamonde')
203 expect(body.account.description).to.equal('Retainer to the king of Doma') 203 expect(body.account.description).to.equal('Retainer to the king of Doma')
204 }) 204 })
205 205
206 it('Should logout Cyan', async function () { 206 it('Should logout Cyan', async function () {
207 await server.loginCommand.logout({ token: cyanAccessToken }) 207 await server.login.logout({ token: cyanAccessToken })
208 }) 208 })
209 209
210 it('Should have logged out Cyan', async function () { 210 it('Should have logged out Cyan', async function () {
211 await server.serversCommand.waitUntilLog('On logout cyan') 211 await server.servers.waitUntilLog('On logout cyan')
212 212
213 await server.usersCommand.getMyInfo({ token: cyanAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 213 await server.users.getMyInfo({ token: cyanAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
214 }) 214 })
215 215
216 it('Should login Cyan and keep the old existing profile', async function () { 216 it('Should login Cyan and keep the old existing profile', async function () {
@@ -228,7 +228,7 @@ describe('Test external auth plugins', function () {
228 cyanAccessToken = res.access_token 228 cyanAccessToken = res.access_token
229 } 229 }
230 230
231 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken }) 231 const body = await server.users.getMyInfo({ token: cyanAccessToken })
232 expect(body.username).to.equal('cyan') 232 expect(body.username).to.equal('cyan')
233 expect(body.account.displayName).to.equal('Cyan Garamonde') 233 expect(body.account.displayName).to.equal('Cyan Garamonde')
234 expect(body.account.description).to.equal('Retainer to the king of Doma') 234 expect(body.account.description).to.equal('Retainer to the king of Doma')
@@ -236,7 +236,7 @@ describe('Test external auth plugins', function () {
236 }) 236 })
237 237
238 it('Should not update an external auth email', async function () { 238 it('Should not update an external auth email', async function () {
239 await server.usersCommand.updateMe({ 239 await server.users.updateMe({
240 token: cyanAccessToken, 240 token: cyanAccessToken,
241 email: 'toto@example.com', 241 email: 'toto@example.com',
242 currentPassword: 'toto', 242 currentPassword: 'toto',
@@ -249,16 +249,16 @@ describe('Test external auth plugins', function () {
249 249
250 await wait(5000) 250 await wait(5000)
251 251
252 await server.usersCommand.getMyInfo({ token: kefkaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 252 await server.users.getMyInfo({ token: kefkaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
253 }) 253 })
254 254
255 it('Should unregister external-auth-2 and do not login existing Kefka', async function () { 255 it('Should unregister external-auth-2 and do not login existing Kefka', async function () {
256 await server.pluginsCommand.updateSettings({ 256 await server.plugins.updateSettings({
257 npmName: 'peertube-plugin-test-external-auth-one', 257 npmName: 'peertube-plugin-test-external-auth-one',
258 settings: { disableKefka: true } 258 settings: { disableKefka: true }
259 }) 259 })
260 260
261 await server.loginCommand.login({ user: { username: 'kefka', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 261 await server.login.login({ user: { username: 'kefka', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
262 262
263 await loginExternal({ 263 await loginExternal({
264 server, 264 server,
@@ -273,7 +273,7 @@ describe('Test external auth plugins', function () {
273 }) 273 })
274 274
275 it('Should have disabled this auth', async function () { 275 it('Should have disabled this auth', async function () {
276 const config = await server.configCommand.getConfig() 276 const config = await server.config.getConfig()
277 277
278 const auths = config.plugin.registeredExternalAuths 278 const auths = config.plugin.registeredExternalAuths
279 expect(auths).to.have.lengthOf(7) 279 expect(auths).to.have.lengthOf(7)
@@ -283,7 +283,7 @@ describe('Test external auth plugins', function () {
283 }) 283 })
284 284
285 it('Should uninstall the plugin one and do not login Cyan', async function () { 285 it('Should uninstall the plugin one and do not login Cyan', async function () {
286 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-external-auth-one' }) 286 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-external-auth-one' })
287 287
288 await loginExternal({ 288 await loginExternal({
289 server, 289 server,
@@ -296,9 +296,9 @@ describe('Test external auth plugins', function () {
296 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 296 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
297 }) 297 })
298 298
299 await server.loginCommand.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 299 await server.login.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
300 await server.loginCommand.login({ user: { username: 'cyan', password: '' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 300 await server.login.login({ user: { username: 'cyan', password: '' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
301 await server.loginCommand.login({ user: { username: 'cyan', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 301 await server.login.login({ user: { username: 'cyan', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
302 }) 302 })
303 303
304 it('Should not login kefka with another plugin', async function () { 304 it('Should not login kefka with another plugin', async function () {
@@ -320,7 +320,7 @@ describe('Test external auth plugins', function () {
320 }) 320 })
321 321
322 it('Should not login an existing user', async function () { 322 it('Should not login an existing user', async function () {
323 await server.usersCommand.create({ username: 'existing_user', password: 'super_password' }) 323 await server.users.create({ username: 'existing_user', password: 'super_password' })
324 324
325 await loginExternal({ 325 await loginExternal({
326 server, 326 server,
@@ -332,7 +332,7 @@ describe('Test external auth plugins', function () {
332 }) 332 })
333 333
334 it('Should display the correct configuration', async function () { 334 it('Should display the correct configuration', async function () {
335 const config = await server.configCommand.getConfig() 335 const config = await server.config.getConfig()
336 336
337 const auths = config.plugin.registeredExternalAuths 337 const auths = config.plugin.registeredExternalAuths
338 expect(auths).to.have.lengthOf(6) 338 expect(auths).to.have.lengthOf(6)
@@ -353,7 +353,7 @@ describe('Test external auth plugins', function () {
353 username: 'cid' 353 username: 'cid'
354 }) 354 })
355 355
356 const { redirectUrl } = await server.loginCommand.logout({ token: resLogin.access_token }) 356 const { redirectUrl } = await server.login.logout({ token: resLogin.access_token })
357 expect(redirectUrl).to.equal('https://example.com/redirectUrl') 357 expect(redirectUrl).to.equal('https://example.com/redirectUrl')
358 }) 358 })
359 359
@@ -365,7 +365,7 @@ describe('Test external auth plugins', function () {
365 username: 'cid' 365 username: 'cid'
366 }) 366 })
367 367
368 const { redirectUrl } = await server.loginCommand.logout({ token: resLogin.access_token }) 368 const { redirectUrl } = await server.login.logout({ token: resLogin.access_token })
369 expect(redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token) 369 expect(redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token)
370 }) 370 })
371}) 371})