aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/plugins')
-rw-r--r--server/tests/plugins/id-and-pass-auth.ts97
1 files changed, 76 insertions, 21 deletions
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts
index 5b4d1a1db..45fa7856c 100644
--- a/server/tests/plugins/id-and-pass-auth.ts
+++ b/server/tests/plugins/id-and-pass-auth.ts
@@ -1,11 +1,23 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' 4import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
5import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils' 5import {
6 getMyUserInformation,
7 getPluginTestPath,
8 installPlugin,
9 logout,
10 setAccessTokensToServers,
11 uninstallPlugin,
12 updateMyUser,
13 userLogin
14} from '../../../shared/extra-utils'
15import { User, UserRole } from '@shared/models'
16import { expect } from 'chai'
6 17
7describe('Test id and pass auth plugins', function () { 18describe('Test id and pass auth plugins', function () {
8 let server: ServerInfo 19 let server: ServerInfo
20 let crashToken: string
9 21
10 before(async function () { 22 before(async function () {
11 this.timeout(30000) 23 this.timeout(30000)
@@ -13,54 +25,97 @@ describe('Test id and pass auth plugins', function () {
13 server = await flushAndRunServer(1) 25 server = await flushAndRunServer(1)
14 await setAccessTokensToServers([ server ]) 26 await setAccessTokensToServers([ server ])
15 27
16 await installPlugin({ 28 for (const suffix of [ 'one', 'two', 'three' ]) {
17 url: server.url, 29 await installPlugin({
18 accessToken: server.accessToken, 30 url: server.url,
19 path: getPluginTestPath('-id-pass-auth-one') 31 accessToken: server.accessToken,
20 }) 32 path: getPluginTestPath('-id-pass-auth-' + suffix)
21 33 })
22 await installPlugin({ 34 }
23 url: server.url,
24 accessToken: server.accessToken,
25 path: getPluginTestPath('-id-pass-auth-two')
26 })
27 }) 35 })
28 36
29 it('Should not login', async function() { 37 it('Should not login', async function () {
30 38 await userLogin(server, { username: 'toto', password: 'password' }, 400)
31 }) 39 })
32 40
33 it('Should login Spyro, create the user and use the token', async function() { 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' })
34 43
44 const res = await getMyUserInformation(server.url, accessToken)
45
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)
35 }) 50 })
36 51
37 it('Should login Crash, create the user and use the token', async function() { 52 it('Should login Crash, create the user and use the token', async function () {
53 crashToken = await userLogin(server, { username: 'crash', password: 'crash password' })
54
55 const res = await getMyUserInformation(server.url, crashToken)
38 56
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)
39 }) 61 })
40 62
41 it('Should login the first Laguna, create the user and use the token', async function() { 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' })
42 65
66 const res = await getMyUserInformation(server.url, accessToken)
67
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)
43 }) 72 })
44 73
45 it('Should update Crash profile', async function () { 74 it('Should update Crash profile', async function () {
75 await updateMyUser({
76 url: server.url,
77 accessToken: crashToken,
78 displayName: 'Beautiful Crash',
79 description: 'Mutant eastern barred bandicoot'
80 })
46 81
82 const res = await getMyUserInformation(server.url, crashToken)
83
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')
47 }) 87 })
48 88
49 it('Should logout Crash', async function () { 89 it('Should logout Crash', async function () {
50 90 await logout(server.url, crashToken)
51 // test token
52 }) 91 })
53 92
54 it('Should have logged the Crash logout', async function () { 93 it('Should have logged out Crash', async function () {
94 await getMyUserInformation(server.url, crashToken, 401)
55 95
96 await waitUntilLog(server, 'On logout for auth 1 - 2')
56 }) 97 })
57 98
58 it('Should login Crash and keep the old existing profile', async function () { 99 it('Should login Crash and keep the old existing profile', async function () {
100 crashToken = await userLogin(server, { username: 'crash', password: 'crash password' })
59 101
102 const res = await getMyUserInformation(server.url, crashToken)
103
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)
60 }) 109 })
61 110
62 it('Should uninstall the plugin one and do not login existing Crash', async function () { 111 it('Should uninstall the plugin one and do not login existing Crash', async function () {
112 await uninstallPlugin({
113 url: server.url,
114 accessToken: server.accessToken,
115 npmName: 'peertube-plugin-test-id-pass-auth-one'
116 })
63 117
118 await userLogin(server, { username: 'crash', password: 'crash password' }, 400)
64 }) 119 })
65 120
66 after(async function () { 121 after(async function () {