2020-04-27 10:58:09 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import { expect } from 'chai'
|
2021-12-17 09:29:23 +01:00
|
|
|
import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
|
2021-07-16 14:27:30 +02:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2020-04-27 10:58:09 +02:00
|
|
|
|
|
|
|
describe('Official plugin auth-ldap', function () {
|
2021-07-16 09:47:51 +02:00
|
|
|
let server: PeerTubeServer
|
2020-04-27 10:58:09 +02:00
|
|
|
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)
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
server = await createSingleServer(1)
|
2020-04-27 10:58:09 +02:00
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.plugins.install({ npmName: 'peertube-plugin-auth-ldap' })
|
2020-04-27 10:58:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with without LDAP settings', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2020-04-27 10:58:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with bad LDAP settings', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.plugins.updateSettings({
|
2020-04-27 10:58:09 +02:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2020-04-27 10:58:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with good LDAP settings but wrong username/password', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.plugins.updateSettings({
|
2020-04-27 10:58:09 +02:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.login.login({ user: { username: 'fry', password: 'bad password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
|
|
|
await server.login.login({ user: { username: 'fryr', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2020-04-27 10:58:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should login with the appropriate username/password', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
accessToken = await server.login.getAccessToken({ username: 'fry', password: 'fry' })
|
2020-04-27 10:58:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should login with the appropriate email/password', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
accessToken = await server.login.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' })
|
2020-04-27 10:58:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should login get my profile', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
const body = await server.users.getMyInfo({ token: accessToken })
|
2020-04-27 10:58:09 +02:00
|
|
|
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 () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.videos.upload({ token: accessToken, attributes: { name: 'my super video' } })
|
2020-04-27 10:58:09 +02:00
|
|
|
})
|
|
|
|
|
2021-02-01 09:24:14 +01:00
|
|
|
it('Should not be able to login if the user is banned', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.users.banUser({ userId })
|
2021-02-01 09:24:14 +01:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.login.login({
|
2021-07-13 11:05:15 +02:00
|
|
|
user: { username: 'fry@planetexpress.com', password: 'fry' },
|
|
|
|
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
|
|
|
})
|
2021-02-01 09:24:14 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should be able to login if the user is unbanned', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.users.unbanUser({ userId })
|
2021-02-01 09:24:14 +01:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.login.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } })
|
2021-02-01 09:24:14 +01:00
|
|
|
})
|
|
|
|
|
2022-09-28 16:00:32 +02:00
|
|
|
it('Should not be able to ask password reset', async function () {
|
|
|
|
await server.users.askResetPassword({ email: 'fry@planetexpress.com', expectedStatus: HttpStatusCode.CONFLICT_409 })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to ask email verification', async function () {
|
|
|
|
await server.users.askSendVerifyEmail({ email: 'fry@planetexpress.com', expectedStatus: HttpStatusCode.CONFLICT_409 })
|
|
|
|
})
|
|
|
|
|
2020-04-27 10:58:09 +02:00
|
|
|
it('Should not login if the plugin is uninstalled', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.plugins.uninstall({ npmName: 'peertube-plugin-auth-ldap' })
|
2020-04-27 10:58:09 +02:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
await server.login.login({
|
2021-07-13 11:05:15 +02:00
|
|
|
user: { username: 'fry@planetexpress.com', password: 'fry' },
|
|
|
|
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
|
|
|
})
|
2020-04-27 10:58:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|