]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { expect } from 'chai' | |
5 | import { HttpStatusCode } from '@shared/core-utils' | |
6 | import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' | |
7 | ||
8 | describe('Official plugin auth-ldap', function () { | |
9 | let server: ServerInfo | |
10 | let accessToken: string | |
11 | let userId: number | |
12 | ||
13 | before(async function () { | |
14 | this.timeout(30000) | |
15 | ||
16 | server = await flushAndRunServer(1) | |
17 | await setAccessTokensToServers([ server ]) | |
18 | ||
19 | await server.plugins.install({ npmName: 'peertube-plugin-auth-ldap' }) | |
20 | }) | |
21 | ||
22 | it('Should not login with without LDAP settings', async function () { | |
23 | await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | |
24 | }) | |
25 | ||
26 | it('Should not login with bad LDAP settings', async function () { | |
27 | await server.plugins.updateSettings({ | |
28 | npmName: 'peertube-plugin-auth-ldap', | |
29 | settings: { | |
30 | 'bind-credentials': 'GoodNewsEveryone', | |
31 | 'bind-dn': 'cn=admin,dc=planetexpress,dc=com', | |
32 | 'insecure-tls': false, | |
33 | 'mail-property': 'mail', | |
34 | 'search-base': 'ou=people,dc=planetexpress,dc=com', | |
35 | 'search-filter': '(|(mail={{username}})(uid={{username}}))', | |
36 | 'url': 'ldap://localhost:390', | |
37 | 'username-property': 'uid' | |
38 | } | |
39 | }) | |
40 | ||
41 | await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | |
42 | }) | |
43 | ||
44 | it('Should not login with good LDAP settings but wrong username/password', async function () { | |
45 | await server.plugins.updateSettings({ | |
46 | npmName: 'peertube-plugin-auth-ldap', | |
47 | settings: { | |
48 | 'bind-credentials': 'GoodNewsEveryone', | |
49 | 'bind-dn': 'cn=admin,dc=planetexpress,dc=com', | |
50 | 'insecure-tls': false, | |
51 | 'mail-property': 'mail', | |
52 | 'search-base': 'ou=people,dc=planetexpress,dc=com', | |
53 | 'search-filter': '(|(mail={{username}})(uid={{username}}))', | |
54 | 'url': 'ldap://localhost:10389', | |
55 | 'username-property': 'uid' | |
56 | } | |
57 | }) | |
58 | ||
59 | await server.login.login({ user: { username: 'fry', password: 'bad password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | |
60 | await server.login.login({ user: { username: 'fryr', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | |
61 | }) | |
62 | ||
63 | it('Should login with the appropriate username/password', async function () { | |
64 | accessToken = await server.login.getAccessToken({ username: 'fry', password: 'fry' }) | |
65 | }) | |
66 | ||
67 | it('Should login with the appropriate email/password', async function () { | |
68 | accessToken = await server.login.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' }) | |
69 | }) | |
70 | ||
71 | it('Should login get my profile', async function () { | |
72 | const body = await server.users.getMyInfo({ token: accessToken }) | |
73 | expect(body.username).to.equal('fry') | |
74 | expect(body.email).to.equal('fry@planetexpress.com') | |
75 | ||
76 | userId = body.id | |
77 | }) | |
78 | ||
79 | it('Should upload a video', async function () { | |
80 | await server.videos.upload({ token: accessToken, attributes: { name: 'my super video' } }) | |
81 | }) | |
82 | ||
83 | it('Should not be able to login if the user is banned', async function () { | |
84 | await server.users.banUser({ userId }) | |
85 | ||
86 | await server.login.login({ | |
87 | user: { username: 'fry@planetexpress.com', password: 'fry' }, | |
88 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
89 | }) | |
90 | }) | |
91 | ||
92 | it('Should be able to login if the user is unbanned', async function () { | |
93 | await server.users.unbanUser({ userId }) | |
94 | ||
95 | await server.login.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } }) | |
96 | }) | |
97 | ||
98 | it('Should not login if the plugin is uninstalled', async function () { | |
99 | await server.plugins.uninstall({ npmName: 'peertube-plugin-auth-ldap' }) | |
100 | ||
101 | await server.login.login({ | |
102 | user: { username: 'fry@planetexpress.com', password: 'fry' }, | |
103 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
104 | }) | |
105 | }) | |
106 | ||
107 | after(async function () { | |
108 | await cleanupTests([ server ]) | |
109 | }) | |
110 | }) |