PeerTube/server/tests/external-plugins/auth-ldap.ts

111 lines
4.0 KiB
TypeScript
Raw Normal View History

2020-04-27 03:58:09 -05:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import { expect } from 'chai'
import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
2021-07-16 07:27:30 -05:00
import { HttpStatusCode } from '@shared/models'
2020-04-27 03:58:09 -05:00
describe('Official plugin auth-ldap', function () {
2021-07-16 02:47:51 -05:00
let server: PeerTubeServer
2020-04-27 03:58:09 -05:00
let accessToken: string
2021-02-01 02:24:14 -06:00
let userId: number
2020-04-27 03:58:09 -05:00
before(async function () {
this.timeout(30000)
2021-07-16 02:47:51 -05:00
server = await createSingleServer(1)
2020-04-27 03:58:09 -05:00
await setAccessTokensToServers([ server ])
2021-07-16 02:04:35 -05:00
await server.plugins.install({ npmName: 'peertube-plugin-auth-ldap' })
2020-04-27 03:58:09 -05:00
})
it('Should not login with without LDAP settings', async function () {
2021-07-16 02:04:35 -05:00
await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
2020-04-27 03:58:09 -05:00
})
it('Should not login with bad LDAP settings', async function () {
2021-07-16 02:04:35 -05:00
await server.plugins.updateSettings({
2020-04-27 03:58:09 -05: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 09:58:32 -05:00
'url': 'ldap://localhost:390',
2020-04-27 03:58:09 -05:00
'username-property': 'uid'
}
})
2021-07-16 02:04:35 -05:00
await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
2020-04-27 03:58:09 -05:00
})
it('Should not login with good LDAP settings but wrong username/password', async function () {
2021-07-16 02:04:35 -05:00
await server.plugins.updateSettings({
2020-04-27 03:58:09 -05: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 04:21:19 -06:00
'url': 'ldap://localhost:10389',
2020-04-27 03:58:09 -05:00
'username-property': 'uid'
}
})
2021-07-16 02:04:35 -05: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 03:58:09 -05:00
})
it('Should login with the appropriate username/password', async function () {
2021-07-16 02:04:35 -05:00
accessToken = await server.login.getAccessToken({ username: 'fry', password: 'fry' })
2020-04-27 03:58:09 -05:00
})
it('Should login with the appropriate email/password', async function () {
2021-07-16 02:04:35 -05:00
accessToken = await server.login.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' })
2020-04-27 03:58:09 -05:00
})
it('Should login get my profile', async function () {
2021-07-16 02:04:35 -05:00
const body = await server.users.getMyInfo({ token: accessToken })
2020-04-27 03:58:09 -05:00
expect(body.username).to.equal('fry')
expect(body.email).to.equal('fry@planetexpress.com')
2021-02-01 02:24:14 -06:00
userId = body.id
2020-04-27 03:58:09 -05:00
})
it('Should upload a video', async function () {
2021-07-16 02:04:35 -05:00
await server.videos.upload({ token: accessToken, attributes: { name: 'my super video' } })
2020-04-27 03:58:09 -05:00
})
2021-02-01 02:24:14 -06:00
it('Should not be able to login if the user is banned', async function () {
2021-07-16 02:04:35 -05:00
await server.users.banUser({ userId })
2021-02-01 02:24:14 -06:00
2021-07-16 02:04:35 -05:00
await server.login.login({
2021-07-13 04:05:15 -05:00
user: { username: 'fry@planetexpress.com', password: 'fry' },
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
2021-02-01 02:24:14 -06:00
})
it('Should be able to login if the user is unbanned', async function () {
2021-07-16 02:04:35 -05:00
await server.users.unbanUser({ userId })
2021-02-01 02:24:14 -06:00
2021-07-16 02:04:35 -05:00
await server.login.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } })
2021-02-01 02:24:14 -06:00
})
2020-04-27 03:58:09 -05:00
it('Should not login if the plugin is uninstalled', async function () {
2021-07-16 02:04:35 -05:00
await server.plugins.uninstall({ npmName: 'peertube-plugin-auth-ldap' })
2020-04-27 03:58:09 -05:00
2021-07-16 02:04:35 -05:00
await server.login.login({
2021-07-13 04:05:15 -05:00
user: { username: 'fry@planetexpress.com', password: 'fry' },
expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
2020-04-27 03:58:09 -05:00
})
after(async function () {
await cleanupTests([ server ])
})
})