1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5 import { HttpStatusCode } from '@shared/models'
7 describe('Official plugin auth-ldap', function () {
8 let server: PeerTubeServer
9 let accessToken: string
12 before(async function () {
15 server = await createSingleServer(1)
16 await setAccessTokensToServers([ server ])
18 await server.plugins.install({ npmName: 'peertube-plugin-auth-ldap' })
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 })
25 it('Should not login with bad LDAP settings', async function () {
26 await server.plugins.updateSettings({
27 npmName: 'peertube-plugin-auth-ldap',
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://localhost:390',
36 'username-property': 'uid'
40 await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
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',
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://localhost:10389',
54 'username-property': 'uid'
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 })
62 it('Should login with the appropriate username/password', async function () {
63 accessToken = await server.login.getAccessToken({ username: 'fry', password: 'fry' })
66 it('Should login with the appropriate email/password', async function () {
67 accessToken = await server.login.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' })
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')
78 it('Should upload a video', async function () {
79 await server.videos.upload({ token: accessToken, attributes: { name: 'my super video' } })
82 it('Should not be able to login if the user is banned', async function () {
83 await server.users.banUser({ userId })
85 await server.login.login({
86 user: { username: 'fry@planetexpress.com', password: 'fry' },
87 expectedStatus: HttpStatusCode.BAD_REQUEST_400
91 it('Should be able to login if the user is unbanned', async function () {
92 await server.users.unbanUser({ userId })
94 await server.login.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } })
97 it('Should not login if the plugin is uninstalled', async function () {
98 await server.plugins.uninstall({ npmName: 'peertube-plugin-auth-ldap' })
100 await server.login.login({
101 user: { username: 'fry@planetexpress.com', password: 'fry' },
102 expectedStatus: HttpStatusCode.BAD_REQUEST_400
106 after(async function () {
107 await cleanupTests([ server ])