auth-ldap.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import 'mocha'
  3. import { expect } from 'chai'
  4. import { User } from '@shared/models/users/user.model'
  5. import {
  6. getMyUserInformation,
  7. installPlugin,
  8. setAccessTokensToServers,
  9. uninstallPlugin,
  10. updatePluginSettings,
  11. uploadVideo,
  12. userLogin
  13. } from '../../../shared/extra-utils'
  14. import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
  15. describe('Official plugin auth-ldap', function () {
  16. let server: ServerInfo
  17. let accessToken: string
  18. before(async function () {
  19. this.timeout(30000)
  20. server = await flushAndRunServer(1)
  21. await setAccessTokensToServers([ server ])
  22. await installPlugin({
  23. url: server.url,
  24. accessToken: server.accessToken,
  25. npmName: 'peertube-plugin-auth-ldap'
  26. })
  27. })
  28. it('Should not login with without LDAP settings', async function () {
  29. await userLogin(server, { username: 'fry', password: 'fry' }, 400)
  30. })
  31. it('Should not login with bad LDAP settings', async function () {
  32. await updatePluginSettings({
  33. url: server.url,
  34. accessToken: server.accessToken,
  35. npmName: 'peertube-plugin-auth-ldap',
  36. settings: {
  37. 'bind-credentials': 'GoodNewsEveryone',
  38. 'bind-dn': 'cn=admin,dc=planetexpress,dc=com',
  39. 'insecure-tls': false,
  40. 'mail-property': 'mail',
  41. 'search-base': 'ou=people,dc=planetexpress,dc=com',
  42. 'search-filter': '(|(mail={{username}})(uid={{username}}))',
  43. 'url': 'ldap://localhost:390',
  44. 'username-property': 'uid'
  45. }
  46. })
  47. await userLogin(server, { username: 'fry', password: 'fry' }, 400)
  48. })
  49. it('Should not login with good LDAP settings but wrong username/password', async function () {
  50. await updatePluginSettings({
  51. url: server.url,
  52. accessToken: server.accessToken,
  53. npmName: 'peertube-plugin-auth-ldap',
  54. settings: {
  55. 'bind-credentials': 'GoodNewsEveryone',
  56. 'bind-dn': 'cn=admin,dc=planetexpress,dc=com',
  57. 'insecure-tls': false,
  58. 'mail-property': 'mail',
  59. 'search-base': 'ou=people,dc=planetexpress,dc=com',
  60. 'search-filter': '(|(mail={{username}})(uid={{username}}))',
  61. 'url': 'ldap://localhost:389',
  62. 'username-property': 'uid'
  63. }
  64. })
  65. await userLogin(server, { username: 'fry', password: 'bad password' }, 400)
  66. await userLogin(server, { username: 'fryr', password: 'fry' }, 400)
  67. })
  68. it('Should login with the appropriate username/password', async function () {
  69. accessToken = await userLogin(server, { username: 'fry', password: 'fry' })
  70. })
  71. it('Should login with the appropriate email/password', async function () {
  72. accessToken = await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' })
  73. })
  74. it('Should login get my profile', async function () {
  75. const res = await getMyUserInformation(server.url, accessToken)
  76. const body: User = res.body
  77. expect(body.username).to.equal('fry')
  78. expect(body.email).to.equal('fry@planetexpress.com')
  79. })
  80. it('Should upload a video', async function () {
  81. await uploadVideo(server.url, accessToken, { name: 'my super video' })
  82. })
  83. it('Should not login if the plugin is uninstalled', async function () {
  84. await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-auth-ldap' })
  85. await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400)
  86. })
  87. after(async function () {
  88. await cleanupTests([ server ])
  89. })
  90. })