2017-04-19 21:15:28 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
let assert = require('assert');
|
2014-03-07 20:48:24 +01:00
|
|
|
|
|
|
|
module.exports = function() {
|
2017-04-19 21:15:28 +02:00
|
|
|
let server = process.server;
|
|
|
|
let express = process.express;
|
2014-03-07 20:48:24 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
describe('Incomplete', function() {
|
|
|
|
before(function() {
|
|
|
|
express.get('/testexp-incomplete', function(_, res) {
|
|
|
|
res.send({
|
2017-04-19 21:15:28 +02:00
|
|
|
'name': 'testexp-incomplete',
|
|
|
|
'versions': {
|
|
|
|
'0.1.0': {
|
|
|
|
'name': 'testexp_tags',
|
|
|
|
'version': '0.1.0',
|
|
|
|
'dist': {
|
|
|
|
'shasum': 'fake',
|
|
|
|
'tarball': 'http://localhost:55550/testexp-incomplete/-/content-length.tar.gz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'0.1.1': {
|
|
|
|
'name': 'testexp_tags',
|
|
|
|
'version': '0.1.1',
|
|
|
|
'dist': {
|
|
|
|
'shasum': 'fake',
|
|
|
|
'tarball': 'http://localhost:55550/testexp-incomplete/-/chunked.tar.gz',
|
|
|
|
},
|
2014-11-12 12:14:37 +01:00
|
|
|
},
|
2017-04-19 21:15:28 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2014-03-07 20:48:24 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
;['content-length', 'chunked'].forEach(function(type) {
|
2014-11-12 12:14:37 +01:00
|
|
|
it('should not store tarballs / ' + type, function(_cb) {
|
2017-04-19 21:15:28 +02:00
|
|
|
let called;
|
2014-11-12 12:14:37 +01:00
|
|
|
express.get('/testexp-incomplete/-/'+type+'.tar.gz', function(_, res) {
|
2017-04-19 21:15:28 +02:00
|
|
|
if (called) return res.socket.destroy();
|
|
|
|
called = true;
|
|
|
|
if (type !== 'chunked') res.header('content-length', 1e6);
|
|
|
|
res.write('test test test\n');
|
2014-11-12 12:14:37 +01:00
|
|
|
setTimeout(function() {
|
2017-04-19 21:15:28 +02:00
|
|
|
res.socket.write('200\nsss\n');
|
|
|
|
res.socket.destroy();
|
|
|
|
cb();
|
|
|
|
}, 10);
|
|
|
|
});
|
2014-03-07 20:48:24 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
server.request({uri: '/testexp-incomplete/-/'+type+'.tar.gz'})
|
2015-04-11 19:11:04 +02:00
|
|
|
.status(200)
|
2017-04-19 21:15:28 +02:00
|
|
|
.response(function(res) {
|
|
|
|
if (type !== 'chunked') assert.equal(res.headers['content-length'], 1e6);
|
2015-04-11 19:11:04 +02:00
|
|
|
})
|
2017-04-19 21:15:28 +02:00
|
|
|
.then(function(body) {
|
|
|
|
assert(body.match(/test test test/));
|
|
|
|
});
|
2014-03-07 20:48:24 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
function cb() {
|
2017-04-19 21:15:28 +02:00
|
|
|
server.request({uri: '/testexp-incomplete/-/'+type+'.tar.gz'})
|
2015-04-11 19:11:04 +02:00
|
|
|
.body_error('internal server error')
|
2017-04-19 21:15:28 +02:00
|
|
|
.then(function() {
|
|
|
|
_cb();
|
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2014-03-07 20:48:24 +01:00
|
|
|
|