]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/plugins/id-and-pass-auth.ts
Support logout and add id and pass tests
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / id-and-pass-auth.ts
index 5b4d1a1db30c1c31f8a6faa8497cca82391888c5..45fa7856ce987bedc75058122b71091183d80e9b 100644 (file)
@@ -1,11 +1,23 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
-import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
-import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils'
+import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
+import {
+  getMyUserInformation,
+  getPluginTestPath,
+  installPlugin,
+  logout,
+  setAccessTokensToServers,
+  uninstallPlugin,
+  updateMyUser,
+  userLogin
+} from '../../../shared/extra-utils'
+import { User, UserRole } from '@shared/models'
+import { expect } from 'chai'
 
 describe('Test id and pass auth plugins', function () {
   let server: ServerInfo
+  let crashToken: string
 
   before(async function () {
     this.timeout(30000)
@@ -13,54 +25,97 @@ describe('Test id and pass auth plugins', function () {
     server = await flushAndRunServer(1)
     await setAccessTokensToServers([ server ])
 
-    await installPlugin({
-      url: server.url,
-      accessToken: server.accessToken,
-      path: getPluginTestPath('-id-pass-auth-one')
-    })
-
-    await installPlugin({
-      url: server.url,
-      accessToken: server.accessToken,
-      path: getPluginTestPath('-id-pass-auth-two')
-    })
+    for (const suffix of [ 'one', 'two', 'three' ]) {
+      await installPlugin({
+        url: server.url,
+        accessToken: server.accessToken,
+        path: getPluginTestPath('-id-pass-auth-' + suffix)
+      })
+    }
   })
 
-  it('Should not login', async function() {
-
+  it('Should not login', async function () {
+    await userLogin(server, { username: 'toto', password: 'password' }, 400)
   })
 
-  it('Should login Spyro, create the user and use the token', async function() {
+  it('Should login Spyro, create the user and use the token', async function () {
+    const accessToken = await userLogin(server, { username: 'spyro', password: 'spyro password' })
 
+    const res = await getMyUserInformation(server.url, accessToken)
+
+    const body: User = res.body
+    expect(body.username).to.equal('spyro')
+    expect(body.account.displayName).to.equal('Spyro the Dragon')
+    expect(body.role).to.equal(UserRole.USER)
   })
 
-  it('Should login Crash, create the user and use the token', async function() {
+  it('Should login Crash, create the user and use the token', async function () {
+    crashToken = await userLogin(server, { username: 'crash', password: 'crash password' })
+
+    const res = await getMyUserInformation(server.url, crashToken)
 
+    const body: User = res.body
+    expect(body.username).to.equal('crash')
+    expect(body.account.displayName).to.equal('Crash Bandicoot')
+    expect(body.role).to.equal(UserRole.MODERATOR)
   })
 
-  it('Should login the first Laguna, create the user and use the token', async function() {
+  it('Should login the first Laguna, create the user and use the token', async function () {
+    const accessToken = await userLogin(server, { username: 'laguna', password: 'laguna password' })
 
+    const res = await getMyUserInformation(server.url, accessToken)
+
+    const body: User = res.body
+    expect(body.username).to.equal('laguna')
+    expect(body.account.displayName).to.equal('laguna')
+    expect(body.role).to.equal(UserRole.USER)
   })
 
   it('Should update Crash profile', async function () {
+    await updateMyUser({
+      url: server.url,
+      accessToken: crashToken,
+      displayName: 'Beautiful Crash',
+      description: 'Mutant eastern barred bandicoot'
+    })
 
+    const res = await getMyUserInformation(server.url, crashToken)
+
+    const body: User = res.body
+    expect(body.account.displayName).to.equal('Beautiful Crash')
+    expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
   })
 
   it('Should logout Crash', async function () {
-
-    // test token
+    await logout(server.url, crashToken)
   })
 
-  it('Should have logged the Crash logout', async function () {
+  it('Should have logged out Crash', async function () {
+    await getMyUserInformation(server.url, crashToken, 401)
 
+    await waitUntilLog(server, 'On logout for auth 1 - 2')
   })
 
   it('Should login Crash and keep the old existing profile', async function () {
+    crashToken = await userLogin(server, { username: 'crash', password: 'crash password' })
 
+    const res = await getMyUserInformation(server.url, crashToken)
+
+    const body: User = res.body
+    expect(body.username).to.equal('crash')
+    expect(body.account.displayName).to.equal('Beautiful Crash')
+    expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
+    expect(body.role).to.equal(UserRole.MODERATOR)
   })
 
   it('Should uninstall the plugin one and do not login existing Crash', async function () {
+    await uninstallPlugin({
+      url: server.url,
+      accessToken: server.accessToken,
+      npmName: 'peertube-plugin-test-id-pass-auth-one'
+    })
 
+    await userLogin(server, { username: 'crash', password: 'crash password' }, 400)
   })
 
   after(async function () {