Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add ability to pass NoEcho to response object #47

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ exports.handler = CfnLambda({
NoUpdate: NoUpdate, // Optional
TriggersReplacement: TriggersReplacement, // Array<String> of properties forcing Replacement

LongRunning: <see Long Running below> // Optional. Configure a lambda to last beyond 5 minutes.
NoEcho: true, // Optional, default is false. Masks the 'Data' Response property. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html for more information.

LongRunning: <see Long Running below> // Optional. Configure a lambda to last beyond 5 minutes.
});
```

Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ function CfnLambdaFactory(resourceDefinition) {
StackId: event.StackId,
RequestId: event.RequestId,
LogicalResourceId: event.LogicalResourceId,
Data: optionalData
Data: optionalData,
NoEcho: resourceDefinition.NoEcho || false
});
}
return functor({
Expand All @@ -270,7 +271,8 @@ function CfnLambdaFactory(resourceDefinition) {
StackId: event.StackId,
RequestId: event.RequestId,
LogicalResourceId: event.LogicalResourceId,
Data: optionalData || OldParams
Data: optionalData || OldParams,
NoEcho: resourceDefinition.NoEcho || false
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions test-helpers/https/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ module.exports = {
callback();
}
return this;
},
close: function() {
server.close();
this.listening = false;
}
};
5 changes: 5 additions & 0 deletions test/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ var ContextStub = require(path.resolve(__dirname, '..', 'test-helpers', 'context
var CfnLambda = require(path.resolve(__dirname, '..', 'index'));

describe('Async support', function() {

after(() => {
Server.close();
});

var expectedUrl = '/foo/bar/taco';
var expectedStackId = 'fakeStackId';
var expectedRequestId = 'fakeRequestId';
Expand Down
38 changes: 38 additions & 0 deletions test/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ var CfnLambda = require(path.resolve(__dirname, '..', 'index'));


describe('Create', function() {

after(() => {
Server.close();
});

var expectedUrl = '/foo/bar/taco';
var expectedStackId = 'fakeStackId';
var expectedRequestId = 'fakeRequestId';
Expand Down Expand Up @@ -206,4 +211,37 @@ describe('Create', function() {
});

});

it('Should default NoEcho to false', function(done) {
var CfnRequest = HollowRequest();
var Lambda = CfnLambda({
Create: function(Params, reply) {
reply();
}
});

Server.on(function() {
Lambda(CfnRequest, ContextStub);
}, function(cfnResponse) {
assert(false === cfnResponse.body.NoEcho, 'Expected NoEcho to be false');
done();
});
});

it('Should set NoEcho to true', function(done) {
var CfnRequest = HollowRequest();
var Lambda = CfnLambda({
Create: function(Params, reply) {
reply();
},
NoEcho: true
});

Server.on(function() {
Lambda(CfnRequest, ContextStub);
}, function(cfnResponse) {
assert(true === cfnResponse.body.NoEcho, 'Expected NoEcho to be true');
done();
});
});
});
38 changes: 38 additions & 0 deletions test/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ var CfnLambda = require(path.resolve(__dirname, '..', 'index'));


describe('Delete', function() {

after(() => {
Server.close();
});

var expectedUrl = '/foo/bar/taco';
var expectedStackId = 'fakeStackId';
var expectedRequestId = 'fakeRequestId';
Expand Down Expand Up @@ -153,4 +158,37 @@ describe('Delete', function() {
});

});

it('Should default NoEcho to false', function(done) {
var CfnRequest = HollowRequest();
var Lambda = CfnLambda({
Delete: function(PhysicalId, Params, reply) {
reply();
}
});

Server.on(function() {
Lambda(CfnRequest, ContextStub);
}, function(cfnResponse) {
assert(false === cfnResponse.body.NoEcho, 'Expected NoEcho to be false');
done();
});
});

it('Should set NoEcho to true', function(done) {
var CfnRequest = HollowRequest();
var Lambda = CfnLambda({
Delete: function(PhysicalId, Params, reply) {
reply();
},
NoEcho: true
});

Server.on(function() {
Lambda(CfnRequest, ContextStub);
}, function(cfnResponse) {
assert(true === cfnResponse.body.NoEcho, 'Expected NoEcho to be true');
done();
});
});
});
5 changes: 5 additions & 0 deletions test/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ var CfnLambda = require(path.resolve(__dirname, '..', 'index'));


describe('CfnLambda#Environment', function() {

after(() => {
Server.close();
});

function HollowRequest() {
return {
RequestType: 'Create',
Expand Down
5 changes: 5 additions & 0 deletions test/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ var CfnLambda = require(path.resolve(__dirname, '..', 'index'));


describe('Severe CloudFormation Errors', function() {

after(() => {
Server.close();
});

it('should still terminate lambda on signed url connection errors', function(done) {
var expectedUrl = '/foo/bar/taco';
var expectedStackId = 'fakeStackId';
Expand Down
5 changes: 5 additions & 0 deletions test/longRunning.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ var CfnLambda = require(path.resolve(__dirname, '..', 'index'));


describe('LongRunning', function() {

after(() => {
Server.close();
});

var expectedUrl = '/foo/bar/taco';
var expectedStackId = 'fakeStackId';
var expectedRequestId = 'fakeRequestId';
Expand Down
40 changes: 39 additions & 1 deletion test/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ var CfnLambda = require(path.resolve(__dirname, '..', 'index'));


describe('Update', function() {

after(() => {
Server.close();
});

var expectedUrl = '/foo/bar/taco';
var expectedStackId = 'fakeStackId';
var expectedRequestId = 'fakeRequestId';
Expand Down Expand Up @@ -318,4 +323,37 @@ describe('Update', function() {
});

});
});

it('Should default NoEcho to false', function(done) {
var CfnRequest = HollowRequest();
var Lambda = CfnLambda({
Update: function(PhysicalId, Params, OldParams, reply) {
reply();
}
});

Server.on(function() {
Lambda(CfnRequest, ContextStub);
}, function(cfnResponse) {
assert(false === cfnResponse.body.NoEcho, 'Expected NoEcho to be false');
done();
});
});

it('Should set NoEcho to true', function(done) {
var CfnRequest = HollowRequest();
var Lambda = CfnLambda({
Update: function(PhysicalId, Params, OldParams, reply) {
reply();
},
NoEcho: true
});

Server.on(function() {
Lambda(CfnRequest, ContextStub);
}, function(cfnResponse) {
assert(true === cfnResponse.body.NoEcho, 'Expected NoEcho to be true');
done();
});
});
});