@@ -81,7 +81,7 @@ function testAmzDatetime() {
8181 }
8282}
8383
84- function testBuildSigningKeyHash ( ) {
84+ function testBuildSigningKeyHashWithReferenceInputs ( ) {
8585 var kSecret = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY' ;
8686 var date = '20150830' ;
8787 var service = 'iam' ;
@@ -96,6 +96,43 @@ function testBuildSigningKeyHash() {
9696 }
9797}
9898
99+ function testBuildSigningKeyHashWithTestSuiteInputs ( ) {
100+ var kSecret = 'pvgoBEA1z7zZKqN9RoKVksKh31AtNou+pspn+iyb' ;
101+ var date = '20200811' ;
102+ var service = 's3' ;
103+ var region = 'us-west-2' ;
104+ var expected = 'a48701bfe803103e89051f55af2297dd76783bbceb5eb416dab71e0eadcbc4f6' ;
105+ var signingKeyHash = s3gateway . _buildSigningKeyHash ( kSecret , date , service , region ) . toString ( 'hex' ) ;
106+
107+ if ( signingKeyHash !== expected ) {
108+ throw 'Signing key hash was not created correctly.\n' +
109+ 'Actual: [' + signingKeyHash + ']\n' +
110+ 'Expected: [' + expected + ']' ;
111+ }
112+ }
113+
114+ function _runSignatureV4 ( r ) {
115+ r . log = function ( msg ) {
116+ console . log ( msg ) ;
117+ }
118+ var timestamp = new Date ( '2020-08-11T19:42:14Z' ) ;
119+ var eightDigitDate = s3gateway . _eightDigitDate ( timestamp ) ;
120+ var amzDatetime = s3gateway . _amzDatetime ( timestamp , eightDigitDate ) ;
121+ var bucket = 'ez-test-bucket-1'
122+ var secret = 'pvgoBEA1z7zZKqN9RoKVksKh31AtNou+pspn+iyb'
123+ var region = 'us-west-2' ;
124+ var server = 's3-us-west-2.amazonaws.com' ;
125+
126+ var expected = 'cf4dd9e1d28c74e2284f938011efc8230d0c20704f56f67e4a3bfc2212026bec' ;
127+ var signature = s3gateway . _buildSignatureV4 ( r , amzDatetime , eightDigitDate , bucket , secret , region , server ) ;
128+
129+ if ( signature !== expected ) {
130+ throw 'V4 signature hash was not created correctly.\n' +
131+ 'Actual: [' + signature + ']\n' +
132+ 'Expected: [' + expected + ']' ;
133+ }
134+ }
135+
99136function testSignatureV4 ( ) {
100137 // Note: since this is a read-only gateway, host, query parameters and all
101138 // client headers will be ignored.
@@ -122,33 +159,55 @@ function testSignatureV4() {
122159 "status" : 0
123160 } ;
124161
125- r . log = function ( msg ) {
126- console . log ( msg ) ;
127- }
128- var timestamp = new Date ( '2020-08-11T19:42:14Z' ) ;
129- var eightDigitDate = s3gateway . _eightDigitDate ( timestamp ) ;
130- var amzDatetime = s3gateway . _amzDatetime ( timestamp , eightDigitDate ) ;
131- var bucket = 'ez-test-bucket-1'
132- var secret = 'pvgoBEA1z7zZKqN9RoKVksKh31AtNou+pspn+iyb'
133- var region = 'us-west-2' ;
134- var server = 's3-us-west-2.amazonaws.com' ;
162+ _runSignatureV4 ( r ) ;
163+ }
135164
136- var expected = 'cf4dd9e1d28c74e2284f938011efc8230d0c20704f56f67e4a3bfc2212026bec' ;
137- var signature = s3gateway . _buildSignatureV4 ( r , amzDatetime , eightDigitDate , bucket , secret , region , server ) ;
165+ function testSignatureV4Cache ( ) {
166+ // Note: since this is a read-only gateway, host, query parameters and all
167+ // client headers will be ignored.
168+ var r = {
169+ "remoteAddress" : "172.17.0.1" ,
170+ "headersIn" : {
171+ "Connection" : "keep-alive" ,
172+ "Accept-Encoding" : "gzip, deflate" ,
173+ "Accept-Language" : "en-US,en;q=0.7,ja;q=0.3" ,
174+ "Host" : "localhost:8999" ,
175+ "User-Agent" : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0" ,
176+ "DNT" : "1" ,
177+ "Cache-Control" : "max-age=0" ,
178+ "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" ,
179+ "Upgrade-Insecure-Requests" : "1"
180+ } ,
181+ "uri" : "/a/c/ramen.jpg" ,
182+ "method" : "GET" ,
183+ "httpVersion" : "1.1" ,
184+ "headersOut" : { } ,
185+ "args" : {
186+ "foo" : "bar"
187+ } ,
188+ "variables" : {
189+ "cache_signing_key_enabled" : 1
190+ } ,
191+ "status" : 0
192+ } ;
138193
139- if ( signature !== expected ) {
140- throw 'V4 signature hash was not created correctly.\n' +
141- 'Actual: [' + signature + ']\n' +
142- 'Expected: [' + expected + ']' ;
194+ _runSignatureV4 ( r ) ;
195+
196+ if ( ! "signing_key_hash" in r . variables ) {
197+ throw "Hash key not written to r.variables.signing_key_hash" ;
143198 }
199+
200+ _runSignatureV4 ( r ) ;
144201}
145202
146203function test ( ) {
147204 testPad ( ) ;
148205 testEightDigitDate ( ) ;
149206 testAmzDatetime ( ) ;
150- testBuildSigningKeyHash ( ) ;
207+ testBuildSigningKeyHashWithReferenceInputs ( ) ;
208+ testBuildSigningKeyHashWithTestSuiteInputs ( ) ;
151209 testSignatureV4 ( ) ;
210+ testSignatureV4Cache ( ) ;
152211}
153212
154213test ( ) ;
0 commit comments