0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/test/unit/modules/access/pkg.access.spec.js

87 lines
2.2 KiB
JavaScript
Raw Normal View History

import request from 'supertest';
import _ from 'lodash';
import path from 'path';
import rimraf from 'rimraf';
2019-05-19 15:23:12 -05:00
import { HEADERS, HTTP_STATUS } from '../../../../src/lib/constants';
import configDefault from '../../partials/config/config_access';
import endPointAPI from '../../../../src/api';
import {mockServer} from '../../__helper/mock';
import {DOMAIN_SERVERS} from '../../../functional/config.functional';
2019-05-19 15:23:12 -05:00
require('../../../../src/lib/logger').setup([]);
describe('api with no limited access configuration', () => {
let app;
let mockRegistry;
2019-05-19 15:23:12 -05:00
const store = path.join(__dirname, '../../partials/store/pkg-access-spec');
beforeAll(function(done) {
const mockServerPort = 55530;
2019-05-19 15:23:12 -05:00
rimraf(store, async () => {
const configForTest = _.assign({}, _.cloneDeep(configDefault), {
auth: {
htpasswd: {
2019-05-19 15:23:12 -05:00
file: './access-storage/htpasswd-pkg-access'
}
},
self_path: store,
uplinks: {
npmjs: {
url: `http://${DOMAIN_SERVERS}:${mockServerPort}`
}
}
});
app = await endPointAPI(configForTest);
mockRegistry = await mockServer(mockServerPort).init();
done();
});
});
2018-03-11 13:25:13 -05:00
afterAll(function(done) {
rimraf(store, (err) => {
if (err) {
mockRegistry[0].stop();
2018-03-11 13:25:13 -05:00
return done(err);
}
mockRegistry[0].stop();
2018-03-11 13:25:13 -05:00
return done();
});
});
describe('test proxy packages partially restricted', () => {
test('should test fails on fetch endpoint /-/jquery', (done) => {
request(app)
.get('/jquery')
.set('content-type', HEADERS.JSON_CHARSET)
.expect('Content-Type', /json/)
.expect(HTTP_STATUS.NOT_FOUND)
.end(function(err, res) {
if (err) {
return done(err);
}
done();
});
});
2018-03-11 13:25:13 -05:00
test('should success on fetch endpoint /-/vue', (done) => {
request(app)
2018-03-11 13:25:13 -05:00
.get('/vue')
.set('content-type', HEADERS.JSON_CHARSET)
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
if (err) {
return done(err);
}
done();
});
});
});
});