From 59bba81c5acde19bea8b0ac506d7686bec2d23a4 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 5 Aug 2016 18:23:43 -0700 Subject: [PATCH] Fix Client.scrape returns no error on invalid URL Fix #167. --- client.js | 1 + test/scrape.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/client.js b/client.js index 21feb93..5f35ce2 100644 --- a/client.js +++ b/client.js @@ -138,6 +138,7 @@ Client.scrape = function (opts, cb) { var client = new Client(clientOpts) client.once('error', cb) + client.once('warning', cb) var len = Array.isArray(opts.infoHash) ? opts.infoHash.length : 1 var results = {} diff --git a/test/scrape.js b/test/scrape.js index 29890ad..e71a8df 100644 --- a/test/scrape.js +++ b/test/scrape.js @@ -85,6 +85,34 @@ test('ws: scrape using Client.scrape static method', function (t) { clientScrapeStatic(t, 'ws') }) +// Ensure the callback function gets called when an invalid url is passed +function clientScrapeStaticInvalid (t, serverType) { + var announceUrl = serverType + '://invalid.lol' + if (serverType === 'http') announceUrl += '/announce' + + var client = Client.scrape({ + announce: announceUrl, + infoHash: fixtures.leaves.parsedTorrent.infoHash, + wrtc: {} + }, function (err, data) { + t.ok(err instanceof Error) + t.end() + }) + if (serverType === 'ws') common.mockWebsocketTracker(client) +} + +test.only('http: scrape using Client.scrape static method (invalid url)', function (t) { + clientScrapeStaticInvalid(t, 'http') +}) + +test('udp: scrape using Client.scrape static method (invalid url)', function (t) { + clientScrapeStaticInvalid(t, 'udp') +}) + +test('ws: scrape using Client.scrape static method (invalid url)', function (t) { + clientScrapeStaticInvalid(t, 'ws') +}) + function clientScrapeMulti (t, serverType) { var infoHash1 = fixtures.leaves.parsedTorrent.infoHash var infoHash2 = fixtures.alice.parsedTorrent.infoHash