forked from TrueCloudLab/frostfs-s3-gw
[#456] auth: Fix authentication for POST Object
During post object operation field AuthHeader in middleware.Box wasn't set that led to panic Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
3dc989d7fe
commit
4f27e34974
2 changed files with 14 additions and 3 deletions
|
@ -270,7 +270,9 @@ func (c *Center) checkFormData(r *http.Request) (*middleware.Box, error) {
|
||||||
return nil, fmt.Errorf("failed to parse x-amz-date field: %w", err)
|
return nil, fmt.Errorf("failed to parse x-amz-date field: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := getAddress(submatches["access_key_id"])
|
accessKeyID := submatches["access_key_id"]
|
||||||
|
|
||||||
|
addr, err := getAddress(accessKeyID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -290,7 +292,15 @@ func (c *Center) checkFormData(r *http.Request) (*middleware.Box, error) {
|
||||||
reqSignature, signature)
|
reqSignature, signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &middleware.Box{AccessBox: box, Attributes: attrs}, nil
|
return &middleware.Box{
|
||||||
|
AccessBox: box,
|
||||||
|
AuthHeaders: &middleware.AuthHeader{
|
||||||
|
AccessKeyID: accessKeyID,
|
||||||
|
Region: region,
|
||||||
|
SignatureV4: signature,
|
||||||
|
},
|
||||||
|
Attributes: attrs,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneRequest(r *http.Request, authHeader *AuthHeader) *http.Request {
|
func cloneRequest(r *http.Request, authHeader *AuthHeader) *http.Request {
|
||||||
|
|
|
@ -434,7 +434,7 @@ func TestAuthenticate(t *testing.T) {
|
||||||
|
|
||||||
func TestHTTPPostAuthenticate(t *testing.T) {
|
func TestHTTPPostAuthenticate(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
policyBase64 = "eyAiZXhwaXJhdGlvbiI6ICIyMDA3LTEyLTAxVDEyOjAwOjAwLjAwMFoiLAogICJjb25kaXRpb25zIjogWwogICAgeyJhY2wiOiAicHVibGljLXJlYWQiIH0sCiAgICB7ImJ1Y2tldCI6ICJqb2huc21pdGgiIH0sCiAgICBbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAidXNlci9lcmljLyJdLAogIF0KfQ=="
|
policyBase64 = "eyJleHBpcmF0aW9uIjogIjIwMjUtMTItMDFUMTI6MDA6MDAuMDAwWiIsImNvbmRpdGlvbnMiOiBbCiBbInN0YXJ0cy13aXRoIiwgIiR4LWFtei1jcmVkZW50aWFsIiwgIiJdLAogWyJzdGFydHMtd2l0aCIsICIkeC1hbXotZGF0ZSIsICIiXQpdfQ=="
|
||||||
invalidValue = "invalid-value"
|
invalidValue = "invalid-value"
|
||||||
defaultFieldName = "file"
|
defaultFieldName = "file"
|
||||||
service = "s3"
|
service = "s3"
|
||||||
|
@ -602,6 +602,7 @@ func TestHTTPPostAuthenticate(t *testing.T) {
|
||||||
} else {
|
} else {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, secret.SecretKey, box.AccessBox.Gate.SecretKey)
|
require.Equal(t, secret.SecretKey, box.AccessBox.Gate.SecretKey)
|
||||||
|
require.Equal(t, accessKeyID, box.AuthHeaders.AccessKeyID)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue