]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/plugins/external-auth.ts
Fix external auth email/password update
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / external-auth.ts
index a72b2829b5e535d167c268c9af116234842747f9..57361be05a84763b70c71a84b4b03b05b4129fe5 100644 (file)
@@ -16,7 +16,10 @@ import {
   setAccessTokensToServers,
   uninstallPlugin,
   updateMyUser,
-  wait
+  wait,
+  userLogin,
+  updatePluginSettings,
+  createUser
 } from '../../../shared/extra-utils'
 import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
 
@@ -27,6 +30,7 @@ async function loginExternal (options: {
   username: string
   query?: any
   statusCodeExpected?: number
+  statusCodeExpectedStep2?: number
 }) {
   const res = await getExternalAuth({
     url: options.server.url,
@@ -45,7 +49,8 @@ async function loginExternal (options: {
   const resLogin = await loginUsingExternalToken(
     options.server,
     options.username,
-    externalAuthToken as string
+    externalAuthToken as string,
+    options.statusCodeExpectedStep2
   )
 
   return resLogin.body
@@ -83,7 +88,7 @@ describe('Test external auth plugins', function () {
     const config: ServerConfig = res.body
 
     const auths = config.plugin.registeredExternalAuths
-    expect(auths).to.have.lengthOf(3)
+    expect(auths).to.have.lengthOf(6)
 
     const auth2 = auths.find((a) => a.authName === 'external-auth-2')
     expect(auth2).to.exist
@@ -250,6 +255,16 @@ describe('Test external auth plugins', function () {
     expect(body.role).to.equal(UserRole.USER)
   })
 
+  it('Should not update an external auth email', async function () {
+    await updateMyUser({
+      url: server.url,
+      accessToken: cyanAccessToken,
+      email: 'toto@example.com',
+      currentPassword: 'toto',
+      statusCodeExpected: 400
+    })
+  })
+
   it('Should reject token of Kefka by the plugin hook', async function () {
     this.timeout(10000)
 
@@ -258,6 +273,40 @@ describe('Test external auth plugins', function () {
     await getMyUserInformation(server.url, kefkaAccessToken, 401)
   })
 
+  it('Should unregister external-auth-2 and do not login existing Kefka', async function () {
+    await updatePluginSettings({
+      url: server.url,
+      accessToken: server.accessToken,
+      npmName: 'peertube-plugin-test-external-auth-one',
+      settings: { disableKefka: true }
+    })
+
+    await userLogin(server, { username: 'kefka', password: 'fake' }, 400)
+
+    await loginExternal({
+      server,
+      npmName: 'test-external-auth-one',
+      authName: 'external-auth-2',
+      query: {
+        username: 'kefka'
+      },
+      username: 'kefka',
+      statusCodeExpected: 404
+    })
+  })
+
+  it('Should have disabled this auth', async function () {
+    const res = await getConfig(server.url)
+
+    const config: ServerConfig = res.body
+
+    const auths = config.plugin.registeredExternalAuths
+    expect(auths).to.have.lengthOf(5)
+
+    const auth1 = auths.find(a => a.authName === 'external-auth-2')
+    expect(auth1).to.not.exist
+  })
+
   it('Should uninstall the plugin one and do not login Cyan', async function () {
     await uninstallPlugin({
       url: server.url,
@@ -275,6 +324,45 @@ describe('Test external auth plugins', function () {
       username: 'cyan',
       statusCodeExpected: 404
     })
+
+    await userLogin(server, { username: 'cyan', password: null }, 400)
+    await userLogin(server, { username: 'cyan', password: '' }, 400)
+    await userLogin(server, { username: 'cyan', password: 'fake' }, 400)
+  })
+
+  it('Should not login kefka with another plugin', async function () {
+    await loginExternal({
+      server,
+      npmName: 'test-external-auth-two',
+      authName: 'external-auth-4',
+      username: 'kefka2',
+      statusCodeExpectedStep2: 400
+    })
+
+    await loginExternal({
+      server,
+      npmName: 'test-external-auth-two',
+      authName: 'external-auth-4',
+      username: 'kefka',
+      statusCodeExpectedStep2: 400
+    })
+  })
+
+  it('Should not login an existing user', async function () {
+    await createUser({
+      url: server.url,
+      accessToken: server.accessToken,
+      username: 'existing_user',
+      password: 'super_password'
+    })
+
+    await loginExternal({
+      server,
+      npmName: 'test-external-auth-two',
+      authName: 'external-auth-6',
+      username: 'existing_user',
+      statusCodeExpectedStep2: 400
+    })
   })
 
   it('Should display the correct configuration', async function () {
@@ -283,7 +371,7 @@ describe('Test external auth plugins', function () {
     const config: ServerConfig = res.body
 
     const auths = config.plugin.registeredExternalAuths
-    expect(auths).to.have.lengthOf(1)
+    expect(auths).to.have.lengthOf(4)
 
     const auth2 = auths.find((a) => a.authName === 'external-auth-2')
     expect(auth2).to.not.exist