2022-07-29 13:51:45 -05:00
|
|
|
import express from 'express';
|
|
|
|
import nock from 'nock';
|
|
|
|
import { join } from 'path';
|
|
|
|
import supertest from 'supertest';
|
2020-10-23 16:12:54 -05:00
|
|
|
|
2022-07-29 13:51:45 -05:00
|
|
|
import { Config, parseConfigFile } from '@verdaccio/config';
|
|
|
|
import { logger, setup } from '@verdaccio/logger';
|
|
|
|
|
|
|
|
import { HTTP_STATUS } from '../../local-storage/node_modules/@verdaccio/core/build';
|
2020-10-23 16:12:54 -05:00
|
|
|
import ProxyAudit, { ConfigAudit } from '../src/index';
|
|
|
|
|
2023-02-12 14:26:18 -05:00
|
|
|
setup({});
|
2022-07-29 13:51:45 -05:00
|
|
|
|
|
|
|
const auditConfig: ConfigAudit = {
|
2020-10-23 16:12:54 -05:00
|
|
|
enabled: true,
|
|
|
|
} as ConfigAudit;
|
|
|
|
|
|
|
|
describe('Audit plugin', () => {
|
|
|
|
test('should test audit', () => {
|
2022-07-29 13:51:45 -05:00
|
|
|
const audit = new ProxyAudit(auditConfig, {
|
|
|
|
logger,
|
|
|
|
config: new Config(parseConfigFile(join(__dirname, 'config.yaml'))),
|
|
|
|
});
|
2020-10-23 16:12:54 -05:00
|
|
|
expect(audit).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should test audit with configuration', () => {
|
|
|
|
const config = { strict_ssl: false } as ConfigAudit;
|
2022-07-29 13:51:45 -05:00
|
|
|
const audit = new ProxyAudit(auditConfig, { logger, config: config });
|
2020-10-23 16:12:54 -05:00
|
|
|
expect(audit).toBeDefined();
|
2022-07-29 13:51:45 -05:00
|
|
|
// expect(audit.strict_ssl).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should handle /-/npm/v1/security/audits/quick', async () => {
|
|
|
|
nock('https://registry.npmjs.org')
|
|
|
|
.post('/-/npm/v1/security/audits/quick')
|
|
|
|
.reply(200, { foo: 'someData' });
|
|
|
|
const config = { strict_ssl: false } as ConfigAudit;
|
|
|
|
const audit = new ProxyAudit(auditConfig, { logger, config: config });
|
|
|
|
const app = express();
|
|
|
|
audit.register_middlewares(app, {
|
|
|
|
// @ts-ignore
|
|
|
|
config: {
|
|
|
|
https_proxy: '',
|
|
|
|
http_proxy: '',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await supertest(app).post('/-/npm/v1/security/audits/quick').expect(HTTP_STATUS.OK);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should handle /-/npm/v1/security/audits/bulk', async () => {
|
|
|
|
nock('https://registry.npmjs.org')
|
|
|
|
.post('/-/npm/v1/security/advisories/bulk')
|
|
|
|
.reply(200, { foo: 'someData' });
|
|
|
|
const config = { strict_ssl: false } as ConfigAudit;
|
|
|
|
const audit = new ProxyAudit(auditConfig, { logger, config: config });
|
|
|
|
const app = express();
|
|
|
|
audit.register_middlewares(app, {
|
|
|
|
// @ts-ignore
|
|
|
|
config: {
|
|
|
|
https_proxy: '',
|
|
|
|
http_proxy: '',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await supertest(app).post('/-/npm/v1/security/advisories/bulk').expect(HTTP_STATUS.OK);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should handle /-/npm/v1/security/audits', async () => {
|
|
|
|
nock('https://registry.npmjs.org')
|
|
|
|
.post('/-/npm/v1/security/audits')
|
|
|
|
.reply(200, { foo: 'someData' });
|
|
|
|
const config = { strict_ssl: false } as ConfigAudit;
|
|
|
|
const audit = new ProxyAudit(auditConfig, { logger, config: config });
|
|
|
|
const app = express();
|
|
|
|
audit.register_middlewares(app, {
|
|
|
|
// @ts-ignore
|
|
|
|
config: {
|
|
|
|
https_proxy: '',
|
|
|
|
http_proxy: '',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await supertest(app).post('/-/npm/v1/security/audits').expect(HTTP_STATUS.OK);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should handle proxy', async () => {
|
|
|
|
nock('https://registry.npmjs.org')
|
|
|
|
.post('/-/npm/v1/security/audits/quick')
|
|
|
|
.reply(200, { foo: 'someData' });
|
|
|
|
const config = { strict_ssl: false } as ConfigAudit;
|
|
|
|
const audit = new ProxyAudit(auditConfig, { logger, config: config });
|
|
|
|
const app = express();
|
|
|
|
audit.register_middlewares(app, {
|
|
|
|
// @ts-ignore
|
|
|
|
config: {
|
|
|
|
https_proxy: 'https://registry.proxy.org',
|
|
|
|
http_proxy: '',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await supertest(app).post('/-/npm/v1/security/audits/quick').expect(HTTP_STATUS.OK);
|
2020-10-23 16:12:54 -05:00
|
|
|
});
|
|
|
|
});
|