Socket
Socket
Sign inDemoInstall

express-request-checker

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.9 to 0.1.0

5

package.json
{
"name": "express-request-checker",
"version": "0.0.9",
"version": "0.1.0",
"description": "Express request checker extension.",
"main": "express-request-checker.js",
"devDependencies": {
"mocha": "2.0.1"
"mocha": "2.0.1",
"validator": "^3.28.0"
},

@@ -9,0 +10,0 @@ "scripts": {

@@ -58,2 +58,28 @@ # express-request-checker

### Play with other modules
```javascript
// router.js
var express = require('express');
var reqCheckerModule = require('express-request-checker');
var reqChecker = reqCheckerModule.requestChecker;
var router = express.Router();
var validator = require('validator');
var options = {
params: {
'email': {
assertTrue: validator.isEmail
},
'jsonData': {
assertTrue: validator.isJSON
}
}
};
router.get('/path', reqChecker(options), handlerFunction);
module.exports = router;
```
### Checker Options Default Values

@@ -60,0 +86,0 @@

51

test/test.js

@@ -21,5 +21,2 @@ var assert = require('assert');

/************/
/* v0.0.6 */
/************/
it('1-1 scope: default, strict: default -> No params required, Got 1 param', function() {

@@ -183,5 +180,2 @@ options = { params: null };

/************/
/* v0.0.7 */
/************/
it('A-1 scope: default, strict: default -> 1 param required(assertTrue), Got 1 valid param', function() {

@@ -504,3 +498,2 @@ options = { params: {

it('J-4 scope: default, strict: default -> 1 param required(allowEmpty:false), Got 1 non-empty param', function() {

@@ -555,2 +548,46 @@ options = { params: {

});
/****************************/
/* Play with other packages */
/****************************/
var validator = require('validator');
it('CO-1 scope: default, strict: default -> 1 param required(play with `validator`), Got 1 valid param', function() {
options = { params: {
param1: { assertTrue: validator.isEmail}
} };
fakeReq = { query: {
param1: "foo@bar.com"
} };
assert.notEqual(false, reqChecker(options)(fakeReq, fakeRes, fakeNext));
});
it('CO-2 scope: default, strict: default -> 1 param required(play with `validator`), Got 1 invalid param', function() {
options = { params: {
param1: { assertTrue: validator.isEmail}
} };
fakeReq = { query: {
param1: "foo@.com"
} };
assert.equal(false, reqChecker(options)(fakeReq, fakeRes, fakeNext));
});
it('CO-3 scope: default, strict: default -> 1 param required(play with `validator`), Got 1 valid param', function() {
options = { params: {
param1: { assertTrue: validator.isJSON}
} };
fakeReq = { query: {
param1: '{"foo":1, "bar":2}'
} };
assert.notEqual(false, reqChecker(options)(fakeReq, fakeRes, fakeNext));
});
it('CO-4 scope: default, strict: default -> 1 param required(play with `validator`), Got 1 invalid param', function() {
options = { params: {
param1: { assertTrue: validator.isJSON}
} };
fakeReq = { query: {
param1: '{"foo":1 "bar":2}'
} };
assert.equal(false, reqChecker(options)(fakeReq, fakeRes, fakeNext));
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc