Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

body-checker

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

body-checker - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

85

__tests__/test.js

@@ -11,3 +11,3 @@ jest

var body = {
var reqBody = {
name: 'Randy',

@@ -17,3 +17,3 @@ rogue: 'DROP users'

check(body, {
check(reqBody, {
name: {

@@ -35,2 +35,59 @@ type: 'string',

describe('undefined params', function() {
var check = require('body-checker');
it('Should not return undefined key values when leys are missing', function() {
var reqBody = {
name: "Randy"
};
var strongParams = { name: { type: 'string', required: true},
address: { type: 'string', required: false}};
check(reqBody, strongParams, function(err, body) {
expect(err).toBeNull();
expect(body).toBeDefined();
expect(Object.keys(body).length).toEqual(1);
});
});
it('Should handle empty object when strong params without keys', function() {
var reqBody = {};
var strongParams = {};
check(reqBody, strongParams, function(err, body) {
expect(err).toBeNull();
expect(body).toBeDefined();
expect(Object.keys(body).length).toEqual(0);
});
});
it('Should handle bad object as strong params without keys', function() {
var reqBody = { test: 'should fail'};
var strongParams = {};
check(reqBody, strongParams, function(err, body) {
expect(err).toBeDefined();
expect(err.message).toEqual('Illegal parameter "test" provided');
expect(body).toBeUndefined();
});
});
});
describe('required parameters', function() {

@@ -42,3 +99,3 @@

var body = {
var reqBody = {
name: 'Randy',

@@ -48,3 +105,3 @@ email: ''

check(body, {
check(reqBody, {
name: {

@@ -70,7 +127,7 @@ type: 'string',

var body = {
var reqBody = {
name: 'Randy'
};
check(body, {
check(reqBody, {
name: {

@@ -101,3 +158,3 @@ type: 'string',

var body = {
var reqBody = {
name: 'Randy',

@@ -107,3 +164,3 @@ email: ''

check(body, {
check(reqBody, {
name: {

@@ -136,3 +193,3 @@ type: 'string',

var body = {
var reqBody = {
name: 'Randy',

@@ -142,3 +199,3 @@ id: '1'

check(body, {
check(reqBody, {
name: {

@@ -170,3 +227,3 @@ type: 'string',

var body = {
var reqBody = {
name: 'Randy',

@@ -177,3 +234,3 @@ email: '',

check(body, {
check(reqBody, {
name: {

@@ -211,3 +268,3 @@ type: 'string',

var body = {
var reqBody = {
name: 'Randy',

@@ -220,3 +277,3 @@ id: 1,

check(body, {
check(reqBody, {
name: {

@@ -223,0 +280,0 @@ type: 'string',

3

index.js

@@ -15,3 +15,2 @@ /**

var valid_keys = Object.keys(options);

@@ -34,3 +33,3 @@

// Optional default handler
if(!options[key].required && !body[key]) {
if(!options[key].required && !body[key] && options[key].default) {
body[key] = options[key].default;

@@ -37,0 +36,0 @@ }

{
"name": "body-checker",
"version": "0.1.4",
"version": "0.1.5",
"description": "A simple tool to protect your API against bad request parameters",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc