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