]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/external-plugins/auth-ldap.ts
Bumped to version v5.2.1
[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 { expect } from 'chai'
4 import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5 import { HttpStatusCode } from '@shared/models'
6
7 describe('Official plugin auth-ldap', function () {
8 let server: PeerTubeServer
9 let accessToken: string
10 let userId: number
11
12 before(async function () {
13 this.timeout(30000)
14
15 server = await createSingleServer(1)
16 await setAccessTokensToServers([ server ])
17
18 await server.plugins.install({ npmName: 'peertube-plugin-auth-ldap' })
19 })
20
21 it('Should not login with without LDAP settings', async function () {
22 await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
23 })
24
25 it('Should not login with bad LDAP settings', async function () {
26 await server.plugins.updateSettings({
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}}))',
35 'url': 'ldap://127.0.0.1:390',
36 'username-property': 'uid'
37 }
38 })
39
40 await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
41 })
42
43 it('Should not login with good LDAP settings but wrong username/password', async function () {
44 await server.plugins.updateSettings({
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://127.0.0.1:10389',
54 'username-property': 'uid'
55 }
56 })
57
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 })
60 })
61
62 it('Should login with the appropriate username/password', async function () {
63 accessToken = await server.login.getAccessToken({ username: 'fry', password: 'fry' })
64 })
65
66 it('Should login with the appropriate email/password', async function () {
67 accessToken = await server.login.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' })
68 })
69
70 it('Should login get my profile', async function () {
71 const body = await server.users.getMyInfo({ token: accessToken })
72 expect(body.username).to.equal('fry')
73 expect(body.email).to.equal('fry@planetexpress.com')
74
75 userId = body.id
76 })
77
78 it('Should upload a video', async function () {
79 await server.videos.upload({ token: accessToken, attributes: { name: 'my super video' } })
80 })
81
82 it('Should not be able to login if the user is banned', async function () {
83 await server.users.banUser({ userId })
84
85 await server.login.login({
86 user: { username: 'fry@planetexpress.com', password: 'fry' },
87 expectedStatus: HttpStatusCode.BAD_REQUEST_400
88 })
89 })
90
91 it('Should be able to login if the user is unbanned', async function () {
92 await server.users.unbanUser({ userId })
93
94 await server.login.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } })
95 })
96
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
105 it('Should not login if the plugin is uninstalled', async function () {
106 await server.plugins.uninstall({ npmName: 'peertube-plugin-auth-ldap' })
107
108 await server.login.login({
109 user: { username: 'fry@planetexpress.com', password: 'fry' },
110 expectedStatus: HttpStatusCode.BAD_REQUEST_400
111 })
112 })
113
114 after(async function () {
115 await cleanupTests([ server ])
116 })
117 })