File tree Expand file tree Collapse file tree 3 files changed +16
-7
lines changed Expand file tree Collapse file tree 3 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -189,15 +189,23 @@ function MessageValidator(hostPattern, encoding) {
189189 * @param {validationCallback } cb
190190 */
191191MessageValidator . prototype . validate = function ( hash , cb ) {
192- var hostPattern = this . hostPattern ;
192+ if ( typeof hash === 'string' ) {
193+ try {
194+ hash = JSON . parse ( hash ) ;
195+ } catch ( err ) {
196+ cb ( err ) ;
197+ return ;
198+ }
199+ }
200+
193201 hash = convertLambdaMessage ( hash ) ;
194202
195203 if ( ! validateMessageStructure ( hash ) ) {
196204 cb ( new Error ( 'Message missing required keys.' ) ) ;
197205 return ;
198206 }
199207
200- if ( ! validateUrl ( hash [ 'SigningCertURL' ] , hostPattern ) ) {
208+ if ( ! validateUrl ( hash [ 'SigningCertURL' ] , this . hostPattern ) ) {
201209 cb ( new Error ( 'The certificate is located on an invalid domain.' ) ) ;
202210 return ;
203211 }
Original file line number Diff line number Diff line change 77 "url" : " https://github.com/aws/aws-js-sns-message-validator.git"
88 },
99 "main" : " index.js" ,
10- "directories" : {
11- "test" : " test"
12- },
1310 "devDependencies" : {
1411 "chai" : " ^3.3.0" ,
1512 "mocha" : " ^2.3.3" ,
1916 "underscore" : " ^1.8.3"
2017 },
2118 "scripts" : {
22- "test" : " node_modules/mocha/bin/ mocha"
19+ "test" : " mocha"
2320 },
2421 "keywords" : [
2522 " AWS" ,
Original file line number Diff line number Diff line change @@ -210,6 +210,11 @@ describe('Message Validator', function () {
210210 ( new MessageValidator ( / ^ l o c a l h o s t : 5 6 7 8 9 $ / ) )
211211 . validate ( validMessage , done ) ;
212212 } ) ;
213+
214+ it ( 'should accept valid messages as JSON strings' , function ( done ) {
215+ ( new MessageValidator ( / ^ l o c a l h o s t : 5 6 7 8 9 $ / ) )
216+ . validate ( JSON . stringify ( validMessage ) , done ) ;
217+ } ) ;
213218 } ) ;
214219
215220 describe ( 'subscription control message validation' , function ( ) {
@@ -239,7 +244,6 @@ describe('Message Validator', function () {
239244 } ) ;
240245
241246 describe ( 'UTF8 message validation' , function ( ) {
242-
243247 it ( 'should accept a valid UTF8 message' , function ( done ) {
244248 ( new MessageValidator ( / ^ l o c a l h o s t : 5 6 7 8 9 $ / , 'utf8' ) )
245249 . validate ( utf8Message , done ) ;
You can’t perform that action at this time.
0 commit comments