Socket
Socket
Sign inDemoInstall

middy

Package Overview
Dependencies
Maintainers
8
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middy - npm Package Compare versions

Comparing version 0.19.5 to 0.20.0

2

package.json
{
"name": "middy",
"version": "0.19.5",
"version": "0.20.0",
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda",

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

@@ -12,2 +12,3 @@ jest.mock('aws-sdk')

SSM.prototype.getParametersByPath = getParametersByPathMock
const onChange = jest.fn()

@@ -19,2 +20,4 @@ beforeEach(() => {

getParametersByPathMock.mockClear()
onChange.mockReset()
onChange.mockClear()
delete process.env.KEY_NAME

@@ -164,2 +167,27 @@ })

test(`It should call onChange handler on first run`, (done) => {
testScenario({
ssmMockResponse: {
Parameters: [{Name: '/dev/service_name/secure_param', Value: 'something-secure'}]
},
middlewareOptions: {
names: {
secureValue: '/dev/service_name/secure_param'
},
cache: true,
onChange: onChange,
setToContext: true,
paramsLoaded: false
},
callbacks: [
(_, {context}) => {
expect(onChange).toHaveBeenCalledTimes(1)
expect(context.secureValue).toEqual('something-secure')
expect(getParametersMock).toBeCalledWith({'Names': ['/dev/service_name/secure_param'], 'WithDecryption': true})
}
],
done
})
})
test(`It should call aws-sdk if cache enabled but cached param has expired`, (done) => {

@@ -195,2 +223,35 @@ testScenario({

test(`It should call onChange along with aws-sdk if cache enabled but cached param has expired`, (done) => {
testScenario({
ssmMockResponse: {
Parameters: [{Name: '/dev/service_name/secure_param', Value: 'something-secure'}]
},
middlewareOptions: {
names: {
secureValue: '/dev/service_name/secure_param'
},
cache: true,
onChange: onChange,
cacheExpiryInMillis: 10,
setToContext: true,
paramsLoaded: false
},
callbacks: [
(_, {context}) => {
expect(onChange).toHaveBeenCalledTimes(1)
expect(context.secureValue).toEqual('something-secure')
expect(getParametersMock).toBeCalledWith({'Names': ['/dev/service_name/secure_param'], 'WithDecryption': true})
getParametersMock.mockClear()
},
(_, {context}) => {
expect(onChange).toHaveBeenCalledTimes(2)
expect(context.secureValue).toEqual('something-secure')
expect(getParametersMock).toBeCalledWith({'Names': ['/dev/service_name/secure_param'], 'WithDecryption': true})
}
],
done,
delay: 20 // 20 > 10, so cache has expired
})
})
test(`It should not call aws-sdk if cache enabled and cached param has not expired`, (done) => {

@@ -197,0 +258,0 @@ testScenario({

@@ -9,2 +9,3 @@ let ssmInstance

},
onChange: undefined,
paths: {},

@@ -67,2 +68,6 @@ names: {},

})
if (typeof options.onChange === 'function') {
options.onChange()
}
options.paramsLoaded = true

@@ -69,0 +74,0 @@ options.paramsCache = objectsToMap

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