1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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)
})
|