Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Aug 14, 2024
1 parent fa1d5c7 commit 38cc391
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/tests/src/api/server/ssrf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import { HttpStatusCode } from '@peertube/peertube-models'
import {
cleanupTests,
createMultipleServers,
Expand All @@ -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[] = []
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/src/server-helpers/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 5 additions & 6 deletions packages/tests/src/shared/requests.ts
Original file line number Diff line number Diff line change
@@ -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
})
}
8 changes: 6 additions & 2 deletions server/core/helpers/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
}

Expand Down

0 comments on commit 38cc391

Please sign in to comment.