Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
feat: proxy npm audit request (#1419)
Browse files Browse the repository at this point in the history
add test for #1407
  • Loading branch information
alsotang authored and fengmk2 committed Jan 22, 2019
1 parent 03d7215 commit b395c66
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ coverage/
config/web_readme.md
.tmp/
*.sqlite

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"koa-maxrequests": "^1.0.0",
"koa-middlewares": "^2.1.0",
"koa-mock": "^1.6.2",
"koa-proxy": "^0.9.0",
"koa-rewrite": "^1.1.2",
"koa-rt": "^1.0.0",
"koa-safe-jsonp": "^0.3.1",
Expand Down
7 changes: 7 additions & 0 deletions servers/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ var cors = require('kcors');
var proxyToNpm = require('../middleware/proxy_to_npm');
var maxrequests = require('koa-maxrequests');

var proxy = require('koa-proxy');
app.use(proxy({
host: 'https://registry.npmjs.org',
match: /^\/\-\/npm\/v1\/security\/audits/
}));


app.use(maxrequests());
app.use(block());
middlewares.jsonp(app);
Expand Down
111 changes: 111 additions & 0 deletions test/controllers/registry/audit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
'use strict';

var should = require('should');
var request = require('supertest');
var pedding = require('pedding');
var app = require('../../../servers/registry');
var utils = require('../../utils');

describe('test/controllers/registry/audit.test.js', function () {
it('should get /-/npm/v1/security/audits', function (done) {
var reqBody = {
"name": "demo-npm",
"version": "1.0.0",
"requires": {
"minimatch": "^1.0.0",
"moment": "^2.10.5"
},
"dependencies": {
"lru-cache": {
"version": "2.7.3",
"integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI="
},
"minimatch": {
"version": "1.0.0",
"integrity": "sha1-4N0hILSeG3JM6NcUxSCCKpQ4V20=",
"requires": {
"lru-cache": "2",
"sigmund": "~1.0.0"
}
},
"moment": {
"version": "2.22.1",
"integrity": "sha512-shJkRTSebXvsVqk56I+lkb2latjBs8I+pc2TzWc545y2iFnSjm7Wg0QMh+ZWcdSLQyGEau5jI8ocnmkyTgr9YQ=="
},
"sigmund": {
"version": "1.0.1",
"integrity": "sha1-P\/IfGYytIXX587eBhT\/ZTQ0ZtZA="
}
},
"install": [

],
"remove": [

],
"metadata": {
"npm_version": "6.0.1",
"node_version": "v8.11.2",
"platform": "win32"
}
};
request(app)
.post('/-/npm/v1/security/audits')
.send(reqBody)
.expect(200, function (err, res) {
res.body.metadata.should.Object()
done();
});
})

it('should get /-/npm/v1/security/audits/quick', function (done) {
var reqBody = {
"name": "demo-npm",
"version": "1.0.0",
"requires": {
"moment": "^2.10.5",
"minimatch": "^1.0.0"
},
"dependencies": {
"lru-cache": {
"version": "2.7.3",
"integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI="
},
"minimatch": {
"version": "1.0.0",
"integrity": "sha1-4N0hILSeG3JM6NcUxSCCKpQ4V20=",
"requires": {
"lru-cache": "2",
"sigmund": "~1.0.0"
}
},
"moment": {
"version": "2.22.1",
"integrity": "sha512-shJkRTSebXvsVqk56I+lkb2latjBs8I+pc2TzWc545y2iFnSjm7Wg0QMh+ZWcdSLQyGEau5jI8ocnmkyTgr9YQ=="
},
"sigmund": {
"version": "1.0.1",
"integrity": "sha1-P\/IfGYytIXX587eBhT\/ZTQ0ZtZA="
}
},
"install": [
"[email protected]"
],
"remove": [

],
"metadata": {
"npm_version": "6.0.1",
"node_version": "v8.11.2",
"platform": "win32"
}
}
request(app)
.post('/-/npm/v1/security/audits/quick')
.send(reqBody)
.expect(200, function (err, res) {
res.body.metadata.should.Object()
done();
});
})
});

0 comments on commit b395c66

Please sign in to comment.