]>
Commit | Line | Data |
---|---|---|
7fed6375 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
e1c55031 C |
4 | import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' |
5 | import { | |
6 | getMyUserInformation, | |
7 | getPluginTestPath, | |
8 | installPlugin, | |
9 | logout, | |
10 | setAccessTokensToServers, | |
11 | uninstallPlugin, | |
12 | updateMyUser, | |
13 | userLogin | |
14 | } from '../../../shared/extra-utils' | |
15 | import { User, UserRole } from '@shared/models' | |
16 | import { expect } from 'chai' | |
7fed6375 C |
17 | |
18 | describe('Test id and pass auth plugins', function () { | |
19 | let server: ServerInfo | |
e1c55031 | 20 | let crashToken: string |
7fed6375 C |
21 | |
22 | before(async function () { | |
23 | this.timeout(30000) | |
24 | ||
25 | server = await flushAndRunServer(1) | |
26 | await setAccessTokensToServers([ server ]) | |
27 | ||
e1c55031 C |
28 | for (const suffix of [ 'one', 'two', 'three' ]) { |
29 | await installPlugin({ | |
30 | url: server.url, | |
31 | accessToken: server.accessToken, | |
32 | path: getPluginTestPath('-id-pass-auth-' + suffix) | |
33 | }) | |
34 | } | |
7fed6375 C |
35 | }) |
36 | ||
e1c55031 C |
37 | it('Should not login', async function () { |
38 | await userLogin(server, { username: 'toto', password: 'password' }, 400) | |
7fed6375 C |
39 | }) |
40 | ||
e1c55031 C |
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' }) | |
7fed6375 | 43 | |
e1c55031 C |
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) | |
7fed6375 C |
50 | }) |
51 | ||
e1c55031 C |
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) | |
7fed6375 | 56 | |
e1c55031 C |
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) | |
7fed6375 C |
61 | }) |
62 | ||
e1c55031 C |
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' }) | |
7fed6375 | 65 | |
e1c55031 C |
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) | |
7fed6375 C |
72 | }) |
73 | ||
74 | it('Should update Crash profile', async function () { | |
e1c55031 C |
75 | await updateMyUser({ |
76 | url: server.url, | |
77 | accessToken: crashToken, | |
78 | displayName: 'Beautiful Crash', | |
79 | description: 'Mutant eastern barred bandicoot' | |
80 | }) | |
7fed6375 | 81 | |
e1c55031 C |
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') | |
7fed6375 C |
87 | }) |
88 | ||
89 | it('Should logout Crash', async function () { | |
e1c55031 | 90 | await logout(server.url, crashToken) |
7fed6375 C |
91 | }) |
92 | ||
e1c55031 C |
93 | it('Should have logged out Crash', async function () { |
94 | await getMyUserInformation(server.url, crashToken, 401) | |
7fed6375 | 95 | |
e1c55031 | 96 | await waitUntilLog(server, 'On logout for auth 1 - 2') |
7fed6375 C |
97 | }) |
98 | ||
99 | it('Should login Crash and keep the old existing profile', async function () { | |
e1c55031 | 100 | crashToken = await userLogin(server, { username: 'crash', password: 'crash password' }) |
7fed6375 | 101 | |
e1c55031 C |
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) | |
7fed6375 C |
109 | }) |
110 | ||
111 | it('Should uninstall the plugin one and do not login existing Crash', async function () { | |
e1c55031 C |
112 | await uninstallPlugin({ |
113 | url: server.url, | |
114 | accessToken: server.accessToken, | |
115 | npmName: 'peertube-plugin-test-id-pass-auth-one' | |
116 | }) | |
7fed6375 | 117 | |
e1c55031 | 118 | await userLogin(server, { username: 'crash', password: 'crash password' }, 400) |
7fed6375 C |
119 | }) |
120 | ||
121 | after(async function () { | |
122 | await cleanupTests([ server ]) | |
123 | }) | |
124 | }) |