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

81 lines
2 KiB
JavaScript
Raw Normal View History

import request from 'supertest';
import _ from 'lodash';
import path from 'path';
import rimraf from 'rimraf';
import configDefault from './partials/config/access';
import Config from '../../src/lib/config';
import Storage from '../../src/lib/storage';
import Auth from '../../src/lib/auth';
import indexAPI from '../../src/api/index';
require('../../src/lib/logger').setup([]);
describe('api with no limited access configuration', () => {
let config;
let storage;
let auth;
let app;
beforeAll(function(done) {
2018-03-11 13:25:13 -05:00
const store = path.join(__dirname, './partials/store/access-storage');
rimraf(store, () => {
const configForTest = _.clone(configDefault);
configForTest.auth = {
htpasswd: {
file: './access-storage/htpasswd-access-test'
}
};
configForTest.self_path = store;
config = new Config(configForTest);
storage = new Storage(config);
auth = new Auth(config);
app = indexAPI(config, auth, storage);
done();
});
});
2018-03-11 13:25:13 -05:00
afterAll(function(done) {
const store = path.join(__dirname, './partials/store/access-storage');
rimraf(store, (err) => {
if (err) {
return done(err);
}
return done();
});
});
describe('test proxy packages partially restricted', () => {
test('should test fails on fetch endpoint /-/jquery', (done) => {
request(app)
.get('/jquery')
.set('content-type', 'application/json; charset=utf-8')
.expect('Content-Type', /json/)
.expect(404)
.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', 'application/json; charset=utf-8')
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
if (err) {
return done(err);
}
done();
});
});
});
});