aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-03-08 14:24:11 +0100
committerChocobozzz <me@florianbigard.com>2021-03-24 18:18:40 +0100
commitdb4b15f21fbf4e33434e930ffc7fb768cdcf9d42 (patch)
tree418117b84a5c2ee578c210288b698d155422d608 /server/tests
parent71926aae0762facb25243f27eaf45933b5a37353 (diff)
downloadPeerTube-db4b15f21fbf4e33434e930ffc7fb768cdcf9d42.tar.gz
PeerTube-db4b15f21fbf4e33434e930ffc7fb768cdcf9d42.tar.zst
PeerTube-db4b15f21fbf4e33434e930ffc7fb768cdcf9d42.zip
Use got instead of request
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/activitypub/security.ts40
-rw-r--r--server/tests/api/server/handle-down.ts2
-rw-r--r--server/tests/helpers/request.ts16
3 files changed, 29 insertions, 29 deletions
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts
index 8bde54a40..26b4545ac 100644
--- a/server/tests/api/activitypub/security.ts
+++ b/server/tests/api/activitypub/security.ts
@@ -79,9 +79,9 @@ describe('Test ActivityPub security', function () {
79 Digest: buildDigest({ hello: 'coucou' }) 79 Digest: buildDigest({ hello: 'coucou' })
80 } 80 }
81 81
82 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 82 const { statusCode } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
83 83
84 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) 84 expect(statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
85 }) 85 })
86 86
87 it('Should fail with an invalid date', async function () { 87 it('Should fail with an invalid date', async function () {
@@ -89,9 +89,9 @@ describe('Test ActivityPub security', function () {
89 const headers = buildGlobalHeaders(body) 89 const headers = buildGlobalHeaders(body)
90 headers['date'] = 'Wed, 21 Oct 2015 07:28:00 GMT' 90 headers['date'] = 'Wed, 21 Oct 2015 07:28:00 GMT'
91 91
92 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 92 const { statusCode } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
93 93
94 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) 94 expect(statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
95 }) 95 })
96 96
97 it('Should fail with bad keys', async function () { 97 it('Should fail with bad keys', async function () {
@@ -101,9 +101,9 @@ describe('Test ActivityPub security', function () {
101 const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) 101 const body = activityPubContextify(getAnnounceWithoutContext(servers[1]))
102 const headers = buildGlobalHeaders(body) 102 const headers = buildGlobalHeaders(body)
103 103
104 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 104 const { statusCode } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
105 105
106 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) 106 expect(statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
107 }) 107 })
108 108
109 it('Should reject requests without appropriate signed headers', async function () { 109 it('Should reject requests without appropriate signed headers', async function () {
@@ -123,8 +123,8 @@ describe('Test ActivityPub security', function () {
123 for (const badHeaders of badHeadersMatrix) { 123 for (const badHeaders of badHeadersMatrix) {
124 signatureOptions.headers = badHeaders 124 signatureOptions.headers = badHeaders
125 125
126 const { response } = await makePOSTAPRequest(url, body, signatureOptions, headers) 126 const { statusCode } = await makePOSTAPRequest(url, body, signatureOptions, headers)
127 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) 127 expect(statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
128 } 128 }
129 }) 129 })
130 130
@@ -132,9 +132,9 @@ describe('Test ActivityPub security', function () {
132 const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) 132 const body = activityPubContextify(getAnnounceWithoutContext(servers[1]))
133 const headers = buildGlobalHeaders(body) 133 const headers = buildGlobalHeaders(body)
134 134
135 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 135 const { statusCode } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
136 136
137 expect(response.statusCode).to.equal(HttpStatusCode.NO_CONTENT_204) 137 expect(statusCode).to.equal(HttpStatusCode.NO_CONTENT_204)
138 }) 138 })
139 139
140 it('Should refresh the actor keys', async function () { 140 it('Should refresh the actor keys', async function () {
@@ -150,9 +150,9 @@ describe('Test ActivityPub security', function () {
150 const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) 150 const body = activityPubContextify(getAnnounceWithoutContext(servers[1]))
151 const headers = buildGlobalHeaders(body) 151 const headers = buildGlobalHeaders(body)
152 152
153 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 153 const { statusCode } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
154 154
155 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) 155 expect(statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
156 }) 156 })
157 }) 157 })
158 158
@@ -183,9 +183,9 @@ describe('Test ActivityPub security', function () {
183 183
184 const headers = buildGlobalHeaders(signedBody) 184 const headers = buildGlobalHeaders(signedBody)
185 185
186 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) 186 const { statusCode } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers)
187 187
188 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) 188 expect(statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
189 }) 189 })
190 190
191 it('Should fail with an altered body', async function () { 191 it('Should fail with an altered body', async function () {
@@ -204,9 +204,9 @@ describe('Test ActivityPub security', function () {
204 204
205 const headers = buildGlobalHeaders(signedBody) 205 const headers = buildGlobalHeaders(signedBody)
206 206
207 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) 207 const { statusCode } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers)
208 208
209 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) 209 expect(statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
210 }) 210 })
211 211
212 it('Should succeed with a valid signature', async function () { 212 it('Should succeed with a valid signature', async function () {
@@ -220,9 +220,9 @@ describe('Test ActivityPub security', function () {
220 220
221 const headers = buildGlobalHeaders(signedBody) 221 const headers = buildGlobalHeaders(signedBody)
222 222
223 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) 223 const { statusCode } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers)
224 224
225 expect(response.statusCode).to.equal(HttpStatusCode.NO_CONTENT_204) 225 expect(statusCode).to.equal(HttpStatusCode.NO_CONTENT_204)
226 }) 226 })
227 227
228 it('Should refresh the actor keys', async function () { 228 it('Should refresh the actor keys', async function () {
@@ -243,9 +243,9 @@ describe('Test ActivityPub security', function () {
243 243
244 const headers = buildGlobalHeaders(signedBody) 244 const headers = buildGlobalHeaders(signedBody)
245 245
246 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) 246 const { statusCode } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers)
247 247
248 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) 248 expect(statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
249 }) 249 })
250 }) 250 })
251 251
diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts
index 043754e70..f3ba11950 100644
--- a/server/tests/api/server/handle-down.ts
+++ b/server/tests/api/server/handle-down.ts
@@ -348,8 +348,8 @@ describe('Test handle downs', function () {
348 348
349 for (let i = 0; i < 3; i++) { 349 for (let i = 0; i < 3; i++) {
350 await getVideo(servers[1].url, videoIdsServer1[i]) 350 await getVideo(servers[1].url, videoIdsServer1[i])
351 await wait(1000)
352 await waitJobs([ servers[1] ]) 351 await waitJobs([ servers[1] ])
352 await wait(1500)
353 } 353 }
354 354
355 for (const id of videoIdsServer1) { 355 for (const id of videoIdsServer1) {
diff --git a/server/tests/helpers/request.ts b/server/tests/helpers/request.ts
index f8b2d599b..5e77f129e 100644
--- a/server/tests/helpers/request.ts
+++ b/server/tests/helpers/request.ts
@@ -1,11 +1,11 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
5import { get4KFileUrl, root, wait } from '../../../shared/extra-utils'
6import { join } from 'path'
7import { pathExists, remove } from 'fs-extra'
8import { expect } from 'chai' 4import { expect } from 'chai'
5import { pathExists, remove } from 'fs-extra'
6import { join } from 'path'
7import { get4KFileUrl, root, wait } from '../../../shared/extra-utils'
8import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
9 9
10describe('Request helpers', function () { 10describe('Request helpers', function () {
11 const destPath1 = join(root(), 'test-output-1.txt') 11 const destPath1 = join(root(), 'test-output-1.txt')
@@ -13,7 +13,7 @@ describe('Request helpers', function () {
13 13
14 it('Should throw an error when the bytes limit is exceeded for request', async function () { 14 it('Should throw an error when the bytes limit is exceeded for request', async function () {
15 try { 15 try {
16 await doRequest({ uri: get4KFileUrl() }, 3) 16 await doRequest(get4KFileUrl(), { bodyKBLimit: 3 })
17 } catch { 17 } catch {
18 return 18 return
19 } 19 }
@@ -23,7 +23,7 @@ describe('Request helpers', function () {
23 23
24 it('Should throw an error when the bytes limit is exceeded for request and save file', async function () { 24 it('Should throw an error when the bytes limit is exceeded for request and save file', async function () {
25 try { 25 try {
26 await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath1, 3) 26 await doRequestAndSaveToFile(get4KFileUrl(), destPath1, { bodyKBLimit: 3 })
27 } catch { 27 } catch {
28 28
29 await wait(500) 29 await wait(500)
@@ -35,8 +35,8 @@ describe('Request helpers', function () {
35 }) 35 })
36 36
37 it('Should succeed if the file is below the limit', async function () { 37 it('Should succeed if the file is below the limit', async function () {
38 await doRequest({ uri: get4KFileUrl() }, 5) 38 await doRequest(get4KFileUrl(), { bodyKBLimit: 5 })
39 await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath2, 5) 39 await doRequestAndSaveToFile(get4KFileUrl(), destPath2, { bodyKBLimit: 5 })
40 40
41 expect(await pathExists(destPath2)).to.be.true 41 expect(await pathExists(destPath2)).to.be.true
42 }) 42 })