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