]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/external-plugins/auth-ldap.ts
Introduce blacklist command
[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 { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo, userLogin } from '../../../shared/extra-utils'
7 import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
8
9 describe('Official plugin auth-ldap', function () {
10 let server: ServerInfo
11 let accessToken: string
12 let userId: number
13
14 before(async function () {
15 this.timeout(30000)
16
17 server = await flushAndRunServer(1)
18 await setAccessTokensToServers([ server ])
19
20 await server.pluginsCommand.install({ npmName: 'peertube-plugin-auth-ldap' })
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 () {
28 await server.pluginsCommand.updateSettings({
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}}))',
37 'url': 'ldap://localhost:390',
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 () {
46 await server.pluginsCommand.updateSettings({
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}}))',
55 'url': 'ldap://localhost:10389',
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')
78
79 userId = body.id
80 })
81
82 it('Should upload a video', async function () {
83 await uploadVideo(server.url, accessToken, { name: 'my super video' })
84 })
85
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
98 it('Should not login if the plugin is uninstalled', async function () {
99 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-auth-ldap' })
100
101 await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400)
102 })
103
104 after(async function () {
105 await cleanupTests([ server ])
106 })
107 })