@@ -24,6 +24,20 @@ var chai = require('chai'),
2424 SubscribeURL : 'https://www.amazonaws.com' ,
2525 Type : 'SubscriptionConfirmation'
2626 } ) ,
27+ utf8Message = {
28+ Type : 'Notification' ,
29+ MessageId : '1' ,
30+ TopicArn : 'arn' ,
31+ Message : 'A Message For you!' ,
32+ Timestamp : ( new Date ) . toISOString ( ) ,
33+ SignatureVersion : '1' ,
34+ SigningCertURL : "https://localhost:56789/cert.pem"
35+ } ,
36+ utf8SubscriptionControlMessage = _ . extend ( { } , utf8Message , {
37+ Token : 'Nonce' ,
38+ SubscribeURL : 'https://www.amazonaws.com' ,
39+ Type : 'SubscriptionConfirmation'
40+ } ) ,
2741 validCertUrl = 'https://sns.us-east-1.amazonaws.com/cert.pem' ;
2842
2943describe ( 'Message Validator' , function ( ) {
@@ -182,4 +196,40 @@ describe('Message Validator', function () {
182196 . validate ( validSubscriptionControlMessage , done ) ;
183197 } ) ;
184198 } ) ;
199+
200+ describe ( 'UTF8 message validation' , function ( ) {
201+ before ( function ( done ) {
202+ pem . createCertificate ( { } , function ( err , certHash ) {
203+ if ( err ) throw err ;
204+
205+ var crypto = require ( 'crypto' ) ,
206+ validMessages = [ utf8Message , utf8SubscriptionControlMessage ] ;
207+
208+ for ( var i = 0 ; i < validMessages . length ; i ++ ) {
209+ var signer = crypto . createSign ( 'RSA-SHA1' ) ;
210+
211+ for ( var j = 0 ; j < signableKeys . length ; j ++ ) {
212+ if ( signableKeys [ j ] in validMessages [ i ] ) {
213+ signer . update ( signableKeys [ j ] + "\n"
214+ + validMessages [ i ] [ signableKeys [ j ] ] + "\n" , 'utf8' ) ;
215+ }
216+ }
217+
218+ validMessages [ i ] [ 'Signature' ]
219+ = signer . sign ( certHash . serviceKey , 'base64' ) ;
220+ }
221+
222+ MessageValidator . __set__ ( 'getCertificate' , function ( url , cb ) {
223+ cb ( null , certHash . certificate ) ;
224+ } ) ;
225+
226+ done ( ) ;
227+ } ) ;
228+ } ) ;
229+
230+ it ( 'should accept a valid UTF8 message' , function ( done ) {
231+ ( new MessageValidator ( / ^ l o c a l h o s t : 5 6 7 8 9 $ / , 'utf8' ) )
232+ . validate ( utf8Message , done ) ;
233+ } ) ;
234+ } ) ;
185235} ) ;
0 commit comments