0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-04-08 02:54:13 -05:00

test(unit): add unit test for packages endpoint

This commit is contained in:
Juan Picado @jotadeveloper 2018-01-28 11:38:22 +01:00
parent 3e41dcaf6e
commit 819f06015e
No known key found for this signature in database
GPG key ID: 18AC54485952D158
3 changed files with 100 additions and 2 deletions

View file

@ -1,5 +1,3 @@
'use strict';
module.exports = function(route) {
route.get('/whoami', function(req, res, next) {
if (req.headers.referer === 'whoami') {

View file

@ -188,4 +188,87 @@ describe('endpoint unit test', () => {
});
describe('should test package api', () => {
test('should fetch jquery package from remote uplink', (done) => {
request(app)
.get('/jquery')
.set('content-type', 'application/json; charset=utf-8')
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
if (err) {
return done(err);
}
expect(res.body).toBeDefined();
expect(res.body.name).toMatch(/jquery/);
done();
});
});
test('should not found a unexisting remote package under scope', (done) => {
request(app)
.get('/@verdaccio/not-found')
.set('content-type', 'application/json; charset=utf-8')
.expect('Content-Type', /json/)
.expect(404)
.end(function(err, res) {
if (err) {
return done(err);
}
done();
});
});
test('should forbid access to remote package', (done) => {
request(app)
.get('/forbidden-place')
.set('content-type', 'application/json; charset=utf-8')
.expect('Content-Type', /json/)
.expect(403)
.end(function(err, res) {
if (err) {
return done(err);
}
done();
});
});
test('should fetch a tarball from remote uplink', (done) => {
request(app)
.get('/jquery/-/jquery-1.5.1.tgz')
.expect('Content-Type', /application\/octet-stream/)
.expect(200)
.end(function(err, res) {
if (err) {
return done(err);
}
expect(res.body).toBeDefined();
done();
});
});
test('should fails fetch a tarball from remote uplink', (done) => {
request(app)
.get('/jquery/-/jquery-0.0.1.tgz')
.expect('Content-Type', /application\/octet-stream/)
.expect(404)
.end(function(err, res) {
if (err) {
return done(err);
}
done();
});
});
});
});

View file

@ -6,8 +6,25 @@ const config = {
}
},
packages: {
'@*/*': {
allow_access: '$all',
allow_publish: '$all',
proxy: 'npmjs'
},
'forbidden-place': {
allow_access: 'nobody',
allow_publish: 'nobody'
},
'jquery': {
allow_access: '$all',
allow_publish: '$all',
proxy: 'npmjs'
},
'*': {
allow_access: '$all',
allow_publish: '$all'
},
},
logs: [