]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/external-plugins/auth-ldap.ts
Merge branch 'master' into release/3.3.0
[github/Chocobozzz/PeerTube.git] / server / tests / external-plugins / auth-ldap.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { expect } from 'chai'
5 import { User } from '@shared/models/users/user.model'
6 import {
7 blockUser,
8 getMyUserInformation,
9 installPlugin,
10 setAccessTokensToServers,
11 unblockUser,
12 uninstallPlugin,
13 updatePluginSettings,
14 uploadVideo,
15 userLogin
16 } from '../../../shared/extra-utils'
17 import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
18
19 describe('Official plugin auth-ldap', function () {
20 let server: ServerInfo
21 let accessToken: string
22 let userId: number
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}}))',
53 'url': 'ldap://localhost:390',
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}}))',
73 'url': 'ldap://localhost:10389',
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')
96
97 userId = body.id
98 })
99
100 it('Should upload a video', async function () {
101 await uploadVideo(server.url, accessToken, { name: 'my super video' })
102 })
103
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
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 })