@@ -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 ( / U R L $ / . test ( key ) && key . replace ( / U R L $ / , '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
5448var 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+
7478var validateMessageStructure = function ( message ) {
7579 var valid = hashHasKeys ( message , requiredKeys ) ;
7680
@@ -182,13 +186,14 @@ function MessageValidator(hostPattern, encoding) {
182186 */
183187MessageValidator . 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