fix: return full authorization header in unsupported authorization type error
the unsupported authorization type error only echoed the algorithm back in ArgumentValue, while s3 returns the whole Authorization header there. the parse error now carries the raw header and the s3 error mapping uses it, which also lets the bats test skipped for #1705 run again. Fixes #2489
This commit is contained in:
1 parent
1b64a938ab
commit
8271bea5c1
5 files changed
+31
-6
No files matched your search
@@ -128,7 +128,7 @@ func mapAuthParseError(err *sigv4auth.ParseError) error {
|
||||
case sigv4auth.ErrUnsupportedAuthorizationVersion:
|
||||
return s3err.GetAPIError(s3err.ErrUnsupportedAuthorizationMechanism)
|
||||
case sigv4auth.ErrInvalidAuthorizationType:
|
||||
return s3err.GetInvalidArgumentErr(s3err.InvalidArgAuthorizationType, err.Value)
|
||||
return s3err.GetInvalidArgumentErr(s3err.InvalidArgAuthorizationType, err.Input)
|
||||
case sigv4auth.ErrMissingComponents:
|
||||
return s3err.MalformedAuth.MissingComponents()
|
||||
case sigv4auth.ErrMissingCredential:
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"github.com/valyala/fasthttp"
|
||||
"github.com/valyala/fasthttp/fasthttputil"
|
||||
"github.com/versity/versitygw/internal/sigv4auth"
|
||||
"github.com/versity/versitygw/s3err"
|
||||
)
|
||||
|
||||
func TestAuthParse(t *testing.T) {
|
||||
@@ -69,6 +71,32 @@ func TestAuthParse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthParseUnsupportedType(t *testing.T) {
|
||||
vectors := []struct {
|
||||
name string
|
||||
authstr string
|
||||
}{
|
||||
{
|
||||
name: "misspelled algorithm",
|
||||
authstr: "AWS-HMAC-SHA25 Credential=user/20261007/us-east-1/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=4a2a292c73c80d2fe4a4b9e506fe0d1a8209f92dd2dfd32c27c30402e42b473d",
|
||||
},
|
||||
{
|
||||
name: "spaces between components",
|
||||
authstr: "AWS2-HMAC-SHA1 Credential=user/20261007/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-date, Signature=4a2a292c73c80d2fe4a4b9e506fe0d1a8209f92dd2dfd32c27c30402e42b473d",
|
||||
},
|
||||
}
|
||||
|
||||
for _, v := range vectors {
|
||||
t.Run(v.name, func(t *testing.T) {
|
||||
_, err := ParseAuthorization(v.authstr)
|
||||
want := s3err.GetInvalidArgumentErr(s3err.InvalidArgAuthorizationType, v.authstr)
|
||||
if !errors.Is(err, want) {
|
||||
t.Errorf("err got %v, expected %v", err, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 2024/02/06 21:03:28 Request headers:
|
||||
// 2024/02/06 21:03:28 Host: 172.21.0.160:11000
|
||||
// 2024/02/06 21:03:28 User-Agent: S3 Browser/11.5.7 (https://s3browser.com)
|
||||
|
||||
Reference in new issue
Block a user