From db48de8597897e5024f8e9ed5acb1a8f40748169 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Jun 2020 16:27:35 +0200 Subject: Block infohash spammers from tracker --- server/tests/api/server/tracker.ts | 49 ++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/server/tracker.ts b/server/tests/api/server/tracker.ts index 5b56a83bb..4b86e0b90 100644 --- a/server/tests/api/server/tracker.ts +++ b/server/tests/api/server/tracker.ts @@ -40,21 +40,6 @@ describe('Test tracker', function () { } }) - it('Should return an error when adding an incorrect infohash', function (done) { - this.timeout(10000) - const webtorrent = new WebTorrent() - - const torrent = webtorrent.add(badMagnet) - - torrent.on('error', done) - torrent.on('warning', warn => { - const message = typeof warn === 'string' ? warn : warn.message - if (message.includes('Unknown infoHash ')) return done() - }) - - torrent.on('done', () => done(new Error('No error on infohash'))) - }) - it('Should succeed with the correct infohash', function (done) { this.timeout(10000) const webtorrent = new WebTorrent() @@ -76,6 +61,7 @@ describe('Test tracker', function () { const errCb = () => done(new Error('Tracker is enabled')) killallServers([ server ]) + reRunServer(server, { tracker: { enabled: false } }) .then(() => { const webtorrent = new WebTorrent() @@ -96,6 +82,39 @@ describe('Test tracker', function () { }) }) + it('Should return an error when adding an incorrect infohash', function (done) { + this.timeout(20000) + + killallServers([ server ]) + + reRunServer(server) + .then(() => { + const webtorrent = new WebTorrent() + + const torrent = webtorrent.add(badMagnet) + + torrent.on('error', done) + torrent.on('warning', warn => { + const message = typeof warn === 'string' ? warn : warn.message + if (message.includes('Unknown infoHash ')) return done() + }) + + torrent.on('done', () => done(new Error('No error on infohash'))) + }) + }) + + it('Should block the IP after the failed infohash', function (done) { + 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.includes('Unsupported tracker protocol')) return done() + }) + }) + after(async function () { await cleanupTests([ server ]) }) -- cgit v1.2.3