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
path: root/test
diff options
context:
space:
mode:
authorAlex <alxmorais8@msn.com>2020-03-15 00:11:40 +0300
committerAlex <alxmorais8@msn.com>2020-03-15 00:11:40 +0300
commit1feb4b6f9aad2793c662c9fb55993edfa83f8079 (patch)
tree7b385ded17be43145e580a23daff51fd65ced17f /test
parent31f5166d9ee807d181ab547fcc58421ea85efdf5 (diff)
Add tests for private option
Diffstat (limited to 'test')
-rw-r--r--test/node/download-private-dht.js104
1 files changed, 104 insertions, 0 deletions
diff --git a/test/node/download-private-dht.js b/test/node/download-private-dht.js
index 35f90d3..0bc43c8 100644
--- a/test/node/download-private-dht.js
+++ b/test/node/download-private-dht.js
@@ -101,3 +101,107 @@ test('public torrent should use DHT', function (t) {
})
})
})
+
+test('public torrent with forced private option should not use DHT', function (t) {
+ t.plan(4)
+
+ var dhtServer = new DHT({ bootstrap: false })
+
+ dhtServer.on('error', function (err) { t.fail(err) })
+ dhtServer.on('warning', function (err) { t.fail(err) })
+
+ var client
+
+ series([
+ function (cb) {
+ dhtServer.listen(cb)
+ },
+
+ function (cb) {
+ client = new WebTorrent({
+ tracker: false,
+ dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ })
+
+ client.on('error', function (err) { t.fail(err) })
+ client.on('warning', function (err) { t.fail(err) })
+
+ var torrent = client.add(fixtures.leaves.parsedTorrent, {
+ private: true,
+ store: MemoryChunkStore
+ })
+
+ torrent.on('dhtAnnounce', function () {
+ t.fail('client announced to dht')
+ })
+
+ client.on('torrent', function () {
+ if (!torrent.discovery.dht) {
+ t.pass('dht is disabled for this torrent')
+ cb(null)
+ }
+ })
+ }
+ ], function (err) {
+ t.error(err)
+
+ dhtServer.destroy(function (err) {
+ t.error(err, 'dht server destroyed')
+ })
+ client.destroy(function (err) {
+ t.error(err, 'client destroyed')
+ })
+ })
+})
+
+test('private torrent with forced public option should use DHT', function (t) {
+ t.plan(4)
+
+ var dhtServer = new DHT({ bootstrap: false })
+
+ dhtServer.on('error', function (err) { t.fail(err) })
+ dhtServer.on('warning', function (err) { t.fail(err) })
+
+ var client
+
+ series([
+ function (cb) {
+ dhtServer.listen(cb)
+ },
+
+ function (cb) {
+ client = new WebTorrent({
+ tracker: false,
+ dht: { bootstrap: '127.0.0.1:' + dhtServer.address().port }
+ })
+
+ client.on('error', function (err) { t.fail(err) })
+ client.on('warning', function (err) { t.fail(err) })
+
+ var torrent = client.add(fixtures.bunny.parsedTorrent, {
+ private: false,
+ store: MemoryChunkStore
+ })
+
+ torrent.on('dhtAnnounce', function () {
+ t.pass('client announced to dht')
+ cb(null)
+ })
+
+ client.on('torrent', function () {
+ if (!torrent.client.dht) {
+ t.fail('dht server is null')
+ }
+ })
+ }
+ ], function (err) {
+ t.error(err)
+
+ dhtServer.destroy(function (err) {
+ t.error(err, 'dht server destroyed')
+ })
+ client.destroy(function (err) {
+ t.error(err, 'client destroyed')
+ })
+ })
+})