1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
6 import { User } from '@shared/models/users/user.model'
7 import { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo } from '../../../shared/extra-utils'
8 import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
10 describe('Official plugin auth-ldap', function () {
11 let server: ServerInfo
12 let accessToken: string
15 before(async function () {
18 server = await flushAndRunServer(1)
19 await setAccessTokensToServers([ server ])
21 await server.pluginsCommand.install({ npmName: 'peertube-plugin-auth-ldap' })
24 it('Should not login with without LDAP settings', async function () {
25 await server.loginCommand.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
28 it('Should not login with bad LDAP settings', async function () {
29 await server.pluginsCommand.updateSettings({
30 npmName: 'peertube-plugin-auth-ldap',
32 'bind-credentials': 'GoodNewsEveryone',
33 'bind-dn': 'cn=admin,dc=planetexpress,dc=com',
34 'insecure-tls': false,
35 'mail-property': 'mail',
36 'search-base': 'ou=people,dc=planetexpress,dc=com',
37 'search-filter': '(|(mail={{username}})(uid={{username}}))',
38 'url': 'ldap://localhost:390',
39 'username-property': 'uid'
43 await server.loginCommand.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
46 it('Should not login with good LDAP settings but wrong username/password', async function () {
47 await server.pluginsCommand.updateSettings({
48 npmName: 'peertube-plugin-auth-ldap',
50 'bind-credentials': 'GoodNewsEveryone',
51 'bind-dn': 'cn=admin,dc=planetexpress,dc=com',
52 'insecure-tls': false,
53 'mail-property': 'mail',
54 'search-base': 'ou=people,dc=planetexpress,dc=com',
55 'search-filter': '(|(mail={{username}})(uid={{username}}))',
56 'url': 'ldap://localhost:10389',
57 'username-property': 'uid'
61 await server.loginCommand.login({ user: { username: 'fry', password: 'bad password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
62 await server.loginCommand.login({ user: { username: 'fryr', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
65 it('Should login with the appropriate username/password', async function () {
66 accessToken = await server.loginCommand.getAccessToken({ username: 'fry', password: 'fry' })
69 it('Should login with the appropriate email/password', async function () {
70 accessToken = await server.loginCommand.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' })
73 it('Should login get my profile', async function () {
74 const res = await getMyUserInformation(server.url, accessToken)
75 const body: User = res.body
77 expect(body.username).to.equal('fry')
78 expect(body.email).to.equal('fry@planetexpress.com')
83 it('Should upload a video', async function () {
84 await uploadVideo(server.url, accessToken, { name: 'my super video' })
87 it('Should not be able to login if the user is banned', async function () {
88 await blockUser(server.url, userId, server.accessToken)
90 await server.loginCommand.login({
91 user: { username: 'fry@planetexpress.com', password: 'fry' },
92 expectedStatus: HttpStatusCode.BAD_REQUEST_400
96 it('Should be able to login if the user is unbanned', async function () {
97 await unblockUser(server.url, userId, server.accessToken)
99 await server.loginCommand.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } })
102 it('Should not login if the plugin is uninstalled', async function () {
103 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-auth-ldap' })
105 await server.loginCommand.login({
106 user: { username: 'fry@planetexpress.com', password: 'fry' },
107 expectedStatus: HttpStatusCode.BAD_REQUEST_400
111 after(async function () {
112 await cleanupTests([ server ])