]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/external-plugins/auth-ldap.ts
Shorter server command names
[github/Chocobozzz/PeerTube.git] / server / tests / external-plugins / auth-ldap.ts
index bb02fbc0292e01d65ca7b1f401c589a4caba68bf..ef624152e6160bdf343f65f34c59c51b8a76a52d 100644 (file)
@@ -2,21 +2,13 @@
 
 import 'mocha'
 import { expect } from 'chai'
-import { User } from '@shared/models/users/user.model'
-import {
-  getMyUserInformation,
-  installPlugin,
-  setAccessTokensToServers,
-  uninstallPlugin,
-  updatePluginSettings,
-  uploadVideo,
-  userLogin
-} from '../../../shared/extra-utils'
-import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
+import { HttpStatusCode } from '@shared/core-utils'
+import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
 
 describe('Official plugin auth-ldap', function () {
   let server: ServerInfo
   let accessToken: string
+  let userId: number
 
   before(async function () {
     this.timeout(30000)
@@ -24,21 +16,15 @@ describe('Official plugin auth-ldap', function () {
     server = await flushAndRunServer(1)
     await setAccessTokensToServers([ server ])
 
-    await installPlugin({
-      url: server.url,
-      accessToken: server.accessToken,
-      npmName: 'peertube-plugin-auth-ldap'
-    })
+    await server.plugins.install({ npmName: 'peertube-plugin-auth-ldap' })
   })
 
   it('Should not login with without LDAP settings', async function () {
-    await userLogin(server, { username: 'fry', password: 'fry' }, 400)
+    await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
   })
 
   it('Should not login with bad LDAP settings', async function () {
-    await updatePluginSettings({
-      url: server.url,
-      accessToken: server.accessToken,
+    await server.plugins.updateSettings({
       npmName: 'peertube-plugin-auth-ldap',
       settings: {
         'bind-credentials': 'GoodNewsEveryone',
@@ -52,13 +38,11 @@ describe('Official plugin auth-ldap', function () {
       }
     })
 
-    await userLogin(server, { username: 'fry', password: 'fry' }, 400)
+    await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
   })
 
   it('Should not login with good LDAP settings but wrong username/password', async function () {
-    await updatePluginSettings({
-      url: server.url,
-      accessToken: server.accessToken,
+    await server.plugins.updateSettings({
       npmName: 'peertube-plugin-auth-ldap',
       settings: {
         'bind-credentials': 'GoodNewsEveryone',
@@ -67,39 +51,57 @@ describe('Official plugin auth-ldap', function () {
         'mail-property': 'mail',
         'search-base': 'ou=people,dc=planetexpress,dc=com',
         'search-filter': '(|(mail={{username}})(uid={{username}}))',
-        'url': 'ldap://localhost:389',
+        'url': 'ldap://localhost:10389',
         'username-property': 'uid'
       }
     })
 
-    await userLogin(server, { username: 'fry', password: 'bad password' }, 400)
-    await userLogin(server, { username: 'fryr', password: 'fry' }, 400)
+    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 })
   })
 
   it('Should login with the appropriate username/password', async function () {
-    accessToken = await userLogin(server, { username: 'fry', password: 'fry' })
+    accessToken = await server.login.getAccessToken({ username: 'fry', password: 'fry' })
   })
 
   it('Should login with the appropriate email/password', async function () {
-    accessToken = await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' })
+    accessToken = await server.login.getAccessToken({ 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
-
+    const body = await server.users.getMyInfo({ token: accessToken })
     expect(body.username).to.equal('fry')
     expect(body.email).to.equal('fry@planetexpress.com')
+
+    userId = body.id
   })
 
   it('Should upload a video', async function () {
-    await uploadVideo(server.url, accessToken, { name: 'my super video' })
+    await server.videos.upload({ token: accessToken, attributes: { name: 'my super video' } })
+  })
+
+  it('Should not be able to login if the user is banned', async function () {
+    await server.users.banUser({ userId })
+
+    await server.login.login({
+      user: { username: 'fry@planetexpress.com', password: 'fry' },
+      expectedStatus: HttpStatusCode.BAD_REQUEST_400
+    })
+  })
+
+  it('Should be able to login if the user is unbanned', async function () {
+    await server.users.unbanUser({ userId })
+
+    await server.login.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } })
   })
 
   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 server.plugins.uninstall({ npmName: 'peertube-plugin-auth-ldap' })
 
-    await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400)
+    await server.login.login({
+      user: { username: 'fry@planetexpress.com', password: 'fry' },
+      expectedStatus: HttpStatusCode.BAD_REQUEST_400
+    })
   })
 
   after(async function () {