serverless-reqvalidator-plugin
Advanced tools
| plugins: | ||
| - serverless-reqvalidator-plugin | ||
| service: my-service-b | ||
| functions: | ||
| hello: | ||
| handler: handler.myHandler | ||
| events: | ||
| - http: | ||
| path: hello | ||
| reqValidatorName: | ||
| Fn::ImportValue: 'myReqValidator' |
| plugins: | ||
| - serverless-reqvalidator-plugin | ||
| service: my-service-d | ||
| functions: | ||
| hello: | ||
| handler: handler.myHandler | ||
| events: | ||
| - http: | ||
| path: hello | ||
| reqValidatorName: | ||
| data: 123 |
| plugins: | ||
| - serverless-reqvalidator-plugin | ||
| service: my-service-a | ||
| functions: | ||
| hello: | ||
| handler: handler.myHandler | ||
| events: | ||
| - http: | ||
| path: hello | ||
| reqValidatorName: 'myReqValidator' | ||
| resources: | ||
| Resources: | ||
| xMyRequestValidator: | ||
| Type: "AWS::ApiGateway::RequestValidator" | ||
| Properties: | ||
| Name: 'my-req-validator' | ||
| RestApiId: | ||
| Ref: ApiGatewayRestApi | ||
| ValidateRequestBody: true | ||
| ValidateRequestParameters: false | ||
| Outputs: | ||
| xMyRequestValidator: | ||
| Value: | ||
| Ref: my-req-validator | ||
| Export: | ||
| Name: myReqValidator |
| plugins: | ||
| - serverless-reqvalidator-plugin | ||
| service: my-service-c | ||
| functions: | ||
| hello: | ||
| handler: handler.myHandler | ||
| events: | ||
| - http: | ||
| path: hello |
| const Ajv = require('ajv'); | ||
| const yaml = require('js-yaml'); | ||
| const fs = require('fs'); | ||
| const { ServerlessReqValidatorPluginConfigSchema } = require('../src/index'); | ||
| const ajv = new Ajv(); | ||
| const validateConfig = ajv.compile({ | ||
| type: 'object', | ||
| ...ServerlessReqValidatorPluginConfigSchema, | ||
| }); | ||
| describe('serverless-reqvalidator-plugin schema', () => { | ||
| it('should validate a configuration without reqValidatorName property', () => { | ||
| const config = yaml.load(fs.readFileSync('./test/fixtures/noValidatorFunction.yaml', 'utf8')); | ||
| const valid = validateConfig(config.functions.hello.events[0].http); | ||
| expect(valid).toBeTruthy(); | ||
| }); | ||
| it('should validate a configuration with a local reqValidatorName property', () => { | ||
| const config = yaml.load(fs.readFileSync('./test/fixtures/localValidatorFunction.yaml', 'utf8')); | ||
| const valid = validateConfig(config.functions.hello.events[0].http); | ||
| expect(valid).toBeTruthy(); | ||
| }); | ||
| it('should validate a configuration with an external reqValidatorName property', () => { | ||
| const config = yaml.load(fs.readFileSync('./test/fixtures/externalValidatorFunction.yaml', 'utf8')); | ||
| const valid = validateConfig(config.functions.hello.events[0].http); | ||
| expect(valid).toBeTruthy(); | ||
| }); | ||
| it('should not validate a configuration with an invalid reqValidatorName property', () => { | ||
| const config = yaml.load(fs.readFileSync('./test/fixtures/invalidValidatorFunction.yaml', 'utf8')); | ||
| const valid = validateConfig(config.functions.hello.events[0].http); | ||
| expect(valid).toBeFalsy(); | ||
| }); | ||
| }); |
+8
-3
| { | ||
| "name": "serverless-reqvalidator-plugin", | ||
| "version": "2.0.0", | ||
| "version": "3.0.0", | ||
| "description": "Serverless plugin for setting request validation", | ||
| "main": "src/index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| "test": "jest test" | ||
| }, | ||
@@ -26,3 +26,8 @@ "repository": { | ||
| }, | ||
| "homepage": "https://github.com/RafPe/serverless-reqvalidator-plugin#readme" | ||
| "homepage": "https://github.com/RafPe/serverless-reqvalidator-plugin#readme", | ||
| "devDependencies": { | ||
| "ajv": "^8.11.2", | ||
| "jest": "^29.3.1", | ||
| "js-yaml": "^4.1.0" | ||
| } | ||
| } |
+17
-5
@@ -36,2 +36,17 @@ 'use strict'; | ||
| const ServerlessReqValidatorPluginConfigSchema = { | ||
| properties: { | ||
| reqValidatorName: { | ||
| anyOf: [ | ||
| { type: 'string' }, | ||
| { type: 'object', | ||
| properties: { | ||
| 'Fn::ImportValue': { type: 'string' } | ||
| }, | ||
| required: ['Fn::ImportValue'], | ||
| }, | ||
| ] | ||
| }, | ||
| }, | ||
| } | ||
| class ServerlessReqValidatorPlugin { | ||
@@ -51,7 +66,3 @@ constructor(serverless, options) { | ||
| // Create schema for your properties. For reference use https://github.com/ajv-validator/ajv | ||
| serverless.configSchemaHandler.defineFunctionEventProperties('aws', 'http', { | ||
| properties: { | ||
| reqValidatorName: { type: 'string' }, | ||
| }, | ||
| }); | ||
| serverless.configSchemaHandler.defineFunctionEventProperties('aws', 'http', ServerlessReqValidatorPluginConfigSchema); | ||
@@ -118,1 +129,2 @@ this.hooks = { | ||
| module.exports = ServerlessReqValidatorPlugin; | ||
| module.exports.ServerlessReqValidatorPluginConfigSchema = ServerlessReqValidatorPluginConfigSchema; |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
12705
35.04%9
125%138
45.26%0
-100%3
Infinity%1
Infinity%