]>
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 { | |
7 | getMyUserInformation, | |
8 | installPlugin, | |
9 | setAccessTokensToServers, | |
10 | uninstallPlugin, | |
11 | updatePluginSettings, | |
12 | uploadVideo, | |
13 | userLogin | |
14 | } from '../../../shared/extra-utils' | |
15 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | |
829b794a C |
16 | |
17 | describe('Official plugin auth-ldap', function () { | |
18 | let server: ServerInfo | |
19 | let accessToken: string | |
20 | ||
21 | before(async function () { | |
22 | this.timeout(30000) | |
23 | ||
24 | server = await flushAndRunServer(1) | |
25 | await setAccessTokensToServers([ server ]) | |
26 | ||
27 | await installPlugin({ | |
28 | url: server.url, | |
29 | accessToken: server.accessToken, | |
30 | npmName: 'peertube-plugin-auth-ldap' | |
31 | }) | |
32 | }) | |
33 | ||
34 | it('Should not login with without LDAP settings', async function () { | |
35 | await userLogin(server, { username: 'fry', password: 'fry' }, 400) | |
36 | }) | |
37 | ||
38 | it('Should not login with bad LDAP settings', async function () { | |
39 | await updatePluginSettings({ | |
40 | url: server.url, | |
41 | accessToken: server.accessToken, | |
42 | npmName: 'peertube-plugin-auth-ldap', | |
43 | settings: { | |
44 | 'bind-credentials': 'GoodNewsEveryone', | |
45 | 'bind-dn': 'cn=admin,dc=planetexpress,dc=com', | |
46 | 'insecure-tls': false, | |
47 | 'mail-property': 'mail', | |
48 | 'search-base': 'ou=people,dc=planetexpress,dc=com', | |
49 | 'search-filter': '(|(mail={{username}})(uid={{username}}))', | |
50 | 'url': 'ldap://ldap:390', | |
51 | 'username-property': 'uid' | |
52 | } | |
53 | }) | |
54 | ||
55 | await userLogin(server, { username: 'fry', password: 'fry' }, 400) | |
56 | }) | |
57 | ||
58 | it('Should not login with good LDAP settings but wrong username/password', async function () { | |
59 | await updatePluginSettings({ | |
60 | url: server.url, | |
61 | accessToken: server.accessToken, | |
62 | npmName: 'peertube-plugin-auth-ldap', | |
63 | settings: { | |
64 | 'bind-credentials': 'GoodNewsEveryone', | |
65 | 'bind-dn': 'cn=admin,dc=planetexpress,dc=com', | |
66 | 'insecure-tls': false, | |
67 | 'mail-property': 'mail', | |
68 | 'search-base': 'ou=people,dc=planetexpress,dc=com', | |
69 | 'search-filter': '(|(mail={{username}})(uid={{username}}))', | |
70 | 'url': 'ldap://ldap:389', | |
71 | 'username-property': 'uid' | |
72 | } | |
73 | }) | |
74 | ||
75 | await userLogin(server, { username: 'fry', password: 'bad password' }, 400) | |
76 | await userLogin(server, { username: 'fryr', password: 'fry' }, 400) | |
77 | }) | |
78 | ||
79 | it('Should login with the appropriate username/password', async function () { | |
80 | accessToken = await userLogin(server, { username: 'fry', password: 'fry' }) | |
81 | }) | |
82 | ||
83 | it('Should login with the appropriate email/password', async function () { | |
84 | accessToken = await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }) | |
85 | }) | |
86 | ||
87 | it('Should login get my profile', async function () { | |
88 | const res = await getMyUserInformation(server.url, accessToken) | |
89 | const body: User = res.body | |
90 | ||
91 | expect(body.username).to.equal('fry') | |
92 | expect(body.email).to.equal('fry@planetexpress.com') | |
93 | }) | |
94 | ||
95 | it('Should upload a video', async function () { | |
96 | await uploadVideo(server.url, accessToken, { name: 'my super video' }) | |
97 | }) | |
98 | ||
99 | it('Should not login if the plugin is uninstalled', async function () { | |
100 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-auth-ldap' }) | |
101 | ||
102 | await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400) | |
103 | }) | |
104 | ||
105 | after(async function () { | |
106 | await cleanupTests([ server ]) | |
107 | }) | |
108 | }) |