diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-29 09:04:42 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-04 16:21:39 +0200 |
commit | 9107d791e2eef9a1b24b0499dac8b9dbba8a792f (patch) | |
tree | f09b20f06008b094f3266b39063bc9785dfebf5f /server/tests/fixtures | |
parent | 4a8d113b9b57d97ff13ad1608798eabca99643e4 (diff) | |
download | PeerTube-9107d791e2eef9a1b24b0499dac8b9dbba8a792f.tar.gz PeerTube-9107d791e2eef9a1b24b0499dac8b9dbba8a792f.tar.zst PeerTube-9107d791e2eef9a1b24b0499dac8b9dbba8a792f.zip |
Add external login tests
Diffstat (limited to 'server/tests/fixtures')
4 files changed, 138 insertions, 0 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js b/server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js new file mode 100644 index 000000000..f29fd1f30 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js | |||
@@ -0,0 +1,67 @@ | |||
1 | async function register ({ | ||
2 | registerExternalAuth, | ||
3 | peertubeHelpers | ||
4 | }) { | ||
5 | { | ||
6 | const result = registerExternalAuth({ | ||
7 | authName: 'external-auth-1', | ||
8 | authDisplayName: 'External Auth 1', | ||
9 | onLogout: user => peertubeHelpers.logger.info('On logout %s', user.username), | ||
10 | onAuthRequest: (req, res) => { | ||
11 | const username = req.query.username | ||
12 | |||
13 | result.userAuthenticated({ | ||
14 | req, | ||
15 | res, | ||
16 | username, | ||
17 | email: username + '@example.com' | ||
18 | }) | ||
19 | } | ||
20 | }) | ||
21 | } | ||
22 | |||
23 | { | ||
24 | const result = registerExternalAuth({ | ||
25 | authName: 'external-auth-2', | ||
26 | authDisplayName: 'External Auth 2', | ||
27 | onAuthRequest: (req, res) => { | ||
28 | result.userAuthenticated({ | ||
29 | req, | ||
30 | res, | ||
31 | username: 'kefka', | ||
32 | email: 'kefka@example.com', | ||
33 | role: 0, | ||
34 | displayName: 'Kefka Palazzo' | ||
35 | }) | ||
36 | }, | ||
37 | hookTokenValidity: (options) => { | ||
38 | if (options.type === 'refresh') { | ||
39 | return { valid: false } | ||
40 | } | ||
41 | |||
42 | if (options.type === 'access') { | ||
43 | const token = options.token | ||
44 | const now = new Date() | ||
45 | now.setTime(now.getTime() - 5000) | ||
46 | |||
47 | const createdAt = new Date(token.createdAt) | ||
48 | |||
49 | return { valid: createdAt.getTime() >= now.getTime() } | ||
50 | } | ||
51 | |||
52 | return { valid: true } | ||
53 | } | ||
54 | }) | ||
55 | } | ||
56 | } | ||
57 | |||
58 | async function unregister () { | ||
59 | return | ||
60 | } | ||
61 | |||
62 | module.exports = { | ||
63 | register, | ||
64 | unregister | ||
65 | } | ||
66 | |||
67 | // ########################################################################### | ||
diff --git a/server/tests/fixtures/peertube-plugin-test-external-auth-one/package.json b/server/tests/fixtures/peertube-plugin-test-external-auth-one/package.json new file mode 100644 index 000000000..22814b047 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-external-auth-one/package.json | |||
@@ -0,0 +1,20 @@ | |||
1 | { | ||
2 | "name": "peertube-plugin-test-external-auth-one", | ||
3 | "version": "0.0.1", | ||
4 | "description": "External auth one", | ||
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/fixtures/peertube-plugin-test-external-auth-two/main.js b/server/tests/fixtures/peertube-plugin-test-external-auth-two/main.js new file mode 100644 index 000000000..34fec1bb3 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-external-auth-two/main.js | |||
@@ -0,0 +1,31 @@ | |||
1 | async function register ({ | ||
2 | registerExternalAuth, | ||
3 | peertubeHelpers | ||
4 | }) { | ||
5 | { | ||
6 | const result = registerExternalAuth({ | ||
7 | authName: 'external-auth-3', | ||
8 | authDisplayName: 'External Auth 3', | ||
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 | }) | ||
19 | } | ||
20 | } | ||
21 | |||
22 | async function unregister () { | ||
23 | return | ||
24 | } | ||
25 | |||
26 | module.exports = { | ||
27 | register, | ||
28 | unregister | ||
29 | } | ||
30 | |||
31 | // ########################################################################### | ||
diff --git a/server/tests/fixtures/peertube-plugin-test-external-auth-two/package.json b/server/tests/fixtures/peertube-plugin-test-external-auth-two/package.json new file mode 100644 index 000000000..a5ca4d07a --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-external-auth-two/package.json | |||
@@ -0,0 +1,20 @@ | |||
1 | { | ||
2 | "name": "peertube-plugin-test-external-auth-two", | ||
3 | "version": "0.0.1", | ||
4 | "description": "External auth two", | ||
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 | } | ||