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