]>
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, | |
e307e4fc C |
13 | userLogin, |
14 | wait, | |
15 | login, refreshToken | |
e1c55031 C |
16 | } from '../../../shared/extra-utils' |
17 | import { User, UserRole } from '@shared/models' | |
18 | import { expect } from 'chai' | |
7fed6375 C |
19 | |
20 | describe('Test id and pass auth plugins', function () { | |
21 | let server: ServerInfo | |
e307e4fc C |
22 | |
23 | let crashAccessToken: string | |
24 | let crashRefreshToken: string | |
25 | ||
26 | let lagunaAccessToken: string | |
27 | let lagunaRefreshToken: string | |
7fed6375 C |
28 | |
29 | before(async function () { | |
30 | this.timeout(30000) | |
31 | ||
32 | server = await flushAndRunServer(1) | |
33 | await setAccessTokensToServers([ server ]) | |
34 | ||
e1c55031 C |
35 | for (const suffix of [ 'one', 'two', 'three' ]) { |
36 | await installPlugin({ | |
37 | url: server.url, | |
38 | accessToken: server.accessToken, | |
39 | path: getPluginTestPath('-id-pass-auth-' + suffix) | |
40 | }) | |
41 | } | |
7fed6375 C |
42 | }) |
43 | ||
e1c55031 C |
44 | it('Should not login', async function () { |
45 | await userLogin(server, { username: 'toto', password: 'password' }, 400) | |
7fed6375 C |
46 | }) |
47 | ||
e1c55031 C |
48 | it('Should login Spyro, create the user and use the token', async function () { |
49 | const accessToken = await userLogin(server, { username: 'spyro', password: 'spyro password' }) | |
7fed6375 | 50 | |
e1c55031 C |
51 | const res = await getMyUserInformation(server.url, accessToken) |
52 | ||
53 | const body: User = res.body | |
54 | expect(body.username).to.equal('spyro') | |
55 | expect(body.account.displayName).to.equal('Spyro the Dragon') | |
56 | expect(body.role).to.equal(UserRole.USER) | |
7fed6375 C |
57 | }) |
58 | ||
e1c55031 | 59 | it('Should login Crash, create the user and use the token', async function () { |
e307e4fc C |
60 | { |
61 | const res = await login(server.url, server.client, { username: 'crash', password: 'crash password' }) | |
62 | crashAccessToken = res.body.access_token | |
63 | crashRefreshToken = res.body.refresh_token | |
64 | } | |
e1c55031 | 65 | |
e307e4fc C |
66 | { |
67 | const res = await getMyUserInformation(server.url, crashAccessToken) | |
7fed6375 | 68 | |
e307e4fc C |
69 | const body: User = res.body |
70 | expect(body.username).to.equal('crash') | |
71 | expect(body.account.displayName).to.equal('Crash Bandicoot') | |
72 | expect(body.role).to.equal(UserRole.MODERATOR) | |
73 | } | |
7fed6375 C |
74 | }) |
75 | ||
e1c55031 | 76 | it('Should login the first Laguna, create the user and use the token', async function () { |
e307e4fc C |
77 | { |
78 | const res = await login(server.url, server.client, { username: 'laguna', password: 'laguna password' }) | |
79 | lagunaAccessToken = res.body.access_token | |
80 | lagunaRefreshToken = res.body.refresh_token | |
81 | } | |
7fed6375 | 82 | |
e307e4fc C |
83 | { |
84 | const res = await getMyUserInformation(server.url, lagunaAccessToken) | |
e1c55031 | 85 | |
e307e4fc C |
86 | const body: User = res.body |
87 | expect(body.username).to.equal('laguna') | |
88 | expect(body.account.displayName).to.equal('laguna') | |
89 | expect(body.role).to.equal(UserRole.USER) | |
90 | } | |
91 | }) | |
92 | ||
93 | it('Should refresh crash token, but not laguna token', async function () { | |
94 | { | |
95 | const resRefresh = await refreshToken(server, crashRefreshToken) | |
96 | crashAccessToken = resRefresh.body.access_token | |
97 | crashRefreshToken = resRefresh.body.refresh_token | |
98 | ||
99 | const res = await getMyUserInformation(server.url, crashAccessToken) | |
100 | const user: User = res.body | |
101 | expect(user.username).to.equal('crash') | |
102 | } | |
103 | ||
104 | { | |
105 | await refreshToken(server, lagunaRefreshToken, 400) | |
106 | } | |
7fed6375 C |
107 | }) |
108 | ||
109 | it('Should update Crash profile', async function () { | |
e1c55031 C |
110 | await updateMyUser({ |
111 | url: server.url, | |
e307e4fc | 112 | accessToken: crashAccessToken, |
e1c55031 C |
113 | displayName: 'Beautiful Crash', |
114 | description: 'Mutant eastern barred bandicoot' | |
115 | }) | |
7fed6375 | 116 | |
e307e4fc | 117 | const res = await getMyUserInformation(server.url, crashAccessToken) |
e1c55031 C |
118 | |
119 | const body: User = res.body | |
120 | expect(body.account.displayName).to.equal('Beautiful Crash') | |
121 | expect(body.account.description).to.equal('Mutant eastern barred bandicoot') | |
7fed6375 C |
122 | }) |
123 | ||
124 | it('Should logout Crash', async function () { | |
e307e4fc | 125 | await logout(server.url, crashAccessToken) |
7fed6375 C |
126 | }) |
127 | ||
e1c55031 | 128 | it('Should have logged out Crash', async function () { |
e1c55031 | 129 | await waitUntilLog(server, 'On logout for auth 1 - 2') |
e307e4fc C |
130 | |
131 | await getMyUserInformation(server.url, crashAccessToken, 401) | |
7fed6375 C |
132 | }) |
133 | ||
134 | it('Should login Crash and keep the old existing profile', async function () { | |
e307e4fc | 135 | crashAccessToken = await userLogin(server, { username: 'crash', password: 'crash password' }) |
7fed6375 | 136 | |
e307e4fc | 137 | const res = await getMyUserInformation(server.url, crashAccessToken) |
e1c55031 C |
138 | |
139 | const body: User = res.body | |
140 | expect(body.username).to.equal('crash') | |
141 | expect(body.account.displayName).to.equal('Beautiful Crash') | |
142 | expect(body.account.description).to.equal('Mutant eastern barred bandicoot') | |
143 | expect(body.role).to.equal(UserRole.MODERATOR) | |
7fed6375 C |
144 | }) |
145 | ||
e307e4fc C |
146 | it('Should correctly auth token of laguna', async function () { |
147 | this.timeout(10000) | |
148 | ||
149 | await wait(5000) | |
150 | ||
151 | await getMyUserInformation(server.url, lagunaAccessToken, 401) | |
152 | }) | |
153 | ||
7fed6375 | 154 | it('Should uninstall the plugin one and do not login existing Crash', async function () { |
e1c55031 C |
155 | await uninstallPlugin({ |
156 | url: server.url, | |
157 | accessToken: server.accessToken, | |
158 | npmName: 'peertube-plugin-test-id-pass-auth-one' | |
159 | }) | |
7fed6375 | 160 | |
e1c55031 | 161 | await userLogin(server, { username: 'crash', password: 'crash password' }, 400) |
7fed6375 C |
162 | }) |
163 | ||
164 | after(async function () { | |
165 | await cleanupTests([ server ]) | |
166 | }) | |
167 | }) |