1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { User } from '@shared/models/users/user.model'
6 import { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo, userLogin } from '../../../shared/extra-utils'
7 import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
9 describe('Official plugin auth-ldap', function () {
10 let server: ServerInfo
11 let accessToken: string
14 before(async function () {
17 server = await flushAndRunServer(1)
18 await setAccessTokensToServers([ server ])
20 await server.pluginsCommand.install({ npmName: 'peertube-plugin-auth-ldap' })
23 it('Should not login with without LDAP settings', async function () {
24 await userLogin(server, { username: 'fry', password: 'fry' }, 400)
27 it('Should not login with bad LDAP settings', async function () {
28 await server.pluginsCommand.updateSettings({
29 npmName: 'peertube-plugin-auth-ldap',
31 'bind-credentials': 'GoodNewsEveryone',
32 'bind-dn': 'cn=admin,dc=planetexpress,dc=com',
33 'insecure-tls': false,
34 'mail-property': 'mail',
35 'search-base': 'ou=people,dc=planetexpress,dc=com',
36 'search-filter': '(|(mail={{username}})(uid={{username}}))',
37 'url': 'ldap://localhost:390',
38 'username-property': 'uid'
42 await userLogin(server, { username: 'fry', password: 'fry' }, 400)
45 it('Should not login with good LDAP settings but wrong username/password', async function () {
46 await server.pluginsCommand.updateSettings({
47 npmName: 'peertube-plugin-auth-ldap',
49 'bind-credentials': 'GoodNewsEveryone',
50 'bind-dn': 'cn=admin,dc=planetexpress,dc=com',
51 'insecure-tls': false,
52 'mail-property': 'mail',
53 'search-base': 'ou=people,dc=planetexpress,dc=com',
54 'search-filter': '(|(mail={{username}})(uid={{username}}))',
55 'url': 'ldap://localhost:10389',
56 'username-property': 'uid'
60 await userLogin(server, { username: 'fry', password: 'bad password' }, 400)
61 await userLogin(server, { username: 'fryr', password: 'fry' }, 400)
64 it('Should login with the appropriate username/password', async function () {
65 accessToken = await userLogin(server, { username: 'fry', password: 'fry' })
68 it('Should login with the appropriate email/password', async function () {
69 accessToken = await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' })
72 it('Should login get my profile', async function () {
73 const res = await getMyUserInformation(server.url, accessToken)
74 const body: User = res.body
76 expect(body.username).to.equal('fry')
77 expect(body.email).to.equal('fry@planetexpress.com')
82 it('Should upload a video', async function () {
83 await uploadVideo(server.url, accessToken, { name: 'my super video' })
86 it('Should not be able to login if the user is banned', async function () {
87 await blockUser(server.url, userId, server.accessToken)
89 await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400)
92 it('Should be able to login if the user is unbanned', async function () {
93 await unblockUser(server.url, userId, server.accessToken)
95 await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' })
98 it('Should not login if the plugin is uninstalled', async function () {
99 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-auth-ldap' })
101 await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400)
104 after(async function () {
105 await cleanupTests([ server ])