@@ -27,10 +27,33 @@ public function testSign()
2727
2828 $ expectedHeaders = [
2929 'header ' => 'baz ' ,
30- 'host ' => 'localhost:1234 ' ,
31- 'x-amz-security-token ' => 'token ' ,
32- 'x-amz-date ' => '20200101T000000Z ' ,
33- 'authorization ' => 'AWS4-HMAC-SHA256 Credential=key/20200101/eu-west-1/sqs/aws4_request, SignedHeaders=header;host;x-amz-date;x-amz-security-token, Signature=87e3d70ecfaf7655c24284198c90c61da166aea5bbe2eb3fe470634369acb108 ' ,
30+ 'Host ' => 'localhost:1234 ' ,
31+ 'X-Amz-Security-Token ' => 'token ' ,
32+ 'X-Amz-Date ' => '20200101T000000Z ' ,
33+ 'Authorization ' => 'AWS4-HMAC-SHA256 Credential=key/20200101/eu-west-1/sqs/aws4_request, SignedHeaders=header;host;x-amz-date;x-amz-security-token, Signature=87e3d70ecfaf7655c24284198c90c61da166aea5bbe2eb3fe470634369acb108 ' ,
34+ ];
35+
36+ self ::assertEqualsCanonicalizing ($ expectedHeaders , $ request ->getHeaders ());
37+ }
38+
39+ public function testSignWithCustomMetadata ()
40+ {
41+ $ signer = new SignerV4 ('sqs ' , 'eu-west-1 ' );
42+
43+ $ request = new Request ('POST ' , '/foo ' , ['arg ' => 'bar ' ], ['header ' => 'baz ' , 'x-amz-meta-foo ' => 'qux ' ], StringStream::create ('body ' ));
44+ $ request ->setEndpoint ('http://localhost:1234/foo?arg=bar ' );
45+ $ context = new RequestContext (['currentDate ' => new \DateTimeImmutable ('2020-01-01T00:00:00Z ' )]);
46+ $ credentials = new Credentials ('key ' , 'secret ' , 'token ' );
47+
48+ $ signer ->sign ($ request , $ credentials , $ context );
49+
50+ $ expectedHeaders = [
51+ 'header ' => 'baz ' ,
52+ 'x-amz-meta-foo ' => 'qux ' ,
53+ 'Host ' => 'localhost:1234 ' ,
54+ 'X-Amz-Security-Token ' => 'token ' ,
55+ 'X-Amz-Date ' => '20200101T000000Z ' ,
56+ 'Authorization ' => 'AWS4-HMAC-SHA256 Credential=key/20200101/eu-west-1/sqs/aws4_request, SignedHeaders=header;host;x-amz-date;x-amz-meta-foo;x-amz-security-token, Signature=ca51c7ab9267efedb93598add21a9bd8e354471c7cbfdccbb5309b6da1fcc74a ' ,
3457 ];
3558
3659 self ::assertEqualsCanonicalizing ($ expectedHeaders , $ request ->getHeaders ());
@@ -61,6 +84,32 @@ public function testPresign()
6184 self ::assertEqualsCanonicalizing ($ expectedQuery , $ request ->getQuery ());
6285 }
6386
87+ public function testPresignWithCustomMetadata ()
88+ {
89+ $ signer = new SignerV4 ('sqs ' , 'eu-west-1 ' );
90+
91+ $ request = new Request ('POST ' , '/foo ' , ['arg ' => 'bar ' ], ['header ' => 'baz ' , 'x-amz-meta-foo ' => 'qux ' ], StringStream::create ('body ' ));
92+ $ request ->setEndpoint ('http://localhost:1234/foo?arg=bar ' );
93+ $ context = new RequestContext (['currentDate ' => new \DateTimeImmutable ('2020-01-01T00:00:00Z ' )]);
94+ $ credentials = new Credentials ('key ' , 'secret ' , 'token ' );
95+
96+ $ signer ->presign ($ request , $ credentials , $ context );
97+
98+ $ expectedQuery = [
99+ 'arg ' => 'bar ' ,
100+ 'X-Amz-Algorithm ' => 'AWS4-HMAC-SHA256 ' ,
101+ 'X-Amz-Security-Token ' => 'token ' ,
102+ 'X-Amz-Date ' => '20200101T000000Z ' ,
103+ 'X-Amz-Expires ' => '3600 ' ,
104+ 'X-Amz-Credential ' => 'key/20200101/eu-west-1/sqs/aws4_request ' ,
105+ 'x-amz-meta-foo ' => 'qux ' ,
106+ 'X-Amz-SignedHeaders ' => 'header;host;x-amz-meta-foo ' ,
107+ 'X-Amz-Signature ' => '03af97bd38e7310c6335aedce2f588fe3714240bcc390c253b8346f1380df909 ' ,
108+ ];
109+
110+ self ::assertEqualsCanonicalizing ($ expectedQuery , $ request ->getQuery ());
111+ }
112+
64113 #[DataProvider('provideRequests ' )]
65114 public function testSignsRequests ($ rawRequest , $ rawExpected )
66115 {
@@ -134,7 +183,7 @@ public static function provideRequests()
134183 // DateHeader should be kept
135184 [
136185 "POST / HTTP/1.1 \r\nHost: host.foo.com:443 \r\nx-AMZ-date: 20110909T233600Z \r\nExpires: Thu, 21 May 20 20:54:15 +0200 \r\n\r\n" ,
137- "POST / HTTP/1.1 \r\nHost: host.foo.com:443 \r\n expires :Thu, 21 May 20 20:54:15 +0200 \r\nX-Amz-Date: 20110909T233600Z \r\nAuthorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=expires;host;x-amz-date, Signature=7090e12acc44281b2b46ba195ee1ae09f2e8c81653fcd592abbfbc30e1a5acc6 \r\n\r\n" ,
186+ "POST / HTTP/1.1 \r\nHost: host.foo.com:443 \r\n Expires :Thu, 21 May 20 20:54:15 +0200 \r\nX-Amz-Date: 20110909T233600Z \r\nAuthorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/host/aws4_request, SignedHeaders=expires;host;x-amz-date, Signature=7090e12acc44281b2b46ba195ee1ae09f2e8c81653fcd592abbfbc30e1a5acc6 \r\n\r\n" ,
138187 ],
139188 ];
140189 }
0 commit comments