aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/index-fast.ts1
-rw-r--r--server/tests/api/server/tracker.ts71
2 files changed, 72 insertions, 0 deletions
diff --git a/server/tests/api/index-fast.ts b/server/tests/api/index-fast.ts
index 531a09b82..02ffdd4f1 100644
--- a/server/tests/api/index-fast.ts
+++ b/server/tests/api/index-fast.ts
@@ -15,3 +15,4 @@ import './server/email'
15import './server/config' 15import './server/config'
16import './server/reverse-proxy' 16import './server/reverse-proxy'
17import './search/search-videos' 17import './search/search-videos'
18import './server/tracker'
diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts
new file mode 100644
index 000000000..5d61c1558
--- /dev/null
+++ b/server/tests/api/server/tracker.ts
@@ -0,0 +1,71 @@
1/* tslint:disable:no-unused-expression */
2
3import * as magnetUtil from 'magnet-uri'
4import * as chai from 'chai'
5import 'mocha'
6import { getVideo, killallServers, runServer, ServerInfo, uploadVideo } from '../../utils'
7import { flushTests, setAccessTokensToServers } from '../../utils/index'
8import { VideoDetails } from '../../../../shared/models/videos'
9import * as WebTorrent from 'webtorrent'
10
11describe('Test tracker', function () {
12 let server: ServerInfo
13 let badMagnet: string
14 let goodMagnet: string
15
16 before(async function () {
17 this.timeout(60000)
18
19 await flushTests()
20 server = await runServer(1)
21 await setAccessTokensToServers([ server ])
22
23 {
24 const res = await uploadVideo(server.url, server.accessToken, {})
25 const videoUUID = res.body.video.uuid
26
27 const resGet = await getVideo(server.url, videoUUID)
28 const video: VideoDetails = resGet.body
29 goodMagnet = video.files[0].magnetUri
30
31 const parsed = magnetUtil.decode(goodMagnet)
32 parsed.infoHash = '010597bb88b1968a5693a4fa8267c592ca65f2e9'
33
34 badMagnet = magnetUtil.encode(parsed)
35 }
36 })
37
38 it('Should return an error when adding an incorrect infohash', done => {
39 this.timeout(10000)
40 const webtorrent = new WebTorrent()
41
42 const torrent = webtorrent.add(badMagnet)
43
44 torrent.on('error', done)
45 torrent.on('warning', warn => {
46 const message = typeof warn === 'string' ? warn : warn.message
47 if (message.indexOf('Unknown infoHash ') !== -1) return done()
48 })
49
50 torrent.on('done', () => done(new Error('No error on infohash')))
51 })
52
53 it('Should succeed with the correct infohash', done => {
54 this.timeout(10000)
55 const webtorrent = new WebTorrent()
56
57 const torrent = webtorrent.add(goodMagnet)
58
59 torrent.on('error', done)
60 torrent.on('warning', warn => {
61 const message = typeof warn === 'string' ? warn : warn.message
62 if (message.indexOf('Unknown infoHash ') !== -1) return done(new Error('Error on infohash'))
63 })
64
65 torrent.on('done', done)
66 })
67
68 after(async function () {
69 killallServers([ server ])
70 })
71})