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