Fix tests
This commit is contained in:
parent
fa1d5c76f8
commit
38cc3910ff
|
@ -1,5 +1,6 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||||
|
|
||||||
|
import { HttpStatusCode } from '@peertube/peertube-models'
|
||||||
import {
|
import {
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
createMultipleServers,
|
createMultipleServers,
|
||||||
|
@ -10,7 +11,6 @@ import {
|
||||||
} from '@peertube/peertube-server-commands'
|
} from '@peertube/peertube-server-commands'
|
||||||
import { MockHTTP } from '@tests/shared/mock-servers/mock-http.js'
|
import { MockHTTP } from '@tests/shared/mock-servers/mock-http.js'
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { HttpStatusCode } from '../../../../models/src/http/http-status-codes.js'
|
|
||||||
|
|
||||||
describe('Test SSRF requests', function () {
|
describe('Test SSRF requests', function () {
|
||||||
let servers: PeerTubeServer[] = []
|
let servers: PeerTubeServer[] = []
|
||||||
|
|
|
@ -43,7 +43,7 @@ describe('Request helpers', function () {
|
||||||
const port = await mock.initialize()
|
const port = await mock.initialize()
|
||||||
|
|
||||||
const before = new Date().getTime()
|
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)
|
expect(new Date().getTime() - before).to.be.greaterThan(2000)
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import { doRequest } from '@peertube/peertube-server/core/helpers/requests.js'
|
import { doRequest } from '@peertube/peertube-server/core/helpers/requests.js'
|
||||||
|
|
||||||
export function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
|
export function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) {
|
||||||
const options = {
|
return doRequest(url, {
|
||||||
method: 'POST' as 'POST',
|
method: 'POST',
|
||||||
json: body,
|
json: body,
|
||||||
httpSignature,
|
httpSignature,
|
||||||
headers
|
headers,
|
||||||
}
|
preventSSRF: false
|
||||||
|
})
|
||||||
return doRequest(url, options)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
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) })
|
.catch(err => { throw buildRequestError(err) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue