aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/requests/requests.ts5
-rw-r--r--shared/extra-utils/server/index.ts1
-rw-r--r--shared/extra-utils/server/tracker.ts27
3 files changed, 32 insertions, 1 deletions
diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.ts
index 60a08b13c..5bbf7f3bf 100644
--- a/shared/extra-utils/requests/requests.ts
+++ b/shared/extra-utils/requests/requests.ts
@@ -29,9 +29,12 @@ function makeRawRequest (url: string, expectedStatus?: HttpStatusCode, range?: s
29 29
30function makeGetRequest (options: CommonRequestParams & { 30function makeGetRequest (options: CommonRequestParams & {
31 query?: any 31 query?: any
32 rawQuery?: string
32}) { 33}) {
33 const req = request(options.url).get(options.path) 34 const req = request(options.url).get(options.path)
34 .query(options.query) 35
36 if (options.query) req.query(options.query)
37 if (options.rawQuery) req.query(options.rawQuery)
35 38
36 return buildRequest(req, { contentType: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options }) 39 return buildRequest(req, { contentType: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options })
37} 40}
diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts
index 92ff7a0f9..76a2099da 100644
--- a/shared/extra-utils/server/index.ts
+++ b/shared/extra-utils/server/index.ts
@@ -14,3 +14,4 @@ export * from './server'
14export * from './servers-command' 14export * from './servers-command'
15export * from './servers' 15export * from './servers'
16export * from './stats-command' 16export * from './stats-command'
17export * from './tracker'
diff --git a/shared/extra-utils/server/tracker.ts b/shared/extra-utils/server/tracker.ts
new file mode 100644
index 000000000..f04e8f8a1
--- /dev/null
+++ b/shared/extra-utils/server/tracker.ts
@@ -0,0 +1,27 @@
1import { expect } from 'chai'
2import { sha1 } from '@server/helpers/core-utils'
3import { makeGetRequest } from '../requests'
4
5async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) {
6 const path = '/tracker/announce'
7
8 const infohash = sha1(`2${masterPlaylistUrl}+V${fileNumber}`)
9
10 // From bittorrent-tracker
11 const infohashBinary = escape(Buffer.from(infohash, 'hex').toString('binary')).replace(/[@*/+]/g, function (char) {
12 return '%' + char.charCodeAt(0).toString(16).toUpperCase()
13 })
14
15 const res = await makeGetRequest({
16 url: serverUrl,
17 path,
18 rawQuery: `peer_id=-WW0105-NkvYO/egUAr4&info_hash=${infohashBinary}&port=42100`,
19 expectedStatus: 200
20 })
21
22 expect(res.text).to.not.contain('failure')
23}
24
25export {
26 hlsInfohashExist
27}