@@ -79,6 +79,12 @@ func verifySignature(w http.ResponseWriter, r *http.Request) {
79
79
signer .Sign (r , body , "s3" , "eu-test-1" , signTime )
80
80
expectedAuthorization := r .Header ["Authorization" ][0 ]
81
81
82
+ // WORKAROUND S3CMD who dont use white space before the comma in the authorization header
83
+ // Sanitize fakeReq to remove white spaces before the comma signature
84
+ receivedAuthorization = strings .Replace (receivedAuthorization , ",Signature" , ", Signature" , 1 )
85
+ // Sanitize fakeReq to remove white spaces before the comma signheaders
86
+ receivedAuthorization = strings .Replace (receivedAuthorization , ",SignedHeaders" , ", SignedHeaders" , 1 )
87
+
82
88
// verify signature
83
89
fmt .Fprintln (w , receivedAuthorization , expectedAuthorization )
84
90
if receivedAuthorization == expectedAuthorization {
@@ -143,6 +149,24 @@ func TestHandlerValidSignature(t *testing.T) {
143
149
assert .Equal (t , 200 , resp .Code )
144
150
assert .Contains (t , resp .Body .String (), "Hello, client" )
145
151
}
152
+ func TestHandlerValidSignatureS3cmd (t * testing.T ) {
153
+ h := newTestProxy (t )
154
+
155
+ req := httptest .NewRequest (http .MethodGet , "http://foobar.example.com" , nil )
156
+ signRequest (req )
157
+ // get the generated signed authorization header in order to simulate the s3cmd syntax
158
+ authorizationReq := req .Header .Get ("Authorization" )
159
+ // simulating s3cmd syntax and remove the whites space after the comma of the Signature part
160
+ authorizationReq = strings .Replace (authorizationReq , ", Signature" , ",Signature" , 1 )
161
+ // simulating s3cmd syntax and remove the whites space before the comma of the SignedHeaders part
162
+ authorizationReq = strings .Replace (authorizationReq , ", SignedHeaders" , ",SignedHeaders" , 1 )
163
+ // push the edited authorization header
164
+ req .Header .Set ("Authorization" , authorizationReq )
165
+ resp := httptest .NewRecorder ()
166
+ h .ServeHTTP (resp , req )
167
+ assert .Equal (t , 200 , resp .Code )
168
+ assert .Contains (t , resp .Body .String (), "Hello, client" )
169
+ }
146
170
147
171
func TestHandlerInvalidCredential (t * testing.T ) {
148
172
h := newTestProxy (t )
0 commit comments