aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/external-plugins/auth-ldap.ts
blob: b626ab2bb30c6d2761fb668ad423fb1c7600ff9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'

describe('Official plugin auth-ldap', function () {
  let server: ServerInfo
  let accessToken: string
  let userId: number

  before(async function () {
    this.timeout(30000)

    server = await flushAndRunServer(1)
    await setAccessTokensToServers([ server ])

    await server.pluginsCommand.install({ npmName: 'peertube-plugin-auth-ldap' })
  })

  it('Should not login with without LDAP settings', async function () {
    await server.loginCommand.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
  })

  it('Should not login with bad LDAP settings', async function () {
    await server.pluginsCommand.updateSettings({
      npmName: 'peertube-plugin-auth-ldap',
      settings: {
        'bind-credentials': 'GoodNewsEveryone',
        'bind-dn': 'cn=admin,dc=planetexpress,dc=com',
        'insecure-tls': false,
        'mail-property': 'mail',
        'search-base': 'ou=people,dc=planetexpress,dc=com',
        'search-filter': '(|(mail={{username}})(uid={{username}}))',
        'url': 'ldap://localhost:390',
        'username-property': 'uid'
      }
    })

    await server.loginCommand.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
  })

  it('Should not login with good LDAP settings but wrong username/password', async function () {
    await server.pluginsCommand.updateSettings({
      npmName: 'peertube-plugin-auth-ldap',
      settings: {
        'bind-credentials': 'GoodNewsEveryone',
        'bind-dn': 'cn=admin,dc=planetexpress,dc=com',
        'insecure-tls': false,
        'mail-property': 'mail',
        'search-base': 'ou=people,dc=planetexpress,dc=com',
        'search-filter': '(|(mail={{username}})(uid={{username}}))',
        'url': 'ldap://localhost:10389',
        'username-property': 'uid'
      }
    })

    await server.loginCommand.login({ user: { username: 'fry', password: 'bad password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
    await server.loginCommand.login({ user: { username: 'fryr', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
  })

  it('Should login with the appropriate username/password', async function () {
    accessToken = await server.loginCommand.getAccessToken({ username: 'fry', password: 'fry' })
  })

  it('Should login with the appropriate email/password', async function () {
    accessToken = await server.loginCommand.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' })
  })

  it('Should login get my profile', async function () {
    const body = await server.usersCommand.getMyInfo({ token: accessToken })
    expect(body.username).to.equal('fry')
    expect(body.email).to.equal('fry@planetexpress.com')

    userId = body.id
  })

  it('Should upload a video', async function () {
    await server.videosCommand.upload({ token: accessToken, attributes: { name: 'my super video' } })
  })

  it('Should not be able to login if the user is banned', async function () {
    await server.usersCommand.banUser({ userId })

    await server.loginCommand.login({
      user: { username: 'fry@planetexpress.com', password: 'fry' },
      expectedStatus: HttpStatusCode.BAD_REQUEST_400
    })
  })

  it('Should be able to login if the user is unbanned', async function () {
    await server.usersCommand.unbanUser({ userId })

    await server.loginCommand.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } })
  })

  it('Should not login if the plugin is uninstalled', async function () {
    await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-auth-ldap' })

    await server.loginCommand.login({
      user: { username: 'fry@planetexpress.com', password: 'fry' },
      expectedStatus: HttpStatusCode.BAD_REQUEST_400
    })
  })

  after(async function () {
    await cleanupTests([ server ])
  })
})