Skip to content

Commit a8869b0

Browse files
committed
Add tests to validate tracker
1 parent 5c90b2b commit a8869b0

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

test/client.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,77 @@ test('http: userAgent', function (t) {
468468
client.start()
469469
})
470470
})
471+
472+
function testSupportedTracker (t, serverType) {
473+
t.plan(1)
474+
475+
common.createServer(t, serverType, function (server, announceUrl) {
476+
var client = new Client({
477+
infoHash: fixtures.leaves.parsedTorrent.infoHash,
478+
announce: announceUrl,
479+
peerId: peerId1,
480+
port: port,
481+
wrtc: {}
482+
})
483+
484+
if (serverType === 'ws') common.mockWebsocketTracker(client)
485+
client.on('error', function (err) { t.error(err) })
486+
client.on('warning', function (err) { t.error(err) })
487+
488+
client.start()
489+
490+
client.once('update', function (data) {
491+
t.pass('tracker is valid')
492+
493+
server.close()
494+
client.destroy()
495+
})
496+
})
497+
}
498+
499+
test('http: valid tracker port', function (t) {
500+
testSupportedTracker(t, 'http')
501+
})
502+
503+
test('udp: valid tracker port', function (t) {
504+
testSupportedTracker(t, 'udp')
505+
})
506+
507+
test('ws: valid tracker port', function (t) {
508+
testSupportedTracker(t, 'ws')
509+
})
510+
511+
function testUnsupportedTracker (t, announceUrl) {
512+
t.plan(1)
513+
514+
var client = new Client({
515+
infoHash: fixtures.leaves.parsedTorrent.infoHash,
516+
announce: announceUrl,
517+
peerId: peerId1,
518+
port: port,
519+
wrtc: {}
520+
})
521+
522+
client.on('error', function (err) { t.error(err) })
523+
client.on('warning', function (err) {
524+
t.ok(err.message.includes('tracker'), 'got warning')
525+
526+
client.destroy()
527+
})
528+
}
529+
530+
test('unsupported tracker protocol', function (t) {
531+
testUnsupportedTracker(t, 'badprotocol://127.0.0.1:8080/announce')
532+
})
533+
534+
test('http: invalid tracker port', function (t) {
535+
testUnsupportedTracker(t, 'http://127.0.0.1:69691337/announce')
536+
})
537+
538+
test('udp: invalid tracker port', function (t) {
539+
testUnsupportedTracker(t, 'udp://127.0.0.1:69691337')
540+
})
541+
542+
test('ws: invalid tracker port', function (t) {
543+
testUnsupportedTracker(t, 'ws://127.0.0.1:69691337')
544+
})

0 commit comments

Comments
 (0)