diff options
Diffstat (limited to 'server/tests/plugins/id-and-pass-auth.ts')
-rw-r--r-- | server/tests/plugins/id-and-pass-auth.ts | 53 |
1 files changed, 17 insertions, 36 deletions
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index e3da64110..787080e7c 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts | |||
@@ -3,18 +3,8 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { HttpStatusCode } from '@shared/core-utils' | 5 | import { HttpStatusCode } from '@shared/core-utils' |
6 | import { | 6 | import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils' |
7 | cleanupTests, | 7 | import { UserRole } from '@shared/models' |
8 | flushAndRunServer, | ||
9 | getMyUserInformation, | ||
10 | getUsersList, | ||
11 | PluginsCommand, | ||
12 | ServerInfo, | ||
13 | setAccessTokensToServers, | ||
14 | updateMyUser, | ||
15 | wait | ||
16 | } from '@shared/extra-utils' | ||
17 | import { User, UserRole } from '@shared/models' | ||
18 | 8 | ||
19 | describe('Test id and pass auth plugins', function () { | 9 | describe('Test id and pass auth plugins', function () { |
20 | let server: ServerInfo | 10 | let server: ServerInfo |
@@ -55,9 +45,8 @@ describe('Test id and pass auth plugins', function () { | |||
55 | it('Should login Spyro, create the user and use the token', async function () { | 45 | it('Should login Spyro, create the user and use the token', async function () { |
56 | const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' }) | 46 | const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' }) |
57 | 47 | ||
58 | const res = await getMyUserInformation(server.url, accessToken) | 48 | const body = await server.usersCommand.getMyInfo({ token: accessToken }) |
59 | 49 | ||
60 | const body: User = res.body | ||
61 | expect(body.username).to.equal('spyro') | 50 | expect(body.username).to.equal('spyro') |
62 | expect(body.account.displayName).to.equal('Spyro the Dragon') | 51 | expect(body.account.displayName).to.equal('Spyro the Dragon') |
63 | expect(body.role).to.equal(UserRole.USER) | 52 | expect(body.role).to.equal(UserRole.USER) |
@@ -71,9 +60,8 @@ describe('Test id and pass auth plugins', function () { | |||
71 | } | 60 | } |
72 | 61 | ||
73 | { | 62 | { |
74 | const res = await getMyUserInformation(server.url, crashAccessToken) | 63 | const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) |
75 | 64 | ||
76 | const body: User = res.body | ||
77 | expect(body.username).to.equal('crash') | 65 | expect(body.username).to.equal('crash') |
78 | expect(body.account.displayName).to.equal('Crash Bandicoot') | 66 | expect(body.account.displayName).to.equal('Crash Bandicoot') |
79 | expect(body.role).to.equal(UserRole.MODERATOR) | 67 | expect(body.role).to.equal(UserRole.MODERATOR) |
@@ -88,9 +76,8 @@ describe('Test id and pass auth plugins', function () { | |||
88 | } | 76 | } |
89 | 77 | ||
90 | { | 78 | { |
91 | const res = await getMyUserInformation(server.url, lagunaAccessToken) | 79 | const body = await server.usersCommand.getMyInfo({ token: lagunaAccessToken }) |
92 | 80 | ||
93 | const body: User = res.body | ||
94 | expect(body.username).to.equal('laguna') | 81 | expect(body.username).to.equal('laguna') |
95 | expect(body.account.displayName).to.equal('laguna') | 82 | expect(body.account.displayName).to.equal('laguna') |
96 | expect(body.role).to.equal(UserRole.USER) | 83 | expect(body.role).to.equal(UserRole.USER) |
@@ -103,9 +90,8 @@ describe('Test id and pass auth plugins', function () { | |||
103 | crashAccessToken = resRefresh.body.access_token | 90 | crashAccessToken = resRefresh.body.access_token |
104 | crashRefreshToken = resRefresh.body.refresh_token | 91 | crashRefreshToken = resRefresh.body.refresh_token |
105 | 92 | ||
106 | const res = await getMyUserInformation(server.url, crashAccessToken) | 93 | const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) |
107 | const user: User = res.body | 94 | expect(body.username).to.equal('crash') |
108 | expect(user.username).to.equal('crash') | ||
109 | } | 95 | } |
110 | 96 | ||
111 | { | 97 | { |
@@ -114,16 +100,14 @@ describe('Test id and pass auth plugins', function () { | |||
114 | }) | 100 | }) |
115 | 101 | ||
116 | it('Should update Crash profile', async function () { | 102 | it('Should update Crash profile', async function () { |
117 | await updateMyUser({ | 103 | await server.usersCommand.updateMe({ |
118 | url: server.url, | 104 | token: crashAccessToken, |
119 | accessToken: crashAccessToken, | ||
120 | displayName: 'Beautiful Crash', | 105 | displayName: 'Beautiful Crash', |
121 | description: 'Mutant eastern barred bandicoot' | 106 | description: 'Mutant eastern barred bandicoot' |
122 | }) | 107 | }) |
123 | 108 | ||
124 | const res = await getMyUserInformation(server.url, crashAccessToken) | 109 | const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) |
125 | 110 | ||
126 | const body: User = res.body | ||
127 | expect(body.account.displayName).to.equal('Beautiful Crash') | 111 | expect(body.account.displayName).to.equal('Beautiful Crash') |
128 | expect(body.account.description).to.equal('Mutant eastern barred bandicoot') | 112 | expect(body.account.description).to.equal('Mutant eastern barred bandicoot') |
129 | }) | 113 | }) |
@@ -135,15 +119,14 @@ describe('Test id and pass auth plugins', function () { | |||
135 | it('Should have logged out Crash', async function () { | 119 | it('Should have logged out Crash', async function () { |
136 | await server.serversCommand.waitUntilLog('On logout for auth 1 - 2') | 120 | await server.serversCommand.waitUntilLog('On logout for auth 1 - 2') |
137 | 121 | ||
138 | await getMyUserInformation(server.url, crashAccessToken, 401) | 122 | await server.usersCommand.getMyInfo({ token: crashAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
139 | }) | 123 | }) |
140 | 124 | ||
141 | it('Should login Crash and keep the old existing profile', async function () { | 125 | it('Should login Crash and keep the old existing profile', async function () { |
142 | crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' }) | 126 | crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' }) |
143 | 127 | ||
144 | const res = await getMyUserInformation(server.url, crashAccessToken) | 128 | const body = await server.usersCommand.getMyInfo({ token: crashAccessToken }) |
145 | 129 | ||
146 | const body: User = res.body | ||
147 | expect(body.username).to.equal('crash') | 130 | expect(body.username).to.equal('crash') |
148 | expect(body.account.displayName).to.equal('Beautiful Crash') | 131 | expect(body.account.displayName).to.equal('Beautiful Crash') |
149 | expect(body.account.description).to.equal('Mutant eastern barred bandicoot') | 132 | expect(body.account.description).to.equal('Mutant eastern barred bandicoot') |
@@ -155,7 +138,7 @@ describe('Test id and pass auth plugins', function () { | |||
155 | 138 | ||
156 | await wait(5000) | 139 | await wait(5000) |
157 | 140 | ||
158 | await getMyUserInformation(server.url, lagunaAccessToken, 401) | 141 | await server.usersCommand.getMyInfo({ token: lagunaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
159 | }) | 142 | }) |
160 | 143 | ||
161 | it('Should reject an invalid username, email, role or display name', async function () { | 144 | it('Should reject an invalid username, email, role or display name', async function () { |
@@ -215,13 +198,11 @@ describe('Test id and pass auth plugins', function () { | |||
215 | }) | 198 | }) |
216 | 199 | ||
217 | it('Should display plugin auth information in users list', async function () { | 200 | it('Should display plugin auth information in users list', async function () { |
218 | const res = await getUsersList(server.url, server.accessToken) | 201 | const { data } = await server.usersCommand.list() |
219 | |||
220 | const users: User[] = res.body.data | ||
221 | 202 | ||
222 | const root = users.find(u => u.username === 'root') | 203 | const root = data.find(u => u.username === 'root') |
223 | const crash = users.find(u => u.username === 'crash') | 204 | const crash = data.find(u => u.username === 'crash') |
224 | const laguna = users.find(u => u.username === 'laguna') | 205 | const laguna = data.find(u => u.username === 'laguna') |
225 | 206 | ||
226 | expect(root.pluginAuth).to.be.null | 207 | expect(root.pluginAuth).to.be.null |
227 | expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one') | 208 | expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one') |