mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
631abe1ac1
* refactor logger module * Update index.ts
97 lines
2.1 KiB
TypeScript
97 lines
2.1 KiB
TypeScript
import request from 'supertest';
|
|
|
|
import { HTTP_STATUS } from '@verdaccio/core';
|
|
import { logger, setup } from '@verdaccio/logger';
|
|
|
|
import { allow } from '../src';
|
|
import { getApp } from './helper';
|
|
|
|
setup({});
|
|
|
|
test('should allow request', async () => {
|
|
const can = allow(
|
|
{
|
|
allow_publish: (params, remove, cb) => {
|
|
return cb(null, true);
|
|
},
|
|
},
|
|
logger
|
|
);
|
|
const app = getApp([]);
|
|
// @ts-ignore
|
|
app.get('/:package', can('publish'), (req, res) => {
|
|
res.status(HTTP_STATUS.OK).json({});
|
|
});
|
|
|
|
return request(app).get('/react').expect(HTTP_STATUS.OK);
|
|
});
|
|
|
|
test('should allow scope request', async () => {
|
|
const can = allow(
|
|
{
|
|
allow_publish: (params, remove, cb) => {
|
|
return cb(null, true);
|
|
},
|
|
},
|
|
logger
|
|
);
|
|
const app = getApp([]);
|
|
// @ts-ignore
|
|
app.get('/:package/:scope', can('publish'), (req, res) => {
|
|
res.status(HTTP_STATUS.OK).json({});
|
|
});
|
|
|
|
return request(app).get('/@verdaccio/core').expect(HTTP_STATUS.OK);
|
|
});
|
|
|
|
test('should allow filename request', async () => {
|
|
const can = allow(
|
|
{
|
|
allow_publish: (params, remove, cb) => {
|
|
return cb(null, true);
|
|
},
|
|
},
|
|
logger
|
|
);
|
|
const app = getApp([]);
|
|
// @ts-ignore
|
|
app.get('/:filename', can('publish'), (req, res) => {
|
|
res.status(HTTP_STATUS.OK).json({});
|
|
});
|
|
|
|
return request(app).get('/aaa-0.0.1.tgz').expect(HTTP_STATUS.OK);
|
|
});
|
|
|
|
test('should not allow request', async () => {
|
|
const can = allow(
|
|
{
|
|
allow_publish: (params, remove, cb) => {
|
|
return cb(null, false);
|
|
},
|
|
},
|
|
logger
|
|
);
|
|
const app = getApp([]);
|
|
// @ts-ignore
|
|
app.get('/sec', can('publish'), (req, res) => {
|
|
res.status(HTTP_STATUS.OK).json({});
|
|
});
|
|
|
|
return request(app).get('/sec').expect(HTTP_STATUS.INTERNAL_ERROR);
|
|
});
|
|
|
|
test('should handle error request', async () => {
|
|
const can = allow(
|
|
{
|
|
allow_publish: (params, remove, cb) => {
|
|
return cb(Error('foo error'));
|
|
},
|
|
},
|
|
logger
|
|
);
|
|
const app = getApp([]);
|
|
// @ts-ignore
|
|
app.get('/err', can('publish'));
|
|
|
|
return request(app).get('/err').expect(HTTP_STATUS.INTERNAL_ERROR);
|
|
});
|