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:
authorSebastian Mayr <github@smayr.name>2016-05-13 06:05:16 +0300
committerSebastian Mayr <github@smayr.name>2016-05-17 20:26:33 +0300
commitd498f11b7668e15fa2ee6e9518e20d917f63da17 (patch)
tree04aff2ef9fc63c8f30e8f791f7b4cf91bd017690 /test
parentc3acb343e916cb898549bb155cb6a4366fb1b91f (diff)
Implement exact source (xs) for magnet URIs
Diffstat (limited to 'test')
-rw-r--r--test/node/download-metadata.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/node/download-metadata.js b/test/node/download-metadata.js
new file mode 100644
index 0000000..07b605a
--- /dev/null
+++ b/test/node/download-metadata.js
@@ -0,0 +1,65 @@
+var fixtures = require('webtorrent-fixtures')
+var http = require('http')
+var test = require('tape')
+var WebTorrent = require('../../')
+
+function createServer (data, cb) {
+ var server = http.createServer(function (req, res) {
+ res.end(data)
+ }).listen(function () {
+ var address = server.address()
+ if (address.family === 'IPv6') {
+ address.address = '[' + address.address + ']'
+ }
+ var url = 'http://' + address.address + ':' + address.port + '/'
+ cb(url, next)
+ })
+
+ function next () {
+ server.close()
+ }
+}
+
+test('Download metadata for magnet URI with xs parameter', function (t) {
+ t.plan(2)
+
+ var client = new WebTorrent({ dht: false, tracker: false })
+
+ createServer(fixtures.leaves.torrent, function (url, next) {
+ client.add(fixtures.leaves.magnetURI + '&xs=' + encodeURIComponent(url), function (torrent) {
+ t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub')
+
+ client.destroy(function (err) { t.error(err, 'client destroyed') })
+ next()
+ })
+ })
+})
+
+test('Download metadata for magnet URI with xs parameter', function (t) {
+ t.plan(2)
+
+ var client = new WebTorrent({ dht: false, tracker: false })
+
+ createServer(fixtures.leaves.torrent, function (url, next) {
+ var encoded = encodeURIComponent(url)
+ var uri = fixtures.leaves.magnetURI + '&xs=' + encoded + '&xs=' + encoded + '2'
+
+ client.add(uri, function (torrent) {
+ t.equal(torrent.name, 'Leaves of Grass by Walt Whitman.epub')
+
+ client.destroy(function (err) { t.error(err, 'client destroyed') })
+ next()
+ })
+ })
+})
+
+test('Download metadata magnet URI with unsupported protocol in xs parameter', function (t) {
+ t.plan(2)
+
+ var client = new WebTorrent({ dht: false, tracker: false })
+ client.add(fixtures.leaves.magnetURI + '&xs=' + encodeURIComponent('invalidurl:example'))
+ setTimeout(function () {
+ t.ok(true, 'no crash')
+ client.destroy(function (err) { t.error(err, 'client destroyed') })
+ }, 100)
+})