1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
10 setAccessTokensToServers,
14 } from '../../../shared/extra-utils'
15 import { User, UserRole } from '@shared/models'
16 import { expect } from 'chai'
18 describe('Test id and pass auth plugins', function () {
19 let server: ServerInfo
20 let crashToken: string
22 before(async function () {
25 server = await flushAndRunServer(1)
26 await setAccessTokensToServers([ server ])
28 for (const suffix of [ 'one', 'two', 'three' ]) {
31 accessToken: server.accessToken,
32 path: getPluginTestPath('-id-pass-auth-' + suffix)
37 it('Should not login', async function () {
38 await userLogin(server, { username: 'toto', password: 'password' }, 400)
41 it('Should login Spyro, create the user and use the token', async function () {
42 const accessToken = await userLogin(server, { username: 'spyro', password: 'spyro password' })
44 const res = await getMyUserInformation(server.url, accessToken)
46 const body: User = res.body
47 expect(body.username).to.equal('spyro')
48 expect(body.account.displayName).to.equal('Spyro the Dragon')
49 expect(body.role).to.equal(UserRole.USER)
52 it('Should login Crash, create the user and use the token', async function () {
53 crashToken = await userLogin(server, { username: 'crash', password: 'crash password' })
55 const res = await getMyUserInformation(server.url, crashToken)
57 const body: User = res.body
58 expect(body.username).to.equal('crash')
59 expect(body.account.displayName).to.equal('Crash Bandicoot')
60 expect(body.role).to.equal(UserRole.MODERATOR)
63 it('Should login the first Laguna, create the user and use the token', async function () {
64 const accessToken = await userLogin(server, { username: 'laguna', password: 'laguna password' })
66 const res = await getMyUserInformation(server.url, accessToken)
68 const body: User = res.body
69 expect(body.username).to.equal('laguna')
70 expect(body.account.displayName).to.equal('laguna')
71 expect(body.role).to.equal(UserRole.USER)
74 it('Should update Crash profile', async function () {
77 accessToken: crashToken,
78 displayName: 'Beautiful Crash',
79 description: 'Mutant eastern barred bandicoot'
82 const res = await getMyUserInformation(server.url, crashToken)
84 const body: User = res.body
85 expect(body.account.displayName).to.equal('Beautiful Crash')
86 expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
89 it('Should logout Crash', async function () {
90 await logout(server.url, crashToken)
93 it('Should have logged out Crash', async function () {
94 await getMyUserInformation(server.url, crashToken, 401)
96 await waitUntilLog(server, 'On logout for auth 1 - 2')
99 it('Should login Crash and keep the old existing profile', async function () {
100 crashToken = await userLogin(server, { username: 'crash', password: 'crash password' })
102 const res = await getMyUserInformation(server.url, crashToken)
104 const body: User = res.body
105 expect(body.username).to.equal('crash')
106 expect(body.account.displayName).to.equal('Beautiful Crash')
107 expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
108 expect(body.role).to.equal(UserRole.MODERATOR)
111 it('Should uninstall the plugin one and do not login existing Crash', async function () {
112 await uninstallPlugin({
114 accessToken: server.accessToken,
115 npmName: 'peertube-plugin-test-id-pass-auth-one'
118 await userLogin(server, { username: 'crash', password: 'crash password' }, 400)
121 after(async function () {
122 await cleanupTests([ server ])