diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/activitypub/client.ts | 40 | ||||
-rw-r--r-- | server/tests/api/activitypub/fetch.ts | 7 | ||||
-rw-r--r-- | server/tests/api/activitypub/helpers.ts | 10 | ||||
-rw-r--r-- | server/tests/api/activitypub/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/activitypub/refresher.ts | 93 | ||||
-rw-r--r-- | server/tests/api/activitypub/security.ts | 7 | ||||
-rw-r--r-- | server/tests/api/check-params/users.ts | 17 | ||||
-rw-r--r-- | server/tests/api/redundancy/redundancy.ts | 27 | ||||
-rw-r--r-- | server/tests/api/users/users.ts | 2 |
9 files changed, 169 insertions, 35 deletions
diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index d45232c8d..6d90d8643 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts | |||
@@ -3,32 +3,41 @@ | |||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { | 5 | import { |
6 | doubleFollow, | ||
7 | flushAndRunMultipleServers, | ||
6 | flushTests, | 8 | flushTests, |
7 | killallServers, | 9 | killallServers, |
8 | makeActivityPubGetRequest, | 10 | makeActivityPubGetRequest, |
9 | runServer, | ||
10 | ServerInfo, | 11 | ServerInfo, |
11 | setAccessTokensToServers | 12 | setAccessTokensToServers, |
13 | uploadVideo | ||
12 | } from '../../../../shared/utils' | 14 | } from '../../../../shared/utils' |
13 | 15 | ||
14 | |||
15 | const expect = chai.expect | 16 | const expect = chai.expect |
16 | 17 | ||
17 | describe('Test activitypub', function () { | 18 | describe('Test activitypub', function () { |
18 | let server: ServerInfo = null | 19 | let servers: ServerInfo[] = [] |
20 | let videoUUID: string | ||
19 | 21 | ||
20 | before(async function () { | 22 | before(async function () { |
21 | this.timeout(30000) | 23 | this.timeout(30000) |
22 | 24 | ||
23 | await flushTests() | 25 | await flushTests() |
24 | 26 | ||
25 | server = await runServer(1) | 27 | servers = await flushAndRunMultipleServers(2) |
28 | |||
29 | await setAccessTokensToServers(servers) | ||
30 | |||
31 | { | ||
32 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) | ||
33 | videoUUID = res.body.video.uuid | ||
34 | } | ||
26 | 35 | ||
27 | await setAccessTokensToServers([ server ]) | 36 | await doubleFollow(servers[0], servers[1]) |
28 | }) | 37 | }) |
29 | 38 | ||
30 | it('Should return the account object', async function () { | 39 | it('Should return the account object', async function () { |
31 | const res = await makeActivityPubGetRequest(server.url, '/accounts/root') | 40 | const res = await makeActivityPubGetRequest(servers[0].url, '/accounts/root') |
32 | const object = res.body | 41 | const object = res.body |
33 | 42 | ||
34 | expect(object.type).to.equal('Person') | 43 | expect(object.type).to.equal('Person') |
@@ -37,7 +46,22 @@ describe('Test activitypub', function () { | |||
37 | expect(object.preferredUsername).to.equal('root') | 46 | expect(object.preferredUsername).to.equal('root') |
38 | }) | 47 | }) |
39 | 48 | ||
49 | it('Should return the video object', async function () { | ||
50 | const res = await makeActivityPubGetRequest(servers[0].url, '/videos/watch/' + videoUUID) | ||
51 | const object = res.body | ||
52 | |||
53 | expect(object.type).to.equal('Video') | ||
54 | expect(object.id).to.equal('http://localhost:9001/videos/watch/' + videoUUID) | ||
55 | expect(object.name).to.equal('video') | ||
56 | }) | ||
57 | |||
58 | it('Should redirect to the origin video object', async function () { | ||
59 | const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + videoUUID, 302) | ||
60 | |||
61 | expect(res.header.location).to.equal('http://localhost:9001/videos/watch/' + videoUUID) | ||
62 | }) | ||
63 | |||
40 | after(async function () { | 64 | after(async function () { |
41 | killallServers([ server ]) | 65 | killallServers(servers) |
42 | }) | 66 | }) |
43 | }) | 67 | }) |
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index e84eb18bb..03609c1a9 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts | |||
@@ -11,12 +11,13 @@ import { | |||
11 | killallServers, | 11 | killallServers, |
12 | ServerInfo, | 12 | ServerInfo, |
13 | setAccessTokensToServers, | 13 | setAccessTokensToServers, |
14 | setActorField, | ||
15 | setVideoField, | ||
14 | uploadVideo, | 16 | uploadVideo, |
15 | userLogin | 17 | userLogin, |
18 | waitJobs | ||
16 | } from '../../../../shared/utils' | 19 | } from '../../../../shared/utils' |
17 | import * as chai from 'chai' | 20 | import * as chai from 'chai' |
18 | import { setActorField, setVideoField } from '../../utils/miscs/sql' | ||
19 | import { waitJobs } from '../../../../shared/utils/server/jobs' | ||
20 | import { Video } from '../../../../shared/models/videos' | 21 | import { Video } from '../../../../shared/models/videos' |
21 | 22 | ||
22 | const expect = chai.expect | 23 | const expect = chai.expect |
diff --git a/server/tests/api/activitypub/helpers.ts b/server/tests/api/activitypub/helpers.ts index 4c42f3d67..ac6e755c3 100644 --- a/server/tests/api/activitypub/helpers.ts +++ b/server/tests/api/activitypub/helpers.ts | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { buildRequestStub } from '../../utils/miscs/stubs' | 5 | import { buildRequestStub } from '../../../../shared/utils/miscs/stubs' |
6 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' | 6 | import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' |
7 | import { cloneDeep } from 'lodash' | 7 | import { cloneDeep } from 'lodash' |
8 | import { buildSignedActivity } from '../../../helpers/activitypub' | 8 | import { buildSignedActivity } from '../../../helpers/activitypub' |
@@ -91,7 +91,7 @@ describe('Test activity pub helpers', function () { | |||
91 | req.headers = mastodonObject.headers | 91 | req.headers = mastodonObject.headers |
92 | req.headers.signature = 'Signature ' + req.headers.signature | 92 | req.headers.signature = 'Signature ' + req.headers.signature |
93 | 93 | ||
94 | const parsed = parseHTTPSignature(req, 3600 * 365 * 3) | 94 | const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10) |
95 | const publicKey = require('./json/mastodon/public-key.json').publicKey | 95 | const publicKey = require('./json/mastodon/public-key.json').publicKey |
96 | 96 | ||
97 | const actor = { publicKey } | 97 | const actor = { publicKey } |
@@ -110,7 +110,7 @@ describe('Test activity pub helpers', function () { | |||
110 | req.headers = mastodonObject.headers | 110 | req.headers = mastodonObject.headers |
111 | req.headers.signature = 'Signature ' + req.headers.signature | 111 | req.headers.signature = 'Signature ' + req.headers.signature |
112 | 112 | ||
113 | const parsed = parseHTTPSignature(req, 3600 * 365 * 3) | 113 | const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10) |
114 | const publicKey = require('./json/mastodon/bad-public-key.json').publicKey | 114 | const publicKey = require('./json/mastodon/bad-public-key.json').publicKey |
115 | 115 | ||
116 | const actor = { publicKey } | 116 | const actor = { publicKey } |
@@ -150,7 +150,7 @@ describe('Test activity pub helpers', function () { | |||
150 | 150 | ||
151 | let errored = false | 151 | let errored = false |
152 | try { | 152 | try { |
153 | parseHTTPSignature(req, 3600 * 365 * 3) | 153 | parseHTTPSignature(req, 3600 * 1000 * 365 * 10) |
154 | } catch { | 154 | } catch { |
155 | errored = true | 155 | errored = true |
156 | } | 156 | } |
@@ -168,7 +168,7 @@ describe('Test activity pub helpers', function () { | |||
168 | req.headers = mastodonObject.headers | 168 | req.headers = mastodonObject.headers |
169 | req.headers.signature = 'Signature ' + req.headers.signature | 169 | req.headers.signature = 'Signature ' + req.headers.signature |
170 | 170 | ||
171 | const parsed = parseHTTPSignature(req, 3600 * 365 * 3) | 171 | const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10) |
172 | const publicKey = require('./json/mastodon/public-key.json').publicKey | 172 | const publicKey = require('./json/mastodon/public-key.json').publicKey |
173 | 173 | ||
174 | const actor = { publicKey } | 174 | const actor = { publicKey } |
diff --git a/server/tests/api/activitypub/index.ts b/server/tests/api/activitypub/index.ts index e748f32e9..450053309 100644 --- a/server/tests/api/activitypub/index.ts +++ b/server/tests/api/activitypub/index.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import './client' | 1 | import './client' |
2 | import './fetch' | 2 | import './fetch' |
3 | import './helpers' | 3 | import './helpers' |
4 | import './refresher' | ||
4 | import './security' | 5 | import './security' |
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts new file mode 100644 index 000000000..332ea7ed1 --- /dev/null +++ b/server/tests/api/activitypub/refresher.ts | |||
@@ -0,0 +1,93 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { | ||
5 | doubleFollow, | ||
6 | flushAndRunMultipleServers, | ||
7 | getVideo, | ||
8 | killallServers, | ||
9 | reRunServer, | ||
10 | ServerInfo, | ||
11 | setAccessTokensToServers, | ||
12 | uploadVideo, | ||
13 | wait, | ||
14 | setVideoField, | ||
15 | waitJobs | ||
16 | } from '../../../../shared/utils' | ||
17 | |||
18 | describe('Test AP refresher', function () { | ||
19 | let servers: ServerInfo[] = [] | ||
20 | let videoUUID1: string | ||
21 | let videoUUID2: string | ||
22 | let videoUUID3: string | ||
23 | |||
24 | before(async function () { | ||
25 | this.timeout(30000) | ||
26 | |||
27 | servers = await flushAndRunMultipleServers(2) | ||
28 | |||
29 | // Get the access tokens | ||
30 | await setAccessTokensToServers(servers) | ||
31 | |||
32 | { | ||
33 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) | ||
34 | videoUUID1 = res.body.video.uuid | ||
35 | } | ||
36 | |||
37 | { | ||
38 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) | ||
39 | videoUUID2 = res.body.video.uuid | ||
40 | } | ||
41 | |||
42 | { | ||
43 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video3' }) | ||
44 | videoUUID3 = res.body.video.uuid | ||
45 | } | ||
46 | |||
47 | await doubleFollow(servers[0], servers[1]) | ||
48 | }) | ||
49 | |||
50 | it('Should remove a deleted remote video', async function () { | ||
51 | this.timeout(60000) | ||
52 | |||
53 | await wait(10000) | ||
54 | |||
55 | // Change UUID so the remote server returns a 404 | ||
56 | await setVideoField(2, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') | ||
57 | |||
58 | await getVideo(servers[0].url, videoUUID1) | ||
59 | await getVideo(servers[0].url, videoUUID2) | ||
60 | |||
61 | await waitJobs(servers) | ||
62 | |||
63 | await getVideo(servers[0].url, videoUUID1, 404) | ||
64 | await getVideo(servers[0].url, videoUUID2, 200) | ||
65 | }) | ||
66 | |||
67 | it('Should not update a remote video if the remote instance is down', async function () { | ||
68 | this.timeout(60000) | ||
69 | |||
70 | killallServers([ servers[1] ]) | ||
71 | |||
72 | await setVideoField(2, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') | ||
73 | |||
74 | // Video will need a refresh | ||
75 | await wait(10000) | ||
76 | |||
77 | await getVideo(servers[0].url, videoUUID3) | ||
78 | // The refresh should fail | ||
79 | await waitJobs([ servers[0] ]) | ||
80 | |||
81 | await reRunServer(servers[1]) | ||
82 | |||
83 | // Should not refresh the video, even if the last refresh failed (to avoir a loop on dead instances) | ||
84 | await getVideo(servers[0].url, videoUUID3) | ||
85 | await waitJobs(servers) | ||
86 | |||
87 | await getVideo(servers[0].url, videoUUID3, 200) | ||
88 | }) | ||
89 | |||
90 | after(async function () { | ||
91 | killallServers(servers) | ||
92 | }) | ||
93 | }) | ||
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index b71a61c8c..342ae0fa1 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts | |||
@@ -6,14 +6,15 @@ import { | |||
6 | flushAndRunMultipleServers, | 6 | flushAndRunMultipleServers, |
7 | flushTests, | 7 | flushTests, |
8 | killallServers, | 8 | killallServers, |
9 | ServerInfo | 9 | makeFollowRequest, |
10 | makePOSTAPRequest, | ||
11 | ServerInfo, | ||
12 | setActorField | ||
10 | } from '../../../../shared/utils' | 13 | } from '../../../../shared/utils' |
11 | import { HTTP_SIGNATURE } from '../../../initializers' | 14 | import { HTTP_SIGNATURE } from '../../../initializers' |
12 | import { buildDigest, buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils' | 15 | import { buildDigest, buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils' |
13 | import * as chai from 'chai' | 16 | import * as chai from 'chai' |
14 | import { setActorField } from '../../utils/miscs/sql' | ||
15 | import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub' | 17 | import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub' |
16 | import { makeFollowRequest, makePOSTAPRequest } from '../../utils/requests/activitypub' | ||
17 | 18 | ||
18 | const expect = chai.expect | 19 | const expect = chai.expect |
19 | 20 | ||
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index f4c177621..05f42bca9 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -103,13 +103,13 @@ describe('Test users API validators', function () { | |||
103 | } | 103 | } |
104 | 104 | ||
105 | it('Should fail with a too small username', async function () { | 105 | it('Should fail with a too small username', async function () { |
106 | const fields = immutableAssign(baseCorrectParams, { username: 'fi' }) | 106 | const fields = immutableAssign(baseCorrectParams, { username: '' }) |
107 | 107 | ||
108 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 108 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
109 | }) | 109 | }) |
110 | 110 | ||
111 | it('Should fail with a too long username', async function () { | 111 | it('Should fail with a too long username', async function () { |
112 | const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' }) | 112 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(11) }) |
113 | 113 | ||
114 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 114 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
115 | }) | 115 | }) |
@@ -432,6 +432,14 @@ describe('Test users API validators', function () { | |||
432 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | 432 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) |
433 | }) | 433 | }) |
434 | 434 | ||
435 | it('Should fail with an invalid emailVerified attribute', async function () { | ||
436 | const fields = { | ||
437 | emailVerified: 'yes' | ||
438 | } | ||
439 | |||
440 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | ||
441 | }) | ||
442 | |||
435 | it('Should fail with an invalid videoQuota attribute', async function () { | 443 | it('Should fail with an invalid videoQuota attribute', async function () { |
436 | const fields = { | 444 | const fields = { |
437 | videoQuota: -90 | 445 | videoQuota: -90 |
@@ -467,6 +475,7 @@ describe('Test users API validators', function () { | |||
467 | it('Should succeed with the correct params', async function () { | 475 | it('Should succeed with the correct params', async function () { |
468 | const fields = { | 476 | const fields = { |
469 | email: 'email@example.com', | 477 | email: 'email@example.com', |
478 | emailVerified: true, | ||
470 | videoQuota: 42, | 479 | videoQuota: 42, |
471 | role: UserRole.MODERATOR | 480 | role: UserRole.MODERATOR |
472 | } | 481 | } |
@@ -545,13 +554,13 @@ describe('Test users API validators', function () { | |||
545 | } | 554 | } |
546 | 555 | ||
547 | it('Should fail with a too small username', async function () { | 556 | it('Should fail with a too small username', async function () { |
548 | const fields = immutableAssign(baseCorrectParams, { username: 'ji' }) | 557 | const fields = immutableAssign(baseCorrectParams, { username: '' }) |
549 | 558 | ||
550 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | 559 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) |
551 | }) | 560 | }) |
552 | 561 | ||
553 | it('Should fail with a too long username', async function () { | 562 | it('Should fail with a too long username', async function () { |
554 | const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' }) | 563 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(11) }) |
555 | 564 | ||
556 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | 565 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) |
557 | }) | 566 | }) |
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 2bc1b60ce..9d3ce8153 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts | |||
@@ -137,7 +137,7 @@ async function check2Webseeds (strategy: VideoRedundancyStrategy, videoUUID?: st | |||
137 | if (!videoUUID) videoUUID = video1Server2UUID | 137 | if (!videoUUID) videoUUID = video1Server2UUID |
138 | 138 | ||
139 | const webseeds = [ | 139 | const webseeds = [ |
140 | 'http://localhost:9001/static/webseed/' + videoUUID, | 140 | 'http://localhost:9001/static/redundancy/' + videoUUID, |
141 | 'http://localhost:9002/static/webseed/' + videoUUID | 141 | 'http://localhost:9002/static/webseed/' + videoUUID |
142 | ] | 142 | ] |
143 | 143 | ||
@@ -149,20 +149,23 @@ async function check2Webseeds (strategy: VideoRedundancyStrategy, videoUUID?: st | |||
149 | for (const file of video.files) { | 149 | for (const file of video.files) { |
150 | checkMagnetWebseeds(file, webseeds, server) | 150 | checkMagnetWebseeds(file, webseeds, server) |
151 | 151 | ||
152 | // Only servers 1 and 2 have the video | 152 | await makeGetRequest({ |
153 | if (server.serverNumber !== 3) { | 153 | url: servers[0].url, |
154 | await makeGetRequest({ | 154 | statusCodeExpected: 200, |
155 | url: server.url, | 155 | path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, |
156 | statusCodeExpected: 200, | 156 | contentType: null |
157 | path: '/static/webseed/' + `${videoUUID}-${file.resolution.id}.mp4`, | 157 | }) |
158 | contentType: null | 158 | await makeGetRequest({ |
159 | }) | 159 | url: servers[1].url, |
160 | } | 160 | statusCodeExpected: 200, |
161 | path: '/static/webseed/' + `${videoUUID}-${file.resolution.id}.mp4`, | ||
162 | contentType: null | ||
163 | }) | ||
161 | } | 164 | } |
162 | } | 165 | } |
163 | 166 | ||
164 | for (const directory of [ 'test1', 'test2' ]) { | 167 | for (const directory of [ 'test1/redundancy', 'test2/videos' ]) { |
165 | const files = await readdir(join(root(), directory, 'videos')) | 168 | const files = await readdir(join(root(), directory)) |
166 | expect(files).to.have.length.at.least(4) | 169 | expect(files).to.have.length.at.least(4) |
167 | 170 | ||
168 | for (const resolution of [ 240, 360, 480, 720 ]) { | 171 | for (const resolution of [ 240, 360, 480, 720 ]) { |
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 7dffbb0b1..4914c8ed5 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -478,6 +478,7 @@ describe('Test users', function () { | |||
478 | userId, | 478 | userId, |
479 | accessToken, | 479 | accessToken, |
480 | email: 'updated2@example.com', | 480 | email: 'updated2@example.com', |
481 | emailVerified: true, | ||
481 | videoQuota: 42, | 482 | videoQuota: 42, |
482 | role: UserRole.MODERATOR | 483 | role: UserRole.MODERATOR |
483 | }) | 484 | }) |
@@ -487,6 +488,7 @@ describe('Test users', function () { | |||
487 | 488 | ||
488 | expect(user.username).to.equal('user_1') | 489 | expect(user.username).to.equal('user_1') |
489 | expect(user.email).to.equal('updated2@example.com') | 490 | expect(user.email).to.equal('updated2@example.com') |
491 | expect(user.emailVerified).to.be.true | ||
490 | expect(user.nsfwPolicy).to.equal('do_not_list') | 492 | expect(user.nsfwPolicy).to.equal('do_not_list') |
491 | expect(user.videoQuota).to.equal(42) | 493 | expect(user.videoQuota).to.equal(42) |
492 | expect(user.roleLabel).to.equal('Moderator') | 494 | expect(user.roleLabel).to.equal('Moderator') |