aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/external-auth.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 14:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (patch)
tree7a166515e4d57a06eb3c08be569f106ed049988b /server/tests/plugins/external-auth.ts
parentd0a0fa429d4651710ed951a3c11af0219e408964 (diff)
downloadPeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.gz
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.zst
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.zip
Introduce user command
Diffstat (limited to 'server/tests/plugins/external-auth.ts')
-rw-r--r--server/tests/plugins/external-auth.ts49
1 files changed, 15 insertions, 34 deletions
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index e421fd224..3e8305611 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -5,17 +5,14 @@ import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createUser,
9 decodeQueryString, 8 decodeQueryString,
10 flushAndRunServer, 9 flushAndRunServer,
11 getMyUserInformation,
12 PluginsCommand, 10 PluginsCommand,
13 ServerInfo, 11 ServerInfo,
14 setAccessTokensToServers, 12 setAccessTokensToServers,
15 updateMyUser,
16 wait 13 wait
17} from '@shared/extra-utils' 14} from '@shared/extra-utils'
18import { User, UserRole } from '@shared/models' 15import { UserRole } from '@shared/models'
19 16
20async function loginExternal (options: { 17async function loginExternal (options: {
21 server: ServerInfo 18 server: ServerInfo
@@ -149,9 +146,7 @@ describe('Test external auth plugins', function () {
149 } 146 }
150 147
151 { 148 {
152 const res = await getMyUserInformation(server.url, cyanAccessToken) 149 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
153
154 const body: User = res.body
155 expect(body.username).to.equal('cyan') 150 expect(body.username).to.equal('cyan')
156 expect(body.account.displayName).to.equal('cyan') 151 expect(body.account.displayName).to.equal('cyan')
157 expect(body.email).to.equal('cyan@example.com') 152 expect(body.email).to.equal('cyan@example.com')
@@ -173,9 +168,7 @@ describe('Test external auth plugins', function () {
173 } 168 }
174 169
175 { 170 {
176 const res = await getMyUserInformation(server.url, kefkaAccessToken) 171 const body = await server.usersCommand.getMyInfo({ token: kefkaAccessToken })
177
178 const body: User = res.body
179 expect(body.username).to.equal('kefka') 172 expect(body.username).to.equal('kefka')
180 expect(body.account.displayName).to.equal('Kefka Palazzo') 173 expect(body.account.displayName).to.equal('Kefka Palazzo')
181 expect(body.email).to.equal('kefka@example.com') 174 expect(body.email).to.equal('kefka@example.com')
@@ -189,9 +182,8 @@ describe('Test external auth plugins', function () {
189 cyanAccessToken = resRefresh.body.access_token 182 cyanAccessToken = resRefresh.body.access_token
190 cyanRefreshToken = resRefresh.body.refresh_token 183 cyanRefreshToken = resRefresh.body.refresh_token
191 184
192 const res = await getMyUserInformation(server.url, cyanAccessToken) 185 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
193 const user: User = res.body 186 expect(body.username).to.equal('cyan')
194 expect(user.username).to.equal('cyan')
195 } 187 }
196 188
197 { 189 {
@@ -200,16 +192,13 @@ describe('Test external auth plugins', function () {
200 }) 192 })
201 193
202 it('Should update Cyan profile', async function () { 194 it('Should update Cyan profile', async function () {
203 await updateMyUser({ 195 await server.usersCommand.updateMe({
204 url: server.url, 196 token: cyanAccessToken,
205 accessToken: cyanAccessToken,
206 displayName: 'Cyan Garamonde', 197 displayName: 'Cyan Garamonde',
207 description: 'Retainer to the king of Doma' 198 description: 'Retainer to the king of Doma'
208 }) 199 })
209 200
210 const res = await getMyUserInformation(server.url, cyanAccessToken) 201 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
211
212 const body: User = res.body
213 expect(body.account.displayName).to.equal('Cyan Garamonde') 202 expect(body.account.displayName).to.equal('Cyan Garamonde')
214 expect(body.account.description).to.equal('Retainer to the king of Doma') 203 expect(body.account.description).to.equal('Retainer to the king of Doma')
215 }) 204 })
@@ -221,7 +210,7 @@ describe('Test external auth plugins', function () {
221 it('Should have logged out Cyan', async function () { 210 it('Should have logged out Cyan', async function () {
222 await server.serversCommand.waitUntilLog('On logout cyan') 211 await server.serversCommand.waitUntilLog('On logout cyan')
223 212
224 await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401) 213 await server.usersCommand.getMyInfo({ token: cyanAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
225 }) 214 })
226 215
227 it('Should login Cyan and keep the old existing profile', async function () { 216 it('Should login Cyan and keep the old existing profile', async function () {
@@ -239,9 +228,7 @@ describe('Test external auth plugins', function () {
239 cyanAccessToken = res.access_token 228 cyanAccessToken = res.access_token
240 } 229 }
241 230
242 const res = await getMyUserInformation(server.url, cyanAccessToken) 231 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
243
244 const body: User = res.body
245 expect(body.username).to.equal('cyan') 232 expect(body.username).to.equal('cyan')
246 expect(body.account.displayName).to.equal('Cyan Garamonde') 233 expect(body.account.displayName).to.equal('Cyan Garamonde')
247 expect(body.account.description).to.equal('Retainer to the king of Doma') 234 expect(body.account.description).to.equal('Retainer to the king of Doma')
@@ -249,12 +236,11 @@ describe('Test external auth plugins', function () {
249 }) 236 })
250 237
251 it('Should not update an external auth email', async function () { 238 it('Should not update an external auth email', async function () {
252 await updateMyUser({ 239 await server.usersCommand.updateMe({
253 url: server.url, 240 token: cyanAccessToken,
254 accessToken: cyanAccessToken,
255 email: 'toto@example.com', 241 email: 'toto@example.com',
256 currentPassword: 'toto', 242 currentPassword: 'toto',
257 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 243 expectedStatus: HttpStatusCode.BAD_REQUEST_400
258 }) 244 })
259 }) 245 })
260 246
@@ -263,7 +249,7 @@ describe('Test external auth plugins', function () {
263 249
264 await wait(5000) 250 await wait(5000)
265 251
266 await getMyUserInformation(server.url, kefkaAccessToken, HttpStatusCode.UNAUTHORIZED_401) 252 await server.usersCommand.getMyInfo({ token: kefkaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
267 }) 253 })
268 254
269 it('Should unregister external-auth-2 and do not login existing Kefka', async function () { 255 it('Should unregister external-auth-2 and do not login existing Kefka', async function () {
@@ -334,12 +320,7 @@ describe('Test external auth plugins', function () {
334 }) 320 })
335 321
336 it('Should not login an existing user', async function () { 322 it('Should not login an existing user', async function () {
337 await createUser({ 323 await server.usersCommand.create({ username: 'existing_user', password: 'super_password' })
338 url: server.url,
339 accessToken: server.accessToken,
340 username: 'existing_user',
341 password: 'super_password'
342 })
343 324
344 await loginExternal({ 325 await loginExternal({
345 server, 326 server,