webseeded-torrent-generator
Version:
Generate webseeded torrent files from urls to files.
242 lines (224 loc) • 11.3 kB
JavaScript
var assert = require('assert');
var HttpFile = require('../lib/http-fs');
describe('Http File Test', function () {
this.timeout(3000);
describe('Accuracy Tests', function () {
it('returns the correct file size for big_buck_bunny', function (done) {
var file = new HttpFile('http://mirrorblender.top-ix.org/peach/bigbuckbunny_movies/big_buck_bunny_1080p_surround.avi');
file.size().then(function (size) {
assert(size === 928670754, 'size returned the wrong file size');
done();
}).fail(function (error) {
done(new Error(error));
});
});
it('returns the correct file size for jack_johnson_banana_pancakes', function (done) {
var file = new HttpFile('http://ia700201.us.archive.org/6/items/jj2005-02-27.fm.shnf/jj2005-02-27.fm.d1t2_64kb.mp3');
file.size().then(function (size) {
assert(size === 1489315, 'size returned the wrong file size');
done();
}).fail(function (error) {
done(new Error(error));
});
});
it('reads the first 10 bytes of jack_johnson_banana_pancakes correctly', function (done) {
var file = new HttpFile('http://ia700201.us.archive.org/6/items/jj2005-02-27.fm.shnf/jj2005-02-27.fm.d1t2_64kb.mp3');
file.read(0, 0x10).then(function (buffer) {
assert(buffer instanceof Buffer, 'buffer is not a Buffer');
assert(buffer.toString('hex') === 'fff38064000000000000000000000000', 'incorrect content');
done();
}).fail(function (error) {
done(new Error(error));
});
});
it('returns the file size of a zero byte file', function (done) {
var file = new HttpFile('http://s3.amazonaws.com/content-test/empty_file');
file.size().then(function (size) {
assert(size === 0, 'size returned the wrong file size');
done();
}).fail(function (error) {
done(new Error(error));
});
});
it('returns the file size of a huge file', function (done) {
var file = new HttpFile('https://s3.amazonaws.com/content-bundles/production-df0ec56d-0fbb-bc2c-11e7-354ff3af9c4e/bf3a4aa8cfe2a908002c9981948f38a07c9997df752a9abeee537aa6dc7bcebf/originals/Footsteps/FOOTSTEPS_2012_FEATUREFILM_1080p.mp4');
file.size().then(function (size) {
assert(size === 4777722361, 'size returned the wrong file size');
done();
}).fail(function (error) {
done(new Error(error));
});
});
});
describe('Encoding Tests', function () {
var PERCENT_FILE_NAME = 'https://s3.amazonaws.com/content-test/go hard 100%.png';
it('Tests ' + PERCENT_FILE_NAME, function (done) {
new HttpFile(PERCENT_FILE_NAME).size().then(function () {
done();
}, function (err) {
done(new Error(err));
});
});
it('Tests encoded version of ' + PERCENT_FILE_NAME + ' does not exist', function (done) {
new HttpFile(encodeURI(PERCENT_FILE_NAME)).size().then(function () {
done(new Error('encoded version of ' + PERCENT_FILE_NAME + ' should not exist'));
}, function () {
done();
});
});
var CHINESE_FILE_NAME = 'https://s3.amazonaws.com/content-test/布碌崙滅門慘案報導.mp4';
it('Tests ' + CHINESE_FILE_NAME, function (done) {
new HttpFile(CHINESE_FILE_NAME).size().then(function () {
done();
}, function (err) {
done(new Error(err));
});
});
it('Tests encoded version of ' + CHINESE_FILE_NAME + ' does not exist', function (done) {
new HttpFile(encodeURI(CHINESE_FILE_NAME)).size().then(function () {
done(new Error('encoded version of ' + CHINESE_FILE_NAME + ' should not exist'));
}, function () {
done();
});
});
var CHINESE_DIRECTORY = 'https://s3.amazonaws.com/content-test/布碌崙滅門慘案報導/布碌崙滅門慘案報導.mp4';
it('Tests ' + CHINESE_DIRECTORY, function (done) {
new HttpFile(CHINESE_DIRECTORY).size().then(function () {
done();
}, function (err) {
done(new Error(err));
});
});
it('Tests encoded version of ' + CHINESE_DIRECTORY + ' does not exist', function (done) {
new HttpFile(encodeURI(CHINESE_DIRECTORY)).size().then(function () {
done(new Error('encoded version of ' + CHINESE_DIRECTORY + ' should not exist'));
}, function () {
done();
});
});
var APOSTROPHE_FILE_NAME = 'https://s3.amazonaws.com/content-test/00_What\'s-Inside.html';
it('Tests ' + APOSTROPHE_FILE_NAME, function (done) {
new HttpFile(APOSTROPHE_FILE_NAME).size().then(function () {
done();
}, function (err) {
done(new Error(err));
});
});
var CONTAINS_PLUS_FILE_NAME = 'https://s3.amazonaws.com/content-test/1+2=3.png';
it('Tests ' + CONTAINS_PLUS_FILE_NAME, function (done) {
new HttpFile(CONTAINS_PLUS_FILE_NAME).size().then(function () {
done();
}, function (err) {
done(new Error(err));
});
});
it('Tests encoded version of ' + CONTAINS_PLUS_FILE_NAME + ' does not exist', function (done) {
var encodedFileName = encodeURI(CONTAINS_PLUS_FILE_NAME)
.replace(/#/g, encodeURIComponent('#'))
.replace(/\?/g, encodeURIComponent('?'))
.replace(/&/g, encodeURIComponent('&'))
.replace(/\+/g, encodeURIComponent('+'))
.replace(/\=/g, encodeURIComponent('='));
new HttpFile(encodedFileName).size().then(function () {
done(new Error('encoded version of ' + CONTAINS_PLUS_FILE_NAME + ' should not exist'));
}, function () {
done();
});
});
var CONTAINS_HASH_FILE_NAME = 'http://s3.amazonaws.com/content-test/file_with_a_#_in_it';
it('Tests ' + CONTAINS_HASH_FILE_NAME, function (done) {
new HttpFile(CONTAINS_HASH_FILE_NAME).size().then(function () {
done();
}, function (err) {
done(new Error(err));
});
});
it('Tests encoded version of ' + CONTAINS_HASH_FILE_NAME + ' does not exist', function (done) {
var encodedFileName = encodeURI(CONTAINS_HASH_FILE_NAME)
.replace(/#/g, encodeURIComponent('#'))
.replace(/\?/g, encodeURIComponent('?'))
.replace(/&/g, encodeURIComponent('&'))
.replace(/\+/g, encodeURIComponent('+'))
.replace(/\=/g, encodeURIComponent('='));
new HttpFile(encodedFileName).size().then(function () {
done(new Error('encoded version of ' + CONTAINS_HASH_FILE_NAME + ' should not exist'));
}, function () {
done();
});
});
var CONTAINS_SPECIAL_URL_CHARACTERS_FILE_NAME = 'http://s3.amazonaws.com/content-test/and&?.png';
it('Tests ' + CONTAINS_SPECIAL_URL_CHARACTERS_FILE_NAME, function (done) {
new HttpFile(CONTAINS_SPECIAL_URL_CHARACTERS_FILE_NAME).size().then(function () {
done();
}, function (err) {
done(new Error(err));
});
});
it('Tests encoded version of ' + CONTAINS_SPECIAL_URL_CHARACTERS_FILE_NAME + ' does not exist', function (done) {
var encodedFileName = encodeURI(CONTAINS_SPECIAL_URL_CHARACTERS_FILE_NAME)
.replace(/#/g, encodeURIComponent('#'))
.replace(/\?/g, encodeURIComponent('?'))
.replace(/&/g, encodeURIComponent('&'))
.replace(/\+/g, encodeURIComponent('+'))
.replace(/\=/g, encodeURIComponent('='));
new HttpFile(encodedFileName).size().then(function () {
done(new Error('encoded version of ' + CONTAINS_SPECIAL_URL_CHARACTERS_FILE_NAME + ' should not exist'));
}, function () {
done();
});
});
var HASH_BEGINNING_FILE_NAME = 'http://s3.amazonaws.com/content-test/#.png';
it('Tests ' + HASH_BEGINNING_FILE_NAME, function (done) {
new HttpFile(HASH_BEGINNING_FILE_NAME).size().then(function () {
done();
}, function (err) {
done(new Error(err));
});
});
it('Tests encoded version of ' + HASH_BEGINNING_FILE_NAME + ' does not exist', function (done) {
var encodedFileName = encodeURI(HASH_BEGINNING_FILE_NAME)
.replace(/#/g, encodeURIComponent('#'))
.replace(/\?/g, encodeURIComponent('?'))
.replace(/&/g, encodeURIComponent('&'))
.replace(/\+/g, encodeURIComponent('+'))
.replace(/\=/g, encodeURIComponent('='));
new HttpFile(encodedFileName).size().then(function () {
done(new Error('encoded version of ' + HASH_BEGINNING_FILE_NAME + ' should not exist'));
}, function () {
done();
});
});
var HASH_UNICODE_NAME = 'http://s3.amazonaws.com/content-test/_#_布碌崙滅門慘案報導.png';
it('Tests ' + HASH_UNICODE_NAME, function (done) {
new HttpFile(HASH_UNICODE_NAME).size().then(function () {
done();
}, function (err) {
done(new Error(err));
});
});
it('Tests encoded version of ' + HASH_UNICODE_NAME + ' does not exist', function (done) {
var encodedFileName = encodeURI(HASH_UNICODE_NAME)
.replace(/#/g, encodeURIComponent('#'))
.replace(/\?/g, encodeURIComponent('?'))
.replace(/&/g, encodeURIComponent('&'))
.replace(/\+/g, encodeURIComponent('+'))
.replace(/\=/g, encodeURIComponent('='));
new HttpFile(encodedFileName).size().then(function () {
done(new Error('encoded version of ' + HASH_UNICODE_NAME + ' should not exist'));
}, function () {
done();
});
});
});
describe('Networking Tests', function () {
it('supports redirects jack_johnson_banana_pancakes', function (done) {
var file = new HttpFile('http://archive.org/download/jj2005-02-27.fm.shnf/jj2005-02-27.fm.d1t2_64kb.mp3');
file.size().then(function (size) {
assert(size === 1489315, 'size returned the wrong file size');
done();
}, function (error) {
done(new Error(error));
});
});
});
});