1
0
Fork 0
peertube/server/tests/external-plugins/auth-ldap.ts

118 lines
4.4 KiB
TypeScript
Raw Normal View History

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