2020-04-27 10:58:09 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import { expect } from 'chai'
|
2020-04-29 09:04:42 +02:00
|
|
|
import { User } from '@shared/models/users/user.model'
|
|
|
|
import {
|
2021-02-01 09:24:14 +01:00
|
|
|
blockUser,
|
2020-04-29 09:04:42 +02:00
|
|
|
getMyUserInformation,
|
|
|
|
installPlugin,
|
|
|
|
setAccessTokensToServers,
|
2021-02-01 09:24:14 +01:00
|
|
|
unblockUser,
|
2020-04-29 09:04:42 +02:00
|
|
|
uninstallPlugin,
|
|
|
|
updatePluginSettings,
|
|
|
|
uploadVideo,
|
|
|
|
userLogin
|
|
|
|
} from '../../../shared/extra-utils'
|
|
|
|
import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
|
2020-04-27 10:58:09 +02:00
|
|
|
|
|
|
|
describe('Official plugin auth-ldap', function () {
|
|
|
|
let server: ServerInfo
|
|
|
|
let accessToken: string
|
2021-02-01 09:24:14 +01:00
|
|
|
let userId: number
|
2020-04-27 10:58:09 +02:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
server = await flushAndRunServer(1)
|
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
|
|
|
|
await installPlugin({
|
|
|
|
url: server.url,
|
|
|
|
accessToken: server.accessToken,
|
|
|
|
npmName: 'peertube-plugin-auth-ldap'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with without LDAP settings', async function () {
|
|
|
|
await userLogin(server, { username: 'fry', password: 'fry' }, 400)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with bad LDAP settings', async function () {
|
|
|
|
await updatePluginSettings({
|
|
|
|
url: server.url,
|
|
|
|
accessToken: server.accessToken,
|
|
|
|
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}}))',
|
2020-07-30 16:58:32 +02:00
|
|
|
'url': 'ldap://localhost:390',
|
2020-04-27 10:58:09 +02:00
|
|
|
'username-property': 'uid'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await userLogin(server, { username: 'fry', password: 'fry' }, 400)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with good LDAP settings but wrong username/password', async function () {
|
|
|
|
await updatePluginSettings({
|
|
|
|
url: server.url,
|
|
|
|
accessToken: server.accessToken,
|
|
|
|
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}}))',
|
2021-01-04 11:21:19 +01:00
|
|
|
'url': 'ldap://localhost:10389',
|
2020-04-27 10:58:09 +02:00
|
|
|
'username-property': 'uid'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await userLogin(server, { username: 'fry', password: 'bad password' }, 400)
|
|
|
|
await userLogin(server, { username: 'fryr', password: 'fry' }, 400)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should login with the appropriate username/password', async function () {
|
|
|
|
accessToken = await userLogin(server, { username: 'fry', password: 'fry' })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should login with the appropriate email/password', async function () {
|
|
|
|
accessToken = await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should login get my profile', async function () {
|
|
|
|
const res = await getMyUserInformation(server.url, accessToken)
|
|
|
|
const body: User = res.body
|
|
|
|
|
|
|
|
expect(body.username).to.equal('fry')
|
|
|
|
expect(body.email).to.equal('fry@planetexpress.com')
|
2021-02-01 09:24:14 +01:00
|
|
|
|
|
|
|
userId = body.id
|
2020-04-27 10:58:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should upload a video', async function () {
|
|
|
|
await uploadVideo(server.url, accessToken, { name: 'my super video' })
|
|
|
|
})
|
|
|
|
|
2021-02-01 09:24:14 +01:00
|
|
|
it('Should not be able to login if the user is banned', async function () {
|
|
|
|
await blockUser(server.url, userId, server.accessToken)
|
|
|
|
|
|
|
|
await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should be able to login if the user is unbanned', async function () {
|
|
|
|
await unblockUser(server.url, userId, server.accessToken)
|
|
|
|
|
|
|
|
await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' })
|
|
|
|
})
|
|
|
|
|
2020-04-27 10:58:09 +02:00
|
|
|
it('Should not login if the plugin is uninstalled', async function () {
|
|
|
|
await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-auth-ldap' })
|
|
|
|
|
|
|
|
await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|