diff options
Diffstat (limited to 'server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js')
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js | 75 |
1 files changed, 75 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..c65b8d3a8 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js | |||
@@ -0,0 +1,75 @@ | |||
1 | async function register ({ | ||
2 | registerExternalAuth, | ||
3 | peertubeHelpers, | ||
4 | settingsManager, | ||
5 | unregisterExternalAuth | ||
6 | }) { | ||
7 | { | ||
8 | const result = registerExternalAuth({ | ||
9 | authName: 'external-auth-1', | ||
10 | authDisplayName: () => 'External Auth 1', | ||
11 | onLogout: user => peertubeHelpers.logger.info('On logout %s', user.username), | ||
12 | onAuthRequest: (req, res) => { | ||
13 | const username = req.query.username | ||
14 | |||
15 | result.userAuthenticated({ | ||
16 | req, | ||
17 | res, | ||
18 | username, | ||
19 | email: username + '@example.com' | ||
20 | }) | ||
21 | } | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | { | ||
26 | const result = registerExternalAuth({ | ||
27 | authName: 'external-auth-2', | ||
28 | authDisplayName: () => 'External Auth 2', | ||
29 | onAuthRequest: (req, res) => { | ||
30 | result.userAuthenticated({ | ||
31 | req, | ||
32 | res, | ||
33 | username: 'kefka', | ||
34 | email: 'kefka@example.com', | ||
35 | role: 0, | ||
36 | displayName: 'Kefka Palazzo' | ||
37 | }) | ||
38 | }, | ||
39 | hookTokenValidity: (options) => { | ||
40 | if (options.type === 'refresh') { | ||
41 | return { valid: false } | ||
42 | } | ||
43 | |||
44 | if (options.type === 'access') { | ||
45 | const token = options.token | ||
46 | const now = new Date() | ||
47 | now.setTime(now.getTime() - 5000) | ||
48 | |||
49 | const createdAt = new Date(token.createdAt) | ||
50 | |||
51 | return { valid: createdAt.getTime() >= now.getTime() } | ||
52 | } | ||
53 | |||
54 | return { valid: true } | ||
55 | } | ||
56 | }) | ||
57 | } | ||
58 | |||
59 | settingsManager.onSettingsChange(settings => { | ||
60 | if (settings.disableKefka) { | ||
61 | unregisterExternalAuth('external-auth-2') | ||
62 | } | ||
63 | }) | ||
64 | } | ||
65 | |||
66 | async function unregister () { | ||
67 | return | ||
68 | } | ||
69 | |||
70 | module.exports = { | ||
71 | register, | ||
72 | unregister | ||
73 | } | ||
74 | |||
75 | // ########################################################################### | ||