]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/tracker.ts
Add ability to disable tracker
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / tracker.ts
index 25ca00029bc9fc8d94731b27be1b9daf257f2257..41803aef133d61893458bdbcbdd6823ad80aa685 100644 (file)
@@ -2,7 +2,7 @@
 
 import * as magnetUtil from 'magnet-uri'
 import 'mocha'
-import { getVideo, killallServers, runServer, ServerInfo, uploadVideo } from '../../../../shared/utils'
+import { getVideo, killallServers, reRunServer, runServer, ServerInfo, uploadVideo } from '../../../../shared/utils'
 import { flushTests, setAccessTokensToServers } from '../../../../shared/utils/index'
 import { VideoDetails } from '../../../../shared/models/videos'
 import * as WebTorrent from 'webtorrent'
@@ -34,7 +34,7 @@ describe('Test tracker', function () {
     }
   })
 
-  it('Should return an error when adding an incorrect infohash', done => {
+  it('Should return an error when adding an incorrect infohash', function (done) {
     this.timeout(10000)
     const webtorrent = new WebTorrent()
 
@@ -49,7 +49,7 @@ describe('Test tracker', function () {
     torrent.on('done', () => done(new Error('No error on infohash')))
   })
 
-  it('Should succeed with the correct infohash', done => {
+  it('Should succeed with the correct infohash', function (done) {
     this.timeout(10000)
     const webtorrent = new WebTorrent()
 
@@ -64,6 +64,26 @@ describe('Test tracker', function () {
     torrent.on('done', done)
   })
 
+  it('Should disable the tracker', function (done) {
+    this.timeout(20000)
+
+    killallServers([ server ])
+    reRunServer(server, { tracker: { enabled: false } })
+      .then(() => {
+        const webtorrent = new WebTorrent()
+
+        const torrent = webtorrent.add(goodMagnet)
+
+        torrent.on('error', done)
+        torrent.on('warning', warn => {
+          const message = typeof warn === 'string' ? warn : warn.message
+          if (message.indexOf('disabled ') !== -1) return done()
+        })
+
+        torrent.on('done', () => done(new Error('Tracker is enabled')))
+      })
+  })
+
   after(async function () {
     killallServers([ server ])
   })