From 9107d791e2eef9a1b24b0499dac8b9dbba8a792f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 29 Apr 2020 09:04:42 +0200 Subject: Add external login tests --- .../peertube-plugin-test-external-auth-one/main.js | 67 ++++++++++++++++++++++ .../package.json | 20 +++++++ .../peertube-plugin-test-external-auth-two/main.js | 31 ++++++++++ .../package.json | 20 +++++++ 4 files changed, 138 insertions(+) create mode 100644 server/tests/fixtures/peertube-plugin-test-external-auth-one/main.js create mode 100644 server/tests/fixtures/peertube-plugin-test-external-auth-one/package.json create mode 100644 server/tests/fixtures/peertube-plugin-test-external-auth-two/main.js create mode 100644 server/tests/fixtures/peertube-plugin-test-external-auth-two/package.json (limited to 'server/tests/fixtures') 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 @@ +async function register ({ + registerExternalAuth, + peertubeHelpers +}) { + { + const result = registerExternalAuth({ + authName: 'external-auth-1', + authDisplayName: 'External Auth 1', + onLogout: user => peertubeHelpers.logger.info('On logout %s', user.username), + onAuthRequest: (req, res) => { + const username = req.query.username + + result.userAuthenticated({ + req, + res, + username, + email: username + '@example.com' + }) + } + }) + } + + { + const result = registerExternalAuth({ + authName: 'external-auth-2', + authDisplayName: 'External Auth 2', + onAuthRequest: (req, res) => { + result.userAuthenticated({ + req, + res, + username: 'kefka', + email: 'kefka@example.com', + role: 0, + displayName: 'Kefka Palazzo' + }) + }, + hookTokenValidity: (options) => { + if (options.type === 'refresh') { + return { valid: false } + } + + if (options.type === 'access') { + const token = options.token + const now = new Date() + now.setTime(now.getTime() - 5000) + + const createdAt = new Date(token.createdAt) + + return { valid: createdAt.getTime() >= now.getTime() } + } + + return { valid: true } + } + }) + } +} + +async function unregister () { + return +} + +module.exports = { + register, + unregister +} + +// ########################################################################### 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 @@ +{ + "name": "peertube-plugin-test-external-auth-one", + "version": "0.0.1", + "description": "External auth one", + "engine": { + "peertube": ">=1.3.0" + }, + "keywords": [ + "peertube", + "plugin" + ], + "homepage": "https://github.com/Chocobozzz/PeerTube", + "author": "Chocobozzz", + "bugs": "https://github.com/Chocobozzz/PeerTube/issues", + "library": "./main.js", + "staticDirs": {}, + "css": [], + "clientScripts": [], + "translations": {} +} 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 @@ +async function register ({ + registerExternalAuth, + peertubeHelpers +}) { + { + const result = registerExternalAuth({ + authName: 'external-auth-3', + authDisplayName: 'External Auth 3', + onAuthRequest: (req, res) => { + result.userAuthenticated({ + req, + res, + username: 'cid', + email: 'cid@example.com', + displayName: 'Cid Marquez' + }) + } + }) + } +} + +async function unregister () { + return +} + +module.exports = { + register, + unregister +} + +// ########################################################################### 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 @@ +{ + "name": "peertube-plugin-test-external-auth-two", + "version": "0.0.1", + "description": "External auth two", + "engine": { + "peertube": ">=1.3.0" + }, + "keywords": [ + "peertube", + "plugin" + ], + "homepage": "https://github.com/Chocobozzz/PeerTube", + "author": "Chocobozzz", + "bugs": "https://github.com/Chocobozzz/PeerTube/issues", + "library": "./main.js", + "staticDirs": {}, + "css": [], + "clientScripts": [], + "translations": {} +} -- cgit v1.2.3