1
0
Fork 0

Fix tests

This commit is contained in:
Chocobozzz 2024-08-14 16:14:06 +02:00
parent fa1d5c76f8
commit 38cc3910ff
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 13 additions and 10 deletions

View file

@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { HttpStatusCode } from '@peertube/peertube-models'
import {
cleanupTests,
createMultipleServers,
@ -10,7 +11,6 @@ import {
} from '@peertube/peertube-server-commands'
import { MockHTTP } from '@tests/shared/mock-servers/mock-http.js'
import { expect } from 'chai'
import { HttpStatusCode } from '../../../../models/src/http/http-status-codes.js'
describe('Test SSRF requests', function () {
let servers: PeerTubeServer[] = []

View file

@ -43,7 +43,7 @@ describe('Request helpers', function () {
const port = await mock.initialize()
const before = new Date().getTime()
await doRequest('http://127.0.0.1:' + port)
await doRequest('http://127.0.0.1:' + port, { preventSSRF: false })
expect(new Date().getTime() - before).to.be.greaterThan(2000)

View file

@ -1,12 +1,11 @@
import { doRequest } from '@peertube/peertube-server/core/helpers/requests.js'
export function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
const options = {
method: 'POST' as 'POST',
return doRequest(url, {
method: 'POST',
json: body,
httpSignature,
headers
}
return doRequest(url, options)
headers,
preventSSRF: false
})
}

View file

@ -124,10 +124,14 @@ export const peertubeGot = CONFIG.FEDERATION.PREVENT_SSRF
// ---------------------------------------------------------------------------
export function doRequest (url: string, options: PeerTubeRequestOptions = {}) {
export function doRequest (url: string, options: PeerTubeRequestOptions & { preventSSRF?: false } = {}) {
const gotOptions = buildGotOptions(options) as OptionsOfTextResponseBody
return peertubeGot(url, gotOptions)
const gotInstance = options.preventSSRF === false
? unsafeSSRFGot
: peertubeGot
return gotInstance(url, gotOptions)
.catch(err => { throw buildRequestError(err) })
}