aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-10-25 13:54:32 +0200
committerChocobozzz <me@florianbigard.com>2019-10-25 13:54:32 +0200
commit4ce7eb71ba28a563336c07d10c182ff89461c72b (patch)
tree9350704adae97d145548d0b2cfdde3bd95b56dd5 /server/tests
parent45863288582a788def282ec25d437b1795510315 (diff)
downloadPeerTube-4ce7eb71ba28a563336c07d10c182ff89461c72b.tar.gz
PeerTube-4ce7eb71ba28a563336c07d10c182ff89461c72b.tar.zst
PeerTube-4ce7eb71ba28a563336c07d10c182ff89461c72b.zip
Add plugin hook on registration
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js11
-rw-r--r--server/tests/plugins/filter-hooks.ts21
2 files changed, 31 insertions, 1 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index 7c53f6afe..055884d29 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -86,6 +86,17 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
86 return false 86 return false
87 } 87 }
88 }) 88 })
89
90 registerHook({
91 target: 'filter:api.user.signup.allowed.result',
92 handler: (result, params) => {
93 if (params && params.body.email.includes('jma')) {
94 return { allowed: false, errorMessage: 'No jma' }
95 }
96
97 return result
98 }
99 })
89} 100}
90 101
91async function unregister () { 102async function unregister () {
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index ec0679b04..b2436fb9e 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -28,11 +28,12 @@ import {
28 getVideoWithToken, 28 getVideoWithToken,
29 setDefaultVideoChannel, 29 setDefaultVideoChannel,
30 waitJobs, 30 waitJobs,
31 doubleFollow 31 doubleFollow, getConfig, registerUser
32} from '../../../shared/extra-utils' 32} from '../../../shared/extra-utils'
33import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' 33import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
34import { VideoDetails } from '../../../shared/models/videos' 34import { VideoDetails } from '../../../shared/models/videos'
35import { getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports' 35import { getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports'
36import { ServerConfig } from '@shared/models'
36 37
37const expect = chai.expect 38const expect = chai.expect
38 39
@@ -187,6 +188,24 @@ describe('Test plugin filter hooks', function () {
187 }) 188 })
188 }) 189 })
189 190
191 describe('Should run filter:api.user.signup.allowed.result', function () {
192
193 it('Should run on config endpoint', async function () {
194 const res = await getConfig(servers[0].url)
195 expect((res.body as ServerConfig).signup.allowed).to.be.true
196 })
197
198 it('Should allow a signup', async function () {
199 await registerUser(servers[0].url, 'john', 'password')
200 })
201
202 it('Should not allow a signup', async function () {
203 const res = await registerUser(servers[0].url, 'jma', 'password', 403)
204
205 expect(res.body.error).to.equal('No jma')
206 })
207 })
208
190 after(async function () { 209 after(async function () {
191 await cleanupTests(servers) 210 await cleanupTests(servers)
192 }) 211 })