From d498f11b7668e15fa2ee6e9518e20d917f63da17 Mon Sep 17 00:00:00 2001 From: Sebastian Mayr Date: Fri, 13 May 2016 05:05:16 +0200 Subject: Implement exact source (xs) for magnet URIs --- test/node/download-metadata.js | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/node/download-metadata.js (limited to 'test') 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) +}) -- cgit v1.2.3