diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-22 16:07:04 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-04 16:21:39 +0200 |
commit | 7fed637506043e4432cbebe041ada0625171cceb (patch) | |
tree | 07f174e17c4b4a0b3d43a0fa6944865c06234338 /server/tests | |
parent | 8d4197637868d5cde49434e937186b57e40f4b2b (diff) | |
download | PeerTube-7fed637506043e4432cbebe041ada0625171cceb.tar.gz PeerTube-7fed637506043e4432cbebe041ada0625171cceb.tar.zst PeerTube-7fed637506043e4432cbebe041ada0625171cceb.zip |
Begin auth plugin support
Diffstat (limited to 'server/tests')
9 files changed, 274 insertions, 4 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index db82e8fc2..7ba04a4ca 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -40,7 +40,7 @@ import { | |||
40 | getVideoAbusesList, updateCustomSubConfig, getCustomConfig, waitJobs | 40 | getVideoAbusesList, updateCustomSubConfig, getCustomConfig, waitJobs |
41 | } from '../../../../shared/extra-utils' | 41 | } from '../../../../shared/extra-utils' |
42 | import { follow } from '../../../../shared/extra-utils/server/follows' | 42 | import { follow } from '../../../../shared/extra-utils/server/follows' |
43 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | 43 | import { setAccessTokensToServers, logout } from '../../../../shared/extra-utils/users/login' |
44 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' | 44 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' |
45 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | 45 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' |
46 | import { CustomConfig } from '@shared/models/server' | 46 | import { CustomConfig } from '@shared/models/server' |
@@ -205,11 +205,17 @@ describe('Test users', function () { | |||
205 | }) | 205 | }) |
206 | 206 | ||
207 | describe('Logout', function () { | 207 | describe('Logout', function () { |
208 | it('Should logout (revoke token)') | 208 | it('Should logout (revoke token)', async function () { |
209 | await logout(server.url, server.accessToken) | ||
210 | }) | ||
209 | 211 | ||
210 | it('Should not be able to get the user information') | 212 | it('Should not be able to get the user information', async function () { |
213 | await getMyUserInformation(server.url, server.accessToken, 401) | ||
214 | }) | ||
211 | 215 | ||
212 | it('Should not be able to upload a video') | 216 | it('Should not be able to upload a video', async function () { |
217 | await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401) | ||
218 | }) | ||
213 | 219 | ||
214 | it('Should not be able to remove a video') | 220 | it('Should not be able to remove a video') |
215 | 221 | ||
diff --git a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js new file mode 100644 index 000000000..4755ed643 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/main.js | |||
@@ -0,0 +1,61 @@ | |||
1 | async function register ({ | ||
2 | registerIdAndPassAuth, | ||
3 | peertubeHelpers | ||
4 | }) { | ||
5 | registerIdAndPassAuth({ | ||
6 | type: 'id-and-pass', | ||
7 | |||
8 | onLogout: () => { | ||
9 | peertubeHelpers.logger.info('On logout for auth 1 - 1') | ||
10 | }, | ||
11 | |||
12 | getWeight: () => 15, | ||
13 | |||
14 | login (body) { | ||
15 | if (body.id === 'spyro' && body.password === 'spyro password') { | ||
16 | return Promise.resolve({ | ||
17 | username: 'spyro', | ||
18 | email: 'spyro@example.com', | ||
19 | role: 0, | ||
20 | displayName: 'Spyro the Dragon' | ||
21 | }) | ||
22 | } | ||
23 | |||
24 | return null | ||
25 | } | ||
26 | }) | ||
27 | |||
28 | registerIdAndPassAuth({ | ||
29 | type: 'id-and-pass', | ||
30 | |||
31 | onLogout: () => { | ||
32 | peertubeHelpers.logger.info('On logout for auth 1 - 2') | ||
33 | }, | ||
34 | |||
35 | getWeight: () => 50, | ||
36 | |||
37 | login (body) { | ||
38 | if (body.id === 'crash' && body.password === 'crash password') { | ||
39 | return Promise.resolve({ | ||
40 | username: 'crash', | ||
41 | email: 'crash@example.com', | ||
42 | role: 2, | ||
43 | displayName: 'Crash Bandicoot' | ||
44 | }) | ||
45 | } | ||
46 | |||
47 | return null | ||
48 | } | ||
49 | }) | ||
50 | } | ||
51 | |||
52 | async function unregister () { | ||
53 | return | ||
54 | } | ||
55 | |||
56 | module.exports = { | ||
57 | register, | ||
58 | unregister | ||
59 | } | ||
60 | |||
61 | // ########################################################################### | ||
diff --git a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/package.json b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/package.json new file mode 100644 index 000000000..f8ad18a90 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-one/package.json | |||
@@ -0,0 +1,20 @@ | |||
1 | { | ||
2 | "name": "peertube-plugin-test-id-pass-auth-one", | ||
3 | "version": "0.0.1", | ||
4 | "description": "Id and pass 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-id-pass-auth-three/main.js b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-three/main.js new file mode 100644 index 000000000..2a15b3754 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-three/main.js | |||
@@ -0,0 +1,37 @@ | |||
1 | async function register ({ | ||
2 | registerIdAndPassAuth, | ||
3 | peertubeHelpers | ||
4 | }) { | ||
5 | registerIdAndPassAuth({ | ||
6 | type: 'id-and-pass', | ||
7 | |||
8 | onLogout: () => { | ||
9 | peertubeHelpers.logger.info('On logout for auth 3 - 1') | ||
10 | }, | ||
11 | |||
12 | getWeight: () => 5, | ||
13 | |||
14 | login (body) { | ||
15 | if (body.id === 'laguna' && body.password === 'laguna password') { | ||
16 | return Promise.resolve({ | ||
17 | username: 'laguna', | ||
18 | email: 'laguna@example.com', | ||
19 | displayName: 'Laguna Loire' | ||
20 | }) | ||
21 | } | ||
22 | |||
23 | return null | ||
24 | } | ||
25 | }) | ||
26 | } | ||
27 | |||
28 | async function unregister () { | ||
29 | return | ||
30 | } | ||
31 | |||
32 | module.exports = { | ||
33 | register, | ||
34 | unregister | ||
35 | } | ||
36 | |||
37 | // ########################################################################### | ||
diff --git a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-three/package.json b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-three/package.json new file mode 100644 index 000000000..f9f107b1a --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-three/package.json | |||
@@ -0,0 +1,20 @@ | |||
1 | { | ||
2 | "name": "peertube-plugin-test-id-pass-auth-three", | ||
3 | "version": "0.0.1", | ||
4 | "description": "Id and pass 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/fixtures/peertube-plugin-test-id-pass-auth-two/main.js b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/main.js new file mode 100644 index 000000000..edfc870c0 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/main.js | |||
@@ -0,0 +1,36 @@ | |||
1 | async function register ({ | ||
2 | registerIdAndPassAuth, | ||
3 | peertubeHelpers | ||
4 | }) { | ||
5 | registerIdAndPassAuth({ | ||
6 | type: 'id-and-pass', | ||
7 | |||
8 | onLogout: () => { | ||
9 | peertubeHelpers.logger.info('On logout for auth 2 - 1') | ||
10 | }, | ||
11 | |||
12 | getWeight: () => 30, | ||
13 | |||
14 | login (body) { | ||
15 | if (body.id === 'laguna' && body.password === 'laguna password') { | ||
16 | return Promise.resolve({ | ||
17 | username: 'laguna', | ||
18 | email: 'laguna@example.com' | ||
19 | }) | ||
20 | } | ||
21 | |||
22 | return null | ||
23 | } | ||
24 | }) | ||
25 | } | ||
26 | |||
27 | async function unregister () { | ||
28 | return | ||
29 | } | ||
30 | |||
31 | module.exports = { | ||
32 | register, | ||
33 | unregister | ||
34 | } | ||
35 | |||
36 | // ########################################################################### | ||
diff --git a/server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/package.json b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/package.json new file mode 100644 index 000000000..5df15fac1 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-id-pass-auth-two/package.json | |||
@@ -0,0 +1,20 @@ | |||
1 | { | ||
2 | "name": "peertube-plugin-test-id-pass-auth-two", | ||
3 | "version": "0.0.1", | ||
4 | "description": "Id and pass 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 | } | ||
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts new file mode 100644 index 000000000..5b4d1a1db --- /dev/null +++ b/server/tests/plugins/id-and-pass-auth.ts | |||
@@ -0,0 +1,69 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | ||
5 | import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils' | ||
6 | |||
7 | describe('Test id and pass auth plugins', function () { | ||
8 | let server: ServerInfo | ||
9 | |||
10 | before(async function () { | ||
11 | this.timeout(30000) | ||
12 | |||
13 | server = await flushAndRunServer(1) | ||
14 | await setAccessTokensToServers([ server ]) | ||
15 | |||
16 | await installPlugin({ | ||
17 | url: server.url, | ||
18 | accessToken: server.accessToken, | ||
19 | path: getPluginTestPath('-id-pass-auth-one') | ||
20 | }) | ||
21 | |||
22 | await installPlugin({ | ||
23 | url: server.url, | ||
24 | accessToken: server.accessToken, | ||
25 | path: getPluginTestPath('-id-pass-auth-two') | ||
26 | }) | ||
27 | }) | ||
28 | |||
29 | it('Should not login', async function() { | ||
30 | |||
31 | }) | ||
32 | |||
33 | it('Should login Spyro, create the user and use the token', async function() { | ||
34 | |||
35 | }) | ||
36 | |||
37 | it('Should login Crash, create the user and use the token', async function() { | ||
38 | |||
39 | }) | ||
40 | |||
41 | it('Should login the first Laguna, create the user and use the token', async function() { | ||
42 | |||
43 | }) | ||
44 | |||
45 | it('Should update Crash profile', async function () { | ||
46 | |||
47 | }) | ||
48 | |||
49 | it('Should logout Crash', async function () { | ||
50 | |||
51 | // test token | ||
52 | }) | ||
53 | |||
54 | it('Should have logged the Crash logout', async function () { | ||
55 | |||
56 | }) | ||
57 | |||
58 | it('Should login Crash and keep the old existing profile', async function () { | ||
59 | |||
60 | }) | ||
61 | |||
62 | it('Should uninstall the plugin one and do not login existing Crash', async function () { | ||
63 | |||
64 | }) | ||
65 | |||
66 | after(async function () { | ||
67 | await cleanupTests([ server ]) | ||
68 | }) | ||
69 | }) | ||
diff --git a/server/tests/plugins/index.ts b/server/tests/plugins/index.ts index 1414e7e58..8aa30654a 100644 --- a/server/tests/plugins/index.ts +++ b/server/tests/plugins/index.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import './action-hooks' | 1 | import './action-hooks' |
2 | import './id-and-pass-auth' | ||
2 | import './filter-hooks' | 3 | import './filter-hooks' |
3 | import './translations' | 4 | import './translations' |
4 | import './video-constants' | 5 | import './video-constants' |