0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00
verdaccio/test/functional/sanity/security.ts

79 lines
2.5 KiB
TypeScript
Raw Normal View History

import _ from 'lodash';
import { HTTP_STATUS } from '../../../src/lib/constants';
2013-12-19 10:11:54 -05:00
export default function (server) {
describe('should test security on endpoints', () => {
2017-12-02 05:19:08 -05:00
beforeAll(function () {
return server.addPackage('testpkg-sec');
2017-04-19 14:15:28 -05:00
});
2013-12-19 10:11:54 -05:00
test('should fails on fetch bad pkg #1', () => {
return server
.getPackage('__proto__')
.status(HTTP_STATUS.FORBIDDEN)
.body_error(/invalid package/);
2017-04-19 14:15:28 -05:00
});
2013-12-19 10:11:54 -05:00
test('should fails on fetch bad pkg #2', () => {
return server
.getPackage('__proto__')
.status(HTTP_STATUS.FORBIDDEN)
.body_error(/invalid package/);
2017-04-19 14:15:28 -05:00
});
test('should do not fails on __proto__, connect stuff', () => {
return server.request({ uri: '/testpkg-sec?__proto__=1' }).then(function (body) {
// test for NOT outputting stack trace
expect(_.isNil(body) || _.isObject(body) || body.indexOf('node_modules')).toBeTruthy();
2013-12-19 10:11:54 -05:00
// test for NOT crashing
return server.request({ uri: '/testpkg-sec' }).status(HTTP_STATUS.OK);
});
2017-04-19 14:15:28 -05:00
});
2013-12-19 10:11:54 -05:00
test('should fails and do not return __proto__ as an attachment', () => {
return server
.request({ uri: '/testpkg-sec/-/__proto__' })
.status(HTTP_STATUS.FORBIDDEN)
.body_error(/invalid filename/);
2017-04-19 14:15:28 -05:00
});
2013-12-19 10:11:54 -05:00
test('should fails on fetch silly things - reading #1', () => {
return server
.request({ uri: '/testpkg-sec/-/../../../../../../../../etc/passwd' })
.status(HTTP_STATUS.NOT_FOUND);
2017-04-19 14:15:28 -05:00
});
2013-12-19 10:11:54 -05:00
test('should fails on fetch silly things - reading #2', () => {
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'
})
.status(HTTP_STATUS.FORBIDDEN)
.body_error(/invalid filename/);
2017-04-19 14:15:28 -05:00
});
2013-12-19 10:11:54 -05:00
test('should fails on fetch silly things - writing #1', () => {
return server
.putTarball('testpkg-sec', '__proto__', '{}')
.status(HTTP_STATUS.FORBIDDEN)
.body_error(/invalid filename/);
2017-04-19 14:15:28 -05:00
});
2013-12-19 10:11:54 -05:00
test('should fails on fetch silly things - writing #3', () => {
return server
.putTarball('testpkg-sec', 'node_modules', '{}')
.status(HTTP_STATUS.FORBIDDEN)
.body_error(/invalid filename/);
2017-04-19 14:15:28 -05:00
});
2013-12-19 10:11:54 -05:00
test('should fails on fetch silly things - writing #4', () => {
return server
.putTarball('testpkg-sec', '../testpkg.tgz', '{}')
.status(HTTP_STATUS.FORBIDDEN)
.body_error(/invalid filename/);
2017-04-19 14:15:28 -05:00
});
});
2017-12-02 05:20:27 -05:00
}