aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/id-and-pass-auth.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 11:05:15 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit41d1d075011174e73dccb74006181a92a618d7b4 (patch)
tree4dc1af0e266977f062cf9716837d04de1cdd628d /server/tests/plugins/id-and-pass-auth.ts
parent6c5065a011b099618681a37bd77eaa7bd3db752e (diff)
downloadPeerTube-41d1d075011174e73dccb74006181a92a618d7b4.tar.gz
PeerTube-41d1d075011174e73dccb74006181a92a618d7b4.tar.zst
PeerTube-41d1d075011174e73dccb74006181a92a618d7b4.zip
Introduce login command
Diffstat (limited to 'server/tests/plugins/id-and-pass-auth.ts')
-rw-r--r--server/tests/plugins/id-and-pass-auth.ts49
1 files changed, 26 insertions, 23 deletions
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts
index a0b31bc1f..e3da64110 100644
--- a/server/tests/plugins/id-and-pass-auth.ts
+++ b/server/tests/plugins/id-and-pass-auth.ts
@@ -2,19 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils'
5import { 6import {
6 cleanupTests, 7 cleanupTests,
7 flushAndRunServer, 8 flushAndRunServer,
8 getMyUserInformation, 9 getMyUserInformation,
9 getUsersList, 10 getUsersList,
10 login,
11 logout,
12 PluginsCommand, 11 PluginsCommand,
13 refreshToken,
14 ServerInfo, 12 ServerInfo,
15 setAccessTokensToServers, 13 setAccessTokensToServers,
16 updateMyUser, 14 updateMyUser,
17 userLogin,
18 wait 15 wait
19} from '@shared/extra-utils' 16} from '@shared/extra-utils'
20import { User, UserRole } from '@shared/models' 17import { User, UserRole } from '@shared/models'
@@ -52,11 +49,11 @@ describe('Test id and pass auth plugins', function () {
52 }) 49 })
53 50
54 it('Should not login', async function () { 51 it('Should not login', async function () {
55 await userLogin(server, { username: 'toto', password: 'password' }, 400) 52 await server.loginCommand.login({ user: { username: 'toto', password: 'password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
56 }) 53 })
57 54
58 it('Should login Spyro, create the user and use the token', async function () { 55 it('Should login Spyro, create the user and use the token', async function () {
59 const accessToken = await userLogin(server, { username: 'spyro', password: 'spyro password' }) 56 const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' })
60 57
61 const res = await getMyUserInformation(server.url, accessToken) 58 const res = await getMyUserInformation(server.url, accessToken)
62 59
@@ -68,9 +65,9 @@ describe('Test id and pass auth plugins', function () {
68 65
69 it('Should login Crash, create the user and use the token', async function () { 66 it('Should login Crash, create the user and use the token', async function () {
70 { 67 {
71 const res = await login(server.url, server.client, { username: 'crash', password: 'crash password' }) 68 const body = await server.loginCommand.login({ user: { username: 'crash', password: 'crash password' } })
72 crashAccessToken = res.body.access_token 69 crashAccessToken = body.access_token
73 crashRefreshToken = res.body.refresh_token 70 crashRefreshToken = body.refresh_token
74 } 71 }
75 72
76 { 73 {
@@ -85,9 +82,9 @@ describe('Test id and pass auth plugins', function () {
85 82
86 it('Should login the first Laguna, create the user and use the token', async function () { 83 it('Should login the first Laguna, create the user and use the token', async function () {
87 { 84 {
88 const res = await login(server.url, server.client, { username: 'laguna', password: 'laguna password' }) 85 const body = await server.loginCommand.login({ user: { username: 'laguna', password: 'laguna password' } })
89 lagunaAccessToken = res.body.access_token 86 lagunaAccessToken = body.access_token
90 lagunaRefreshToken = res.body.refresh_token 87 lagunaRefreshToken = body.refresh_token
91 } 88 }
92 89
93 { 90 {
@@ -102,7 +99,7 @@ describe('Test id and pass auth plugins', function () {
102 99
103 it('Should refresh crash token, but not laguna token', async function () { 100 it('Should refresh crash token, but not laguna token', async function () {
104 { 101 {
105 const resRefresh = await refreshToken(server, crashRefreshToken) 102 const resRefresh = await server.loginCommand.refreshToken({ refreshToken: crashRefreshToken })
106 crashAccessToken = resRefresh.body.access_token 103 crashAccessToken = resRefresh.body.access_token
107 crashRefreshToken = resRefresh.body.refresh_token 104 crashRefreshToken = resRefresh.body.refresh_token
108 105
@@ -112,7 +109,7 @@ describe('Test id and pass auth plugins', function () {
112 } 109 }
113 110
114 { 111 {
115 await refreshToken(server, lagunaRefreshToken, 400) 112 await server.loginCommand.refreshToken({ refreshToken: lagunaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
116 } 113 }
117 }) 114 })
118 115
@@ -132,7 +129,7 @@ describe('Test id and pass auth plugins', function () {
132 }) 129 })
133 130
134 it('Should logout Crash', async function () { 131 it('Should logout Crash', async function () {
135 await logout(server.url, crashAccessToken) 132 await server.loginCommand.logout({ token: crashAccessToken })
136 }) 133 })
137 134
138 it('Should have logged out Crash', async function () { 135 it('Should have logged out Crash', async function () {
@@ -142,7 +139,7 @@ describe('Test id and pass auth plugins', function () {
142 }) 139 })
143 140
144 it('Should login Crash and keep the old existing profile', async function () { 141 it('Should login Crash and keep the old existing profile', async function () {
145 crashAccessToken = await userLogin(server, { username: 'crash', password: 'crash password' }) 142 crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' })
146 143
147 const res = await getMyUserInformation(server.url, crashAccessToken) 144 const res = await getMyUserInformation(server.url, crashAccessToken)
148 145
@@ -162,16 +159,18 @@ describe('Test id and pass auth plugins', function () {
162 }) 159 })
163 160
164 it('Should reject an invalid username, email, role or display name', async function () { 161 it('Should reject an invalid username, email, role or display name', async function () {
165 await userLogin(server, { username: 'ward', password: 'ward password' }, 400) 162 const command = server.loginCommand
163
164 await command.login({ user: { username: 'ward', password: 'ward password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
166 await server.serversCommand.waitUntilLog('valid username') 165 await server.serversCommand.waitUntilLog('valid username')
167 166
168 await userLogin(server, { username: 'kiros', password: 'kiros password' }, 400) 167 await command.login({ user: { username: 'kiros', password: 'kiros password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
169 await server.serversCommand.waitUntilLog('valid display name') 168 await server.serversCommand.waitUntilLog('valid display name')
170 169
171 await userLogin(server, { username: 'raine', password: 'raine password' }, 400) 170 await command.login({ user: { username: 'raine', password: 'raine password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
172 await server.serversCommand.waitUntilLog('valid role') 171 await server.serversCommand.waitUntilLog('valid role')
173 172
174 await userLogin(server, { username: 'ellone', password: 'elonne password' }, 400) 173 await command.login({ user: { username: 'ellone', password: 'elonne password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
175 await server.serversCommand.waitUntilLog('valid email') 174 await server.serversCommand.waitUntilLog('valid email')
176 }) 175 })
177 176
@@ -181,8 +180,9 @@ describe('Test id and pass auth plugins', function () {
181 settings: { disableSpyro: true } 180 settings: { disableSpyro: true }
182 }) 181 })
183 182
184 await userLogin(server, { username: 'spyro', password: 'spyro password' }, 400) 183 const command = server.loginCommand
185 await userLogin(server, { username: 'spyro', password: 'fake' }, 400) 184 await command.login({ user: { username: 'spyro', password: 'spyro password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
185 await command.login({ user: { username: 'spyro', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
186 }) 186 })
187 187
188 it('Should have disabled this auth', async function () { 188 it('Should have disabled this auth', async function () {
@@ -198,7 +198,10 @@ describe('Test id and pass auth plugins', function () {
198 it('Should uninstall the plugin one and do not login existing Crash', async function () { 198 it('Should uninstall the plugin one and do not login existing Crash', async function () {
199 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' }) 199 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' })
200 200
201 await userLogin(server, { username: 'crash', password: 'crash password' }, 400) 201 await server.loginCommand.login({
202 user: { username: 'crash', password: 'crash password' },
203 expectedStatus: HttpStatusCode.BAD_REQUEST_400
204 })
202 }) 205 })
203 206
204 it('Should display the correct configuration', async function () { 207 it('Should display the correct configuration', async function () {