2018-06-23 09:18:31 +02:00
|
|
|
import _ from 'lodash';
|
|
|
|
import {HTTP_STATUS} from '../../../src/lib/constants';
|
2017-04-19 21:15:28 +02:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
export default function(server) {
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
describe('should test security on endpoints', () => {
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-06-28 22:56:02 +02:00
|
|
|
return server.addPackage('testpkg-sec');
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch bad pkg #1', () => {
|
2017-06-28 22:56:02 +02:00
|
|
|
return server.getPackage('package.json')
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid package/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch bad pkg #2', () => {
|
2017-06-28 22:56:02 +02:00
|
|
|
return server.getPackage('__proto__')
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid package/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2015-03-28 19:25:53 +01:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should do not fails on __proto__, connect stuff', () => {
|
2017-04-19 21:15:28 +02:00
|
|
|
return server.request({uri: '/testpkg-sec?__proto__=1'})
|
2017-08-06 21:54:15 +02:00
|
|
|
.then(function (body) {
|
2015-04-11 19:11:04 +02:00
|
|
|
// test for NOT outputting stack trace
|
2018-06-23 09:18:31 +02:00
|
|
|
expect(_.isNil(body) || _.isObject(body) || body.indexOf('node_modules')).toBeTruthy();
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
// test for NOT crashing
|
2018-06-23 09:18:31 +02:00
|
|
|
return server.request({uri: '/testpkg-sec'}).status(HTTP_STATUS.OK);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails and do not return package.json as an attachment', () => {
|
2017-04-19 21:15:28 +02:00
|
|
|
return server.request({uri: '/testpkg-sec/-/package.json'})
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid filename/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch silly things - reading #1', () => {
|
2017-04-19 21:15:28 +02:00
|
|
|
return server.request({uri: '/testpkg-sec/-/../../../../../../../../etc/passwd'})
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.NOT_FOUND);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch silly things - reading #2', () => {
|
2017-04-19 21:15:28 +02:00
|
|
|
return server.request({uri: '/testpkg-sec/-/%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd'})
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid filename/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch silly things - writing #1', () => {
|
2017-06-28 22:56:02 +02:00
|
|
|
return server.putTarball('testpkg-sec', 'package.json', '{}')
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid filename/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch silly things - writing #3', () => {
|
2017-06-28 22:56:02 +02:00
|
|
|
return server.putTarball('testpkg-sec', 'node_modules', '{}')
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid filename/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2018-06-23 09:18:31 +02:00
|
|
|
test('should fails on fetch silly things - writing #4', () => {
|
2017-06-28 22:56:02 +02:00
|
|
|
return server.putTarball('testpkg-sec', '../testpkg.tgz', '{}')
|
2018-06-23 09:18:31 +02:00
|
|
|
.status(HTTP_STATUS.FORBIDDEN)
|
2017-08-06 21:54:15 +02:00
|
|
|
.body_error(/invalid filename/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
|
|
|
});
|
2017-12-02 11:20:27 +01:00
|
|
|
}
|