Merge pull request #168 from feross/fix-167

Fix Client.scrape returns no error on invalid URL
This commit is contained in:
Feross Aboukhadijeh 2016-08-05 18:25:14 -07:00 committed by GitHub
commit 17807dc608
2 changed files with 29 additions and 0 deletions

View File

@ -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 = {}

View File

@ -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