@@ -79,11 +79,11 @@ 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 )
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
87
88
88
// verify signature
89
89
fmt .Fprintln (w , receivedAuthorization , expectedAuthorization )
@@ -154,10 +154,14 @@ func TestHandlerValidSignatureS3cmd(t *testing.T) {
154
154
155
155
req := httptest .NewRequest (http .MethodGet , "http://foobar.example.com" , nil )
156
156
signRequest (req )
157
- authorizationReq := req .Header .Get ("Authorization" );
158
- authorizationReq = strings .Replace (authorizationReq ,", Signature" ,",Signature" ,1 )
159
- authorizationReq = strings .Replace (authorizationReq ,", SignedHeaders" ,",SignedHeaders" ,1 )
160
- req .Header .Set ("Authorization" ,authorizationReq );
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 )
161
165
resp := httptest .NewRecorder ()
162
166
h .ServeHTTP (resp , req )
163
167
assert .Equal (t , 200 , resp .Code )
0 commit comments