diff options
Diffstat (limited to 'server/tests/external-plugins/auth-ldap.ts')
-rw-r--r-- | server/tests/external-plugins/auth-ldap.ts | 69 |
1 files changed, 27 insertions, 42 deletions
diff --git a/server/tests/external-plugins/auth-ldap.ts b/server/tests/external-plugins/auth-ldap.ts index e4eae7e8c..acec69df5 100644 --- a/server/tests/external-plugins/auth-ldap.ts +++ b/server/tests/external-plugins/auth-ldap.ts | |||
@@ -2,46 +2,29 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { User } from '@shared/models/users/user.model' | 5 | import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' |
6 | import { | 6 | import { HttpStatusCode } from '@shared/models' |
7 | blockUser, | ||
8 | getMyUserInformation, | ||
9 | installPlugin, | ||
10 | setAccessTokensToServers, | ||
11 | unblockUser, | ||
12 | uninstallPlugin, | ||
13 | updatePluginSettings, | ||
14 | uploadVideo, | ||
15 | userLogin | ||
16 | } from '../../../shared/extra-utils' | ||
17 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | ||
18 | 7 | ||
19 | describe('Official plugin auth-ldap', function () { | 8 | describe('Official plugin auth-ldap', function () { |
20 | let server: ServerInfo | 9 | let server: PeerTubeServer |
21 | let accessToken: string | 10 | let accessToken: string |
22 | let userId: number | 11 | let userId: number |
23 | 12 | ||
24 | before(async function () { | 13 | before(async function () { |
25 | this.timeout(30000) | 14 | this.timeout(30000) |
26 | 15 | ||
27 | server = await flushAndRunServer(1) | 16 | server = await createSingleServer(1) |
28 | await setAccessTokensToServers([ server ]) | 17 | await setAccessTokensToServers([ server ]) |
29 | 18 | ||
30 | await installPlugin({ | 19 | await server.plugins.install({ npmName: 'peertube-plugin-auth-ldap' }) |
31 | url: server.url, | ||
32 | accessToken: server.accessToken, | ||
33 | npmName: 'peertube-plugin-auth-ldap' | ||
34 | }) | ||
35 | }) | 20 | }) |
36 | 21 | ||
37 | it('Should not login with without LDAP settings', async function () { | 22 | it('Should not login with without LDAP settings', async function () { |
38 | await userLogin(server, { username: 'fry', password: 'fry' }, 400) | 23 | await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
39 | }) | 24 | }) |
40 | 25 | ||
41 | it('Should not login with bad LDAP settings', async function () { | 26 | it('Should not login with bad LDAP settings', async function () { |
42 | await updatePluginSettings({ | 27 | await server.plugins.updateSettings({ |
43 | url: server.url, | ||
44 | accessToken: server.accessToken, | ||
45 | npmName: 'peertube-plugin-auth-ldap', | 28 | npmName: 'peertube-plugin-auth-ldap', |
46 | settings: { | 29 | settings: { |
47 | 'bind-credentials': 'GoodNewsEveryone', | 30 | 'bind-credentials': 'GoodNewsEveryone', |
@@ -55,13 +38,11 @@ describe('Official plugin auth-ldap', function () { | |||
55 | } | 38 | } |
56 | }) | 39 | }) |
57 | 40 | ||
58 | await userLogin(server, { username: 'fry', password: 'fry' }, 400) | 41 | await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
59 | }) | 42 | }) |
60 | 43 | ||
61 | it('Should not login with good LDAP settings but wrong username/password', async function () { | 44 | it('Should not login with good LDAP settings but wrong username/password', async function () { |
62 | await updatePluginSettings({ | 45 | await server.plugins.updateSettings({ |
63 | url: server.url, | ||
64 | accessToken: server.accessToken, | ||
65 | npmName: 'peertube-plugin-auth-ldap', | 46 | npmName: 'peertube-plugin-auth-ldap', |
66 | settings: { | 47 | settings: { |
67 | 'bind-credentials': 'GoodNewsEveryone', | 48 | 'bind-credentials': 'GoodNewsEveryone', |
@@ -75,22 +56,20 @@ describe('Official plugin auth-ldap', function () { | |||
75 | } | 56 | } |
76 | }) | 57 | }) |
77 | 58 | ||
78 | await userLogin(server, { username: 'fry', password: 'bad password' }, 400) | 59 | await server.login.login({ user: { username: 'fry', password: 'bad password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
79 | await userLogin(server, { username: 'fryr', password: 'fry' }, 400) | 60 | await server.login.login({ user: { username: 'fryr', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
80 | }) | 61 | }) |
81 | 62 | ||
82 | it('Should login with the appropriate username/password', async function () { | 63 | it('Should login with the appropriate username/password', async function () { |
83 | accessToken = await userLogin(server, { username: 'fry', password: 'fry' }) | 64 | accessToken = await server.login.getAccessToken({ username: 'fry', password: 'fry' }) |
84 | }) | 65 | }) |
85 | 66 | ||
86 | it('Should login with the appropriate email/password', async function () { | 67 | it('Should login with the appropriate email/password', async function () { |
87 | accessToken = await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }) | 68 | accessToken = await server.login.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' }) |
88 | }) | 69 | }) |
89 | 70 | ||
90 | it('Should login get my profile', async function () { | 71 | it('Should login get my profile', async function () { |
91 | const res = await getMyUserInformation(server.url, accessToken) | 72 | const body = await server.users.getMyInfo({ token: accessToken }) |
92 | const body: User = res.body | ||
93 | |||
94 | expect(body.username).to.equal('fry') | 73 | expect(body.username).to.equal('fry') |
95 | expect(body.email).to.equal('fry@planetexpress.com') | 74 | expect(body.email).to.equal('fry@planetexpress.com') |
96 | 75 | ||
@@ -98,25 +77,31 @@ describe('Official plugin auth-ldap', function () { | |||
98 | }) | 77 | }) |
99 | 78 | ||
100 | it('Should upload a video', async function () { | 79 | it('Should upload a video', async function () { |
101 | await uploadVideo(server.url, accessToken, { name: 'my super video' }) | 80 | await server.videos.upload({ token: accessToken, attributes: { name: 'my super video' } }) |
102 | }) | 81 | }) |
103 | 82 | ||
104 | it('Should not be able to login if the user is banned', async function () { | 83 | it('Should not be able to login if the user is banned', async function () { |
105 | await blockUser(server.url, userId, server.accessToken) | 84 | await server.users.banUser({ userId }) |
106 | 85 | ||
107 | await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400) | 86 | await server.login.login({ |
87 | user: { username: 'fry@planetexpress.com', password: 'fry' }, | ||
88 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
89 | }) | ||
108 | }) | 90 | }) |
109 | 91 | ||
110 | it('Should be able to login if the user is unbanned', async function () { | 92 | it('Should be able to login if the user is unbanned', async function () { |
111 | await unblockUser(server.url, userId, server.accessToken) | 93 | await server.users.unbanUser({ userId }) |
112 | 94 | ||
113 | await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }) | 95 | await server.login.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } }) |
114 | }) | 96 | }) |
115 | 97 | ||
116 | it('Should not login if the plugin is uninstalled', async function () { | 98 | it('Should not login if the plugin is uninstalled', async function () { |
117 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-auth-ldap' }) | 99 | await server.plugins.uninstall({ npmName: 'peertube-plugin-auth-ldap' }) |
118 | 100 | ||
119 | await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400) | 101 | await server.login.login({ |
102 | user: { username: 'fry@planetexpress.com', password: 'fry' }, | ||
103 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
104 | }) | ||
120 | }) | 105 | }) |
121 | 106 | ||
122 | after(async function () { | 107 | after(async function () { |