]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
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 | wait, | |
15 | login, refreshToken | |
16 | } from '../../../shared/extra-utils' | |
17 | import { User, UserRole } from '@shared/models' | |
18 | import { expect } from 'chai' | |
19 | ||
20 | describe('Test id and pass auth plugins', function () { | |
21 | let server: ServerInfo | |
22 | ||
23 | let crashAccessToken: string | |
24 | let crashRefreshToken: string | |
25 | ||
26 | let lagunaAccessToken: string | |
27 | let lagunaRefreshToken: string | |
28 | ||
29 | before(async function () { | |
30 | this.timeout(30000) | |
31 | ||
32 | server = await flushAndRunServer(1) | |
33 | await setAccessTokensToServers([ server ]) | |
34 | ||
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 | } | |
42 | }) | |
43 | ||
44 | it('Should not login', async function () { | |
45 | await userLogin(server, { username: 'toto', password: 'password' }, 400) | |
46 | }) | |
47 | ||
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' }) | |
50 | ||
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) | |
57 | }) | |
58 | ||
59 | it('Should login Crash, create the user and use the token', async function () { | |
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 | } | |
65 | ||
66 | { | |
67 | const res = await getMyUserInformation(server.url, crashAccessToken) | |
68 | ||
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 | } | |
74 | }) | |
75 | ||
76 | it('Should login the first Laguna, create the user and use the token', async function () { | |
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 | } | |
82 | ||
83 | { | |
84 | const res = await getMyUserInformation(server.url, lagunaAccessToken) | |
85 | ||
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 | } | |
107 | }) | |
108 | ||
109 | it('Should update Crash profile', async function () { | |
110 | await updateMyUser({ | |
111 | url: server.url, | |
112 | accessToken: crashAccessToken, | |
113 | displayName: 'Beautiful Crash', | |
114 | description: 'Mutant eastern barred bandicoot' | |
115 | }) | |
116 | ||
117 | const res = await getMyUserInformation(server.url, crashAccessToken) | |
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') | |
122 | }) | |
123 | ||
124 | it('Should logout Crash', async function () { | |
125 | await logout(server.url, crashAccessToken) | |
126 | }) | |
127 | ||
128 | it('Should have logged out Crash', async function () { | |
129 | await waitUntilLog(server, 'On logout for auth 1 - 2') | |
130 | ||
131 | await getMyUserInformation(server.url, crashAccessToken, 401) | |
132 | }) | |
133 | ||
134 | it('Should login Crash and keep the old existing profile', async function () { | |
135 | crashAccessToken = await userLogin(server, { username: 'crash', password: 'crash password' }) | |
136 | ||
137 | const res = await getMyUserInformation(server.url, crashAccessToken) | |
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) | |
144 | }) | |
145 | ||
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 | ||
154 | it('Should uninstall the plugin one and do not login existing Crash', async function () { | |
155 | await uninstallPlugin({ | |
156 | url: server.url, | |
157 | accessToken: server.accessToken, | |
158 | npmName: 'peertube-plugin-test-id-pass-auth-one' | |
159 | }) | |
160 | ||
161 | await userLogin(server, { username: 'crash', password: 'crash password' }, 400) | |
162 | }) | |
163 | ||
164 | after(async function () { | |
165 | await cleanupTests([ server ]) | |
166 | }) | |
167 | }) |