2018-06-23 04:12:20 -05:00
|
|
|
import {API_ERROR, HEADER_TYPE, HTTP_STATUS} from '../../../src/lib/constants';
|
2018-06-24 03:11:52 -05:00
|
|
|
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.functional';
|
2017-08-06 14:54:15 -05:00
|
|
|
|
|
|
|
const defaultPkg = {
|
|
|
|
'name': 'testexp-incomplete',
|
|
|
|
'versions': {
|
|
|
|
'0.1.0': {
|
|
|
|
'name': 'testexp_tags',
|
|
|
|
'version': '0.1.0',
|
|
|
|
'dist': {
|
|
|
|
'shasum': 'fake',
|
2018-06-23 04:12:20 -05:00
|
|
|
'tarball': `http://${DOMAIN_SERVERS}:${PORT_SERVER_APP}/testexp-incomplete/-/content-length.tar.gz`,
|
2017-08-06 14:54:15 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'0.1.1': {
|
|
|
|
'name': 'testexp_tags',
|
|
|
|
'version': '0.1.1',
|
|
|
|
'dist': {
|
|
|
|
'shasum': 'fake',
|
2018-06-23 04:12:20 -05:00
|
|
|
'tarball': `http://${DOMAIN_SERVERS}:${PORT_SERVER_APP}/testexp-incomplete/-/chunked.tar.gz`,
|
2017-08-06 14:54:15 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
export default function (server, express) {
|
2018-06-23 04:12:20 -05:00
|
|
|
const listofCalls = [HEADER_TYPE.CONTENT_LENGTH, 'chunked'];
|
2017-08-06 14:54:15 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
describe('test send incomplete packages', () => {
|
2017-08-06 14:54:15 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
beforeAll(function () {
|
2017-08-06 14:54:15 -05:00
|
|
|
express.get('/testexp-incomplete', function (_, res) {
|
|
|
|
res.send(defaultPkg);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-24 03:11:52 -05:00
|
|
|
listofCalls.forEach((type) => {
|
|
|
|
test(`should not store tarballs / ${type}`, callback => {
|
2017-08-06 14:54:15 -05:00
|
|
|
let called;
|
2018-06-24 03:11:52 -05:00
|
|
|
express.get(`/testexp-incomplete/-/${type}.tar.gz`, function (_, response) {
|
2017-08-06 14:54:15 -05:00
|
|
|
if (called) {
|
|
|
|
return response.socket.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
called = true;
|
|
|
|
if (type !== 'chunked') {
|
2018-06-23 04:12:20 -05:00
|
|
|
response.header(HEADER_TYPE.CONTENT_LENGTH, 1e6);
|
2017-08-06 14:54:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
response.write('test test test\n');
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
response.socket.write('200\nsss\n');
|
|
|
|
response.socket.destroy();
|
|
|
|
cb();
|
|
|
|
}, 10);
|
|
|
|
});
|
|
|
|
|
|
|
|
server.request({uri: '/testexp-incomplete/-/' + type + '.tar.gz'})
|
2018-06-23 04:12:20 -05:00
|
|
|
.status(HTTP_STATUS.OK)
|
2017-08-06 14:54:15 -05:00
|
|
|
.response(function (res) {
|
|
|
|
if (type !== 'chunked') {
|
2018-06-23 04:12:20 -05:00
|
|
|
expect(parseInt(res.headers[HEADER_TYPE.CONTENT_LENGTH], 10)).toBe(1e6);
|
2017-08-06 14:54:15 -05:00
|
|
|
}
|
|
|
|
}).then(function (body) {
|
2018-06-23 04:12:20 -05:00
|
|
|
expect(body).toMatch(/test test test/);
|
2017-08-06 14:54:15 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
function cb() {
|
|
|
|
server.request({uri: '/testexp-incomplete/-/' + type + '.tar.gz'})
|
2018-06-23 04:12:20 -05:00
|
|
|
.body_error(API_ERROR.INTERNAL_SERVER_ERROR)
|
2017-08-06 14:54:15 -05:00
|
|
|
.then(function () {
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-12-02 05:19:08 -05:00
|
|
|
}
|