0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-23 22:27:34 -05:00
verdaccio/packages/server/test/package-access/index.spec.ts

98 lines
2.5 KiB
TypeScript
Raw Normal View History

2020-03-03 17:59:19 -05:00
import path from 'path';
import request from 'supertest';
2020-03-03 17:59:19 -05:00
import { setup, logger } from '@verdaccio/logger';
2020-03-03 17:59:19 -05:00
setup([]);
import { HEADERS, HTTP_STATUS } from '@verdaccio/commons-api';
import { generateRamdonStorage, mockServer, configExample, DOMAIN_SERVERS } from '@verdaccio/mock';
import endPointAPI from '../../src';
2020-03-03 17:59:19 -05:00
describe('api with no limited access configuration', () => {
let app;
let mockRegistry;
const store = generateRamdonStorage();
jest.setTimeout(10000);
beforeAll(async (done) => {
const mockServerPort = 55530;
const configForTest = configExample(
{
config_path: store,
uplinks: {
remote: {
url: `http://${DOMAIN_SERVERS}:${mockServerPort}`,
},
},
2020-03-03 17:59:19 -05:00
},
'pkg.access.yaml',
__dirname
);
2020-03-03 17:59:19 -05:00
app = await endPointAPI(configForTest);
const binPath = require.resolve('verdaccio/bin/verdaccio');
const storePath = path.join(__dirname, '/mock/store');
mockRegistry = await mockServer(mockServerPort, { storePath, silence: true }).init(binPath);
done();
});
afterAll(function (done) {
2020-03-03 17:59:19 -05:00
const [registry, pid] = mockRegistry;
registry.stop();
logger.info(`registry ${pid} has been stopped`);
done();
});
describe('test proxy packages partially restricted', () => {
test('should test fails on fetch endpoint /-/not-found', (done) => {
request(app)
// @ts-ignore
2020-03-03 17:59:19 -05:00
.get('/not-found-for-sure')
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
.expect(HEADERS.CONTENT_TYPE, /json/)
.expect(HTTP_STATUS.NOT_FOUND)
.end(function (err) {
2020-03-03 17:59:19 -05:00
if (err) {
return done(err);
}
done();
});
});
test('should test fetch endpoint /-/jquery', (done) => {
request(app)
// @ts-ignore
.get('/jquery')
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
.expect(HEADERS.CONTENT_TYPE, /json/)
.expect(HTTP_STATUS.OK)
.end(function (err) {
2020-03-03 17:59:19 -05:00
if (err) {
return done(err);
}
done();
});
});
test('should success on fetch endpoint /-/vue', (done) => {
request(app)
// @ts-ignore
.get('/vue')
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
.expect(HEADERS.CONTENT_TYPE, /json/)
.expect(HTTP_STATUS.OK)
.end(function (err) {
2020-03-03 17:59:19 -05:00
if (err) {
return done(err);
}
done();
});
});
});
});