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:
authorFeross Aboukhadijeh <feross@feross.org>2016-05-20 02:08:18 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-05-20 02:08:18 +0300
commit722cd0ab2f46b7a0bdafb6069b5ee1530c34fd15 (patch)
treeb85659f9888f5b62176af8286c4e193924cc348b /test
parentf0a035ae321dbf3ab8c6191b39017f7e0666ba55 (diff)
add more metadata tests
- test multiple &xs= params in magnet link - test param that 404s
Diffstat (limited to 'test')
-rw-r--r--test/node/download-metadata.js83
1 files changed, 67 insertions, 16 deletions
diff --git a/test/node/download-metadata.js b/test/node/download-metadata.js
index 59936cb..95d5795 100644
--- a/test/node/download-metadata.js
+++ b/test/node/download-metadata.js
@@ -5,56 +5,107 @@ var WebTorrent = require('../../')
function createServer (data, cb) {
var server = http.createServer(function (req, res) {
+ if (req.url !== '/') {
+ res.statusCode = 404
+ res.end()
+ }
res.end(data)
- }).listen(function () {
+ })
+
+ server.on('listening', function () {
var address = server.address()
if (address.family === 'IPv6') {
address.address = '[' + address.address + ']'
}
var url = 'http://' + address.address + ':' + address.port + '/'
- cb(url, next)
+ cb(url, server)
})
- function next () {
- server.close()
- }
+ server.listen()
}
test('Download metadata for magnet URI with xs parameter', function (t) {
- t.plan(2)
+ t.plan(3)
var client = new WebTorrent({ dht: false, tracker: false })
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- createServer(fixtures.leaves.torrent, function (url, next) {
- client.add(fixtures.leaves.magnetURI + '&xs=' + encodeURIComponent(url), function (torrent) {
+ createServer(fixtures.leaves.torrent, function (url, server) {
+ var encodedUrl = encodeURIComponent(url)
+ client.add(fixtures.leaves.magnetURI + '&xs=' + encodedUrl, function (torrent) {
t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
-
client.destroy(function (err) { t.error(err, 'client destroyed') })
- next()
+ server.close(function () { t.pass('server closed') })
})
})
})
-test('Download metadata for magnet URI with xs parameter', function (t) {
- t.plan(2)
+test('Download metadata for magnet URI with 2 xs parameters', function (t) {
+ t.plan(4)
var client = new WebTorrent({ dht: false, tracker: false })
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
- createServer(fixtures.leaves.torrent, function (url, next) {
- var encoded = encodeURIComponent(url)
- var uri = fixtures.leaves.magnetURI + '&xs=' + encoded + '&xs=' + encoded + '2'
+ createServer(fixtures.leaves.torrent, function (url1, server1) {
+ var encodedUrl1 = encodeURIComponent(url1)
+
+ createServer(fixtures.leaves.torrent, function (url2, server2) {
+ var encodedUrl2 = encodeURIComponent(url2)
+
+ var uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2
+
+ client.add(uri, function (torrent) {
+ t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
+ client.destroy(function (err) { t.error(err, 'client destroyed') })
+ server1.close(function () { t.pass('server closed') })
+ server2.close(function () { t.pass('server closed') })
+ })
+ })
+ })
+})
+
+test('Download metadata for magnet URI with 2 xs parameters, with 1 invalid protocol', function (t) {
+ t.plan(3)
+
+ var client = new WebTorrent({ dht: false, tracker: false })
+
+ client.on('error', function (err) { t.fail(err) })
+ client.on('warning', function (err) { t.fail(err) })
+
+ createServer(fixtures.leaves.torrent, function (url, server) {
+ var encodedUrl1 = encodeURIComponent('invalidurl:example')
+ var encodedUrl2 = encodeURIComponent(url)
+ var uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2
client.add(uri, function (torrent) {
t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
+ client.destroy(function (err) { t.error(err, 'client destroyed') })
+ server.close(function () { t.pass('server closed') })
+ })
+ })
+})
+test('Download metadata for magnet URI with 2 xs parameters, with 1 404 URL', function (t) {
+ t.plan(3)
+
+ var client = new WebTorrent({ dht: false, tracker: false })
+
+ client.on('error', function (err) { t.fail(err) })
+ client.on('warning', function (err) { t.fail(err) })
+
+ createServer(fixtures.leaves.torrent, function (url, server) {
+ var encodedUrl1 = encodeURIComponent(url + 'blah_404')
+ var encodedUrl2 = encodeURIComponent(url)
+ var uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2
+
+ client.add(uri, function (torrent) {
+ t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
client.destroy(function (err) { t.error(err, 'client destroyed') })
- next()
+ server.close(function () { t.pass('server closed') })
})
})
})