aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-27 10:58:09 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-05-04 16:21:39 +0200
commit829b794a8542b55bdfff481fa7c3593bc88cb696 (patch)
tree0f493580cad5b915f76eef5de174b2ba5e7204c5
parent2db9c70f670c2210d103062fa143dc4888caa190 (diff)
downloadPeerTube-829b794a8542b55bdfff481fa7c3593bc88cb696.tar.gz
PeerTube-829b794a8542b55bdfff481fa7c3593bc88cb696.tar.zst
PeerTube-829b794a8542b55bdfff481fa7c3593bc88cb696.zip
Add plugin ldap tests
-rw-r--r--.gitlab-ci.yml31
-rwxr-xr-xscripts/ci.sh3
-rw-r--r--server/tests/external-plugins/auth-ldap.ts100
-rw-r--r--server/tests/external-plugins/index.ts1
4 files changed, 134 insertions, 1 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 64c818476..0305171c7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,6 +5,7 @@ stages:
5 - test 5 - test
6 - clients 6 - clients
7 - docker-nightly 7 - docker-nightly
8 - external-plugins
8 9
9#before_script: 10#before_script:
10# - 'sed -i -z "s/database:\n hostname: ''localhost''/database:\n hostname: ''postgres''/" config/test.yaml' 11# - 'sed -i -z "s/database:\n hostname: ''localhost''/database:\n hostname: ''postgres''/" config/test.yaml'
@@ -93,7 +94,7 @@ build-openapi-clients:
93 - schedules 94 - schedules
94 changes: 95 changes:
95 - support/doc/api/openapi.yaml 96 - support/doc/api/openapi.yaml
96 script: 97 script:
97 - apt-get update -qq 98 - apt-get update -qq
98 - apt-get -yqqq install openjdk-8-jre 99 - apt-get -yqqq install openjdk-8-jre
99 - yarn install --pure-lockfile 100 - yarn install --pure-lockfile
@@ -145,3 +146,31 @@ build-docker-master:
145 - master 146 - master
146 variables: 147 variables:
147 DOCKER_IMAGE_NAME: chocobozzz/peertube:production-buster 148 DOCKER_IMAGE_NAME: chocobozzz/peertube:production-buster
149
150test-external-plugins:
151 stage: external-plugins
152 only:
153 - schedules
154 services:
155 - name: postgres:9.6
156 alias: postgres
157 - name: redis:latest
158 alias: redis
159 - name: rroemhild/test-openldap
160 alias: ldap
161 variables:
162 PGHOST: postgres
163 PGUSER: postgres
164 REDIS_HOST: redis
165 artifacts:
166 expire_in: 1 day
167 paths:
168 - test*/logs
169 when: always
170 before_script:
171 - 'sed -i -z "s/database:\n hostname: ''localhost''/database:\n hostname: ''postgres''/" config/test.yaml'
172 - 'sed -i -z "s/redis:\n hostname: ''localhost''/redis:\n hostname: ''redis''/" config/test.yaml'
173 - psql -c "create user peertube with password 'peertube';"; fi
174 - NOCLIENT=1 yarn install --pure-lockfile --cache-folder .yarn-cache
175 script:
176 - npm run ci -- "external-plugins" \ No newline at end of file
diff --git a/scripts/ci.sh b/scripts/ci.sh
index aea009d9f..7854d88fc 100755
--- a/scripts/ci.sh
+++ b/scripts/ci.sh
@@ -34,6 +34,9 @@ elif [ "$1" = "api-3" ]; then
34elif [ "$1" = "api-4" ]; then 34elif [ "$1" = "api-4" ]; then
35 npm run build:server 35 npm run build:server
36 sh ./server/tests/api/ci-4.sh 2 36 sh ./server/tests/api/ci-4.sh 2
37elif [ "$1" = "external-plugins" ]; then
38 npm run build:server
39 mocha --timeout 5000 --exit --require ts-node/register --require tsconfig-paths/register --bail server/tests/external-plugins/index.ts
37elif [ "$1" = "lint" ]; then 40elif [ "$1" = "lint" ]; then
38 npm run eslint -- --ext .ts "server/**/*.ts" "shared/**/*.ts" 41 npm run eslint -- --ext .ts "server/**/*.ts" "shared/**/*.ts"
39 npm run swagger-cli -- validate support/doc/api/openapi.yaml 42 npm run swagger-cli -- validate support/doc/api/openapi.yaml
diff --git a/server/tests/external-plugins/auth-ldap.ts b/server/tests/external-plugins/auth-ldap.ts
new file mode 100644
index 000000000..7aee986c7
--- /dev/null
+++ b/server/tests/external-plugins/auth-ldap.ts
@@ -0,0 +1,100 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { getMyUserInformation, installPlugin, setAccessTokensToServers, updatePluginSettings, userLogin, uploadVideo, uninstallPlugin } from '../../../shared/extra-utils'
5import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
6import { User } from '@shared/models/users/user.model'
7import { expect } from 'chai'
8
9describe('Official plugin auth-ldap', function () {
10 let server: ServerInfo
11 let accessToken: string
12
13 before(async function () {
14 this.timeout(30000)
15
16 server = await flushAndRunServer(1)
17 await setAccessTokensToServers([ server ])
18
19 await installPlugin({
20 url: server.url,
21 accessToken: server.accessToken,
22 npmName: 'peertube-plugin-auth-ldap'
23 })
24 })
25
26 it('Should not login with without LDAP settings', async function () {
27 await userLogin(server, { username: 'fry', password: 'fry' }, 400)
28 })
29
30 it('Should not login with bad LDAP settings', async function () {
31 await updatePluginSettings({
32 url: server.url,
33 accessToken: server.accessToken,
34 npmName: 'peertube-plugin-auth-ldap',
35 settings: {
36 'bind-credentials': 'GoodNewsEveryone',
37 'bind-dn': 'cn=admin,dc=planetexpress,dc=com',
38 'insecure-tls': false,
39 'mail-property': 'mail',
40 'search-base': 'ou=people,dc=planetexpress,dc=com',
41 'search-filter': '(|(mail={{username}})(uid={{username}}))',
42 'url': 'ldap://ldap:390',
43 'username-property': 'uid'
44 }
45 })
46
47 await userLogin(server, { username: 'fry', password: 'fry' }, 400)
48 })
49
50 it('Should not login with good LDAP settings but wrong username/password', async function () {
51 await updatePluginSettings({
52 url: server.url,
53 accessToken: server.accessToken,
54 npmName: 'peertube-plugin-auth-ldap',
55 settings: {
56 'bind-credentials': 'GoodNewsEveryone',
57 'bind-dn': 'cn=admin,dc=planetexpress,dc=com',
58 'insecure-tls': false,
59 'mail-property': 'mail',
60 'search-base': 'ou=people,dc=planetexpress,dc=com',
61 'search-filter': '(|(mail={{username}})(uid={{username}}))',
62 'url': 'ldap://ldap:389',
63 'username-property': 'uid'
64 }
65 })
66
67 await userLogin(server, { username: 'fry', password: 'bad password' }, 400)
68 await userLogin(server, { username: 'fryr', password: 'fry' }, 400)
69 })
70
71 it('Should login with the appropriate username/password', async function () {
72 accessToken = await userLogin(server, { username: 'fry', password: 'fry' })
73 })
74
75 it('Should login with the appropriate email/password', async function () {
76 accessToken = await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' })
77 })
78
79 it('Should login get my profile', async function () {
80 const res = await getMyUserInformation(server.url, accessToken)
81 const body: User = res.body
82
83 expect(body.username).to.equal('fry')
84 expect(body.email).to.equal('fry@planetexpress.com')
85 })
86
87 it('Should upload a video', async function () {
88 await uploadVideo(server.url, accessToken, { name: 'my super video' })
89 })
90
91 it('Should not login if the plugin is uninstalled', async function () {
92 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-auth-ldap' })
93
94 await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400)
95 })
96
97 after(async function () {
98 await cleanupTests([ server ])
99 })
100})
diff --git a/server/tests/external-plugins/index.ts b/server/tests/external-plugins/index.ts
new file mode 100644
index 000000000..1f1236c69
--- /dev/null
+++ b/server/tests/external-plugins/index.ts
@@ -0,0 +1 @@
export * from './auth-ldap'