Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2015-12-30 02:03:00 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-12-30 02:03:00 +0300
commit0b4dfc608600390b108b846a7bebd293ebf73937 (patch)
tree976d21b7bd13dc6f162884aaad969619d731444d /test/node/blocklist-tracker.js
parentb378a8e40b62348733d7bef4a75ec1798e2b1131 (diff)
Add more browser tests
Run more of the tests in the browser. There's now a test/node and test/browser folder for tests that are specific to each environment. Anything in test/ will be run in both environments.
Diffstat (limited to 'test/node/blocklist-tracker.js')
-rw-r--r--test/node/blocklist-tracker.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/node/blocklist-tracker.js b/test/node/blocklist-tracker.js
new file mode 100644
index 0000000..90ac3be
--- /dev/null
+++ b/test/node/blocklist-tracker.js
@@ -0,0 +1,90 @@
+var common = require('../common')
+var extend = require('xtend')
+var series = require('run-series')
+var test = require('tape')
+var TrackerServer = require('bittorrent-tracker/server')
+var WebTorrent = require('../../')
+
+test('blocklist blocks peers discovered via tracker', function (t) {
+ t.plan(9)
+
+ var parsedTorrent = extend(common.leaves.parsedTorrent)
+ var tracker, client1, client2
+
+ series([
+ function (cb) {
+ tracker = new TrackerServer({ udp: false, ws: false })
+
+ tracker.listen(function () {
+ var port = tracker.http.address().port
+ var announceUrl = 'http://127.0.0.1:' + port + '/announce'
+
+ // Overwrite announce with our local tracker
+ parsedTorrent.announce = announceUrl
+
+ cb(null)
+ })
+
+ tracker.once('start', function () {
+ t.pass('client1 connected to tracker')
+
+ tracker.once('start', function () {
+ t.pass('client2 connected to tracker')
+ })
+ })
+ },
+
+ function (cb) {
+ client1 = new WebTorrent({ dht: false })
+ client1.on('error', function (err) { t.fail(err) })
+ client1.on('warning', function (err) { t.fail(err) })
+
+ var torrent1 = client1.add(parsedTorrent)
+
+ torrent1.on('peer', function () {
+ t.pass('client1 found itself')
+ cb(null)
+ })
+
+ torrent1.on('blockedPeer', function () {
+ t.fail('client1 should not block any peers')
+ })
+ },
+
+ function (cb) {
+ client2 = new WebTorrent({
+ dht: false,
+ blocklist: [ '127.0.0.1' ]
+ })
+ client2.on('error', function (err) { t.fail(err) })
+ client2.on('warning', function (err) { t.fail(err) })
+
+ var torrent2 = client2.add(parsedTorrent)
+
+ torrent2.once('blockedPeer', function () {
+ t.pass('client2 blocked first peer')
+
+ torrent2.once('blockedPeer', function () {
+ t.pass('client2 blocked second peer')
+ cb(null)
+ })
+ })
+
+ torrent2.on('peer', function () {
+ t.fail('client2 should not find any peers')
+ })
+ }
+
+ ], function (err) {
+ t.error(err)
+ tracker.close(function () {
+ t.pass('tracker closed')
+ })
+ client1.destroy(function (err) {
+ t.error(err, 'client1 destroyed')
+ })
+ client2.destroy(function (err) {
+ t.error(err, 'client2 destroyed')
+ })
+ })
+})