diff options
author | Chocobozzz <chocobozzz@framasoft.org> | 2020-11-20 15:36:43 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@framasoft.org> | 2020-11-20 15:36:43 +0100 |
commit | 74fd2643b43057c25558b3da79398efe104e2660 (patch) | |
tree | 4fd7dd84775780eed82bc4b3caaa328c3526a14c /server/tests | |
parent | 8f3ad70874f8769f5340632754dc2ca7f4c82733 (diff) | |
download | PeerTube-74fd2643b43057c25558b3da79398efe104e2660.tar.gz PeerTube-74fd2643b43057c25558b3da79398efe104e2660.tar.zst PeerTube-74fd2643b43057c25558b3da79398efe104e2660.zip |
Provide express request to onLogout call
+ pluginInfo related changes
Diffstat (limited to 'server/tests')
3 files changed, 103 insertions, 4 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-external-auth-three/main.js b/server/tests/fixtures/peertube-plugin-test-external-auth-three/main.js new file mode 100644 index 000000000..30cedccc6 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-external-auth-three/main.js | |||
@@ -0,0 +1,53 @@ | |||
1 | async function register ({ | ||
2 | registerExternalAuth, | ||
3 | peertubeHelpers | ||
4 | }) { | ||
5 | { | ||
6 | const result = registerExternalAuth({ | ||
7 | authName: 'external-auth-7', | ||
8 | authDisplayName: () => 'External Auth 7', | ||
9 | onAuthRequest: (req, res) => { | ||
10 | result.userAuthenticated({ | ||
11 | req, | ||
12 | res, | ||
13 | username: 'cid', | ||
14 | email: 'cid@example.com', | ||
15 | displayName: 'Cid Marquez' | ||
16 | }) | ||
17 | }, | ||
18 | onLogout: (user, req) => { | ||
19 | return 'https://example.com/redirectUrl' | ||
20 | } | ||
21 | }) | ||
22 | } | ||
23 | |||
24 | { | ||
25 | const result = registerExternalAuth({ | ||
26 | authName: 'external-auth-8', | ||
27 | authDisplayName: () => 'External Auth 8', | ||
28 | onAuthRequest: (req, res) => { | ||
29 | result.userAuthenticated({ | ||
30 | req, | ||
31 | res, | ||
32 | username: 'cid', | ||
33 | email: 'cid@example.com', | ||
34 | displayName: 'Cid Marquez' | ||
35 | }) | ||
36 | }, | ||
37 | onLogout: (user, req) => { | ||
38 | return 'https://example.com/redirectUrl?access_token=' + req.headers['authorization'].split(' ')[1] | ||
39 | } | ||
40 | }) | ||
41 | } | ||
42 | } | ||
43 | |||
44 | async function unregister () { | ||
45 | |||
46 | } | ||
47 | |||
48 | module.exports = { | ||
49 | register, | ||
50 | unregister | ||
51 | } | ||
52 | |||
53 | // ########################################################################### | ||
diff --git a/server/tests/fixtures/peertube-plugin-test-external-auth-three/package.json b/server/tests/fixtures/peertube-plugin-test-external-auth-three/package.json new file mode 100644 index 000000000..f323d189d --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-external-auth-three/package.json | |||
@@ -0,0 +1,20 @@ | |||
1 | { | ||
2 | "name": "peertube-plugin-test-external-auth-three", | ||
3 | "version": "0.0.1", | ||
4 | "description": "External auth three", | ||
5 | "engine": { | ||
6 | "peertube": ">=1.3.0" | ||
7 | }, | ||
8 | "keywords": [ | ||
9 | "peertube", | ||
10 | "plugin" | ||
11 | ], | ||
12 | "homepage": "https://github.com/Chocobozzz/PeerTube", | ||
13 | "author": "Chocobozzz", | ||
14 | "bugs": "https://github.com/Chocobozzz/PeerTube/issues", | ||
15 | "library": "./main.js", | ||
16 | "staticDirs": {}, | ||
17 | "css": [], | ||
18 | "clientScripts": [], | ||
19 | "translations": {} | ||
20 | } | ||
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index 57361be05..6d907cc51 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts | |||
@@ -73,7 +73,7 @@ describe('Test external auth plugins', function () { | |||
73 | server = await flushAndRunServer(1) | 73 | server = await flushAndRunServer(1) |
74 | await setAccessTokensToServers([ server ]) | 74 | await setAccessTokensToServers([ server ]) |
75 | 75 | ||
76 | for (const suffix of [ 'one', 'two' ]) { | 76 | for (const suffix of [ 'one', 'two', 'three' ]) { |
77 | await installPlugin({ | 77 | await installPlugin({ |
78 | url: server.url, | 78 | url: server.url, |
79 | accessToken: server.accessToken, | 79 | accessToken: server.accessToken, |
@@ -88,7 +88,7 @@ describe('Test external auth plugins', function () { | |||
88 | const config: ServerConfig = res.body | 88 | const config: ServerConfig = res.body |
89 | 89 | ||
90 | const auths = config.plugin.registeredExternalAuths | 90 | const auths = config.plugin.registeredExternalAuths |
91 | expect(auths).to.have.lengthOf(6) | 91 | expect(auths).to.have.lengthOf(8) |
92 | 92 | ||
93 | const auth2 = auths.find((a) => a.authName === 'external-auth-2') | 93 | const auth2 = auths.find((a) => a.authName === 'external-auth-2') |
94 | expect(auth2).to.exist | 94 | expect(auth2).to.exist |
@@ -301,7 +301,7 @@ describe('Test external auth plugins', function () { | |||
301 | const config: ServerConfig = res.body | 301 | const config: ServerConfig = res.body |
302 | 302 | ||
303 | const auths = config.plugin.registeredExternalAuths | 303 | const auths = config.plugin.registeredExternalAuths |
304 | expect(auths).to.have.lengthOf(5) | 304 | expect(auths).to.have.lengthOf(7) |
305 | 305 | ||
306 | const auth1 = auths.find(a => a.authName === 'external-auth-2') | 306 | const auth1 = auths.find(a => a.authName === 'external-auth-2') |
307 | expect(auth1).to.not.exist | 307 | expect(auth1).to.not.exist |
@@ -371,7 +371,7 @@ describe('Test external auth plugins', function () { | |||
371 | const config: ServerConfig = res.body | 371 | const config: ServerConfig = res.body |
372 | 372 | ||
373 | const auths = config.plugin.registeredExternalAuths | 373 | const auths = config.plugin.registeredExternalAuths |
374 | expect(auths).to.have.lengthOf(4) | 374 | expect(auths).to.have.lengthOf(6) |
375 | 375 | ||
376 | const auth2 = auths.find((a) => a.authName === 'external-auth-2') | 376 | const auth2 = auths.find((a) => a.authName === 'external-auth-2') |
377 | expect(auth2).to.not.exist | 377 | expect(auth2).to.not.exist |
@@ -380,4 +380,30 @@ describe('Test external auth plugins', function () { | |||
380 | after(async function () { | 380 | after(async function () { |
381 | await cleanupTests([ server ]) | 381 | await cleanupTests([ server ]) |
382 | }) | 382 | }) |
383 | |||
384 | it('Should forward the redirectUrl if the plugin returns one', async function () { | ||
385 | const resLogin = await loginExternal({ | ||
386 | server, | ||
387 | npmName: 'test-external-auth-three', | ||
388 | authName: 'external-auth-7', | ||
389 | username: 'cid' | ||
390 | }) | ||
391 | |||
392 | const resLogout = await logout(server.url, resLogin.access_token) | ||
393 | |||
394 | expect(resLogout.body.redirectUrl).to.equal('https://example.com/redirectUrl') | ||
395 | }) | ||
396 | |||
397 | it('Should call the plugin\'s onLogout method with the request', async function () { | ||
398 | const resLogin = await loginExternal({ | ||
399 | server, | ||
400 | npmName: 'test-external-auth-three', | ||
401 | authName: 'external-auth-8', | ||
402 | username: 'cid' | ||
403 | }) | ||
404 | |||
405 | const resLogout = await logout(server.url, resLogin.access_token) | ||
406 | |||
407 | expect(resLogout.body.redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token) | ||
408 | }) | ||
383 | }) | 409 | }) |