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