Skip to content

Commit e06d354

Browse files
committed
Replace Lambda-specific handling with a Lambda -> HTTP-style message converter
1 parent 981c1e4 commit e06d354

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ language: node_js
22
node_js:
33
- "0.10"
44
- "0.12"
5-
- "4.0"
6-
- "4.1"
75
- "4.2"
8-
- "4.3"
96
- "4.4"
10-
- "6.0"
11-
- "6.1"
7+
- "5"
8+
- "6"
9+
- "7"
10+
- "8"
1211

1312
script:
1413
- npm test

index.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,15 @@ var url = require('url'),
3939
'Token',
4040
'TopicArn',
4141
'Type'
42-
];
43-
44-
var hashHasKey = function (hash, key) {
45-
if (!(key in hash)) {
46-
if (/URL$/.test(key) && key.replace(/URL$/, 'Url') in hash) {
47-
return true;
48-
}
49-
return false;
50-
}
51-
return true;
52-
};
42+
],
43+
lambdaMessageKeys = {
44+
'SigningCertUrl': 'SigningCertURL',
45+
'UnsubscribeUrl': 'UnsubscribeURL'
46+
};
5347

5448
var hashHasKeys = function (hash, keys) {
5549
for (var i = 0; i < keys.length; i++) {
56-
if (!hashHasKey(hash, keys[i])) {
50+
if (!(keys[i] in hash)) {
5751
return false;
5852
}
5953
}
@@ -71,6 +65,16 @@ var indexOf = function (array, value) {
7165
return -1;
7266
};
7367

68+
function convertLambdaMessage(message) {
69+
for (var key in lambdaMessageKeys) {
70+
if (key in message) {
71+
message[lambdaMessageKeys[key]] = message[key];
72+
}
73+
}
74+
75+
return message;
76+
}
77+
7478
var validateMessageStructure = function (message) {
7579
var valid = hashHasKeys(message, requiredKeys);
7680

@@ -182,13 +186,14 @@ function MessageValidator(hostPattern, encoding) {
182186
*/
183187
MessageValidator.prototype.validate = function (hash, cb) {
184188
var hostPattern = this.hostPattern;
189+
hash = convertLambdaMessage(hash);
185190

186191
if (!validateMessageStructure(hash)) {
187192
cb(new Error('Message missing required keys.'));
188193
return;
189194
}
190195

191-
if (!validateUrl(hash['SigningCertURL'] || hash['SigningCertUrl'], hostPattern)) {
196+
if (!validateUrl(hash['SigningCertURL'], hostPattern)) {
192197
cb(new Error('The certificate is located on an invalid domain.'));
193198
return;
194199
}

0 commit comments

Comments
 (0)