fix: Fixed GetBucketAcl return type, fixed staticcheck uppercase error, fixed unit tests for PutActions

This commit is contained in:
jonaustin09
2023-06-15 20:39:20 +04:00
parent 114d9fdf63
commit 3d7ce4210a
7 changed files with 35 additions and 14 deletions

View File

@@ -26,3 +26,12 @@ type Grantee struct {
Permission types.Permission
Access string
}
type GetBucketAclOutput struct {
Owner *types.Owner
AccessControlList AccessControlList
}
type AccessControlList struct {
Grants []types.Grant
}

View File

@@ -20,6 +20,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/versity/versitygw/backend/auth"
"github.com/versity/versitygw/s3err"
"github.com/versity/versitygw/s3response"
)
@@ -32,7 +33,7 @@ type Backend interface {
ListBuckets() (*s3.ListBucketsOutput, error)
HeadBucket(bucket string) (*s3.HeadBucketOutput, error)
GetBucketAcl(bucket string) (*s3.GetBucketAclOutput, error)
GetBucketAcl(bucket string) (*auth.GetBucketAclOutput, error)
PutBucket(bucket, owner string) error
PutBucketAcl(*s3.PutBucketAclInput) error
DeleteBucket(bucket string) error
@@ -90,7 +91,7 @@ func (BackendUnsupported) RestoreObject(bucket, object string, restoreRequest *s
func (BackendUnsupported) UploadPartCopy(*s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, error) {
return nil, s3err.GetAPIError(s3err.ErrNotImplemented)
}
func (BackendUnsupported) GetBucketAcl(bucket string) (*s3.GetBucketAclOutput, error) {
func (BackendUnsupported) GetBucketAcl(bucket string) (*auth.GetBucketAclOutput, error) {
return nil, s3err.GetAPIError(s3err.ErrNotImplemented)
}
func (BackendUnsupported) HeadBucket(bucket string) (*s3.HeadBucketOutput, error) {

View File

@@ -6,6 +6,7 @@ package backend
import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/versity/versitygw/backend/auth"
"github.com/versity/versitygw/s3response"
"io"
"sync"
@@ -45,7 +46,7 @@ var _ Backend = &BackendMock{}
// DeleteObjectsFunc: func(bucket string, objects *s3.DeleteObjectsInput) error {
// panic("mock out the DeleteObjects method")
// },
// GetBucketAclFunc: func(bucket string) (*s3.GetBucketAclOutput, error) {
// GetBucketAclFunc: func(bucket string) (*auth.GetBucketAclOutput, error) {
// panic("mock out the GetBucketAcl method")
// },
// GetObjectFunc: func(bucket string, object string, acceptRange string, writer io.Writer) (*s3.GetObjectOutput, error) {
@@ -146,7 +147,7 @@ type BackendMock struct {
DeleteObjectsFunc func(bucket string, objects *s3.DeleteObjectsInput) error
// GetBucketAclFunc mocks the GetBucketAcl method.
GetBucketAclFunc func(bucket string) (*s3.GetBucketAclOutput, error)
GetBucketAclFunc func(bucket string) (*auth.GetBucketAclOutput, error)
// GetObjectFunc mocks the GetObject method.
GetObjectFunc func(bucket string, object string, acceptRange string, writer io.Writer) (*s3.GetObjectOutput, error)
@@ -796,7 +797,7 @@ func (mock *BackendMock) DeleteObjectsCalls() []struct {
}
// GetBucketAcl calls GetBucketAclFunc.
func (mock *BackendMock) GetBucketAcl(bucket string) (*s3.GetBucketAclOutput, error) {
func (mock *BackendMock) GetBucketAcl(bucket string) (*auth.GetBucketAclOutput, error) {
if mock.GetBucketAclFunc == nil {
panic("BackendMock.GetBucketAclFunc: method is nil but Backend.GetBucketAcl was just called")
}

View File

@@ -21,6 +21,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/versity/versitygw/backend/auth"
"github.com/versity/versitygw/s3err"
)
@@ -120,7 +121,7 @@ func TestBackend_GetBucketAcl(t *testing.T) {
tests = append(tests, test{
name: "get bucket acl error",
c: &BackendMock{
GetBucketAclFunc: func(bucket string) (*s3.GetBucketAclOutput, error) {
GetBucketAclFunc: func(bucket string) (*auth.GetBucketAclOutput, error) {
return nil, s3err.GetAPIError(s3err.ErrNotImplemented)
},
},

View File

@@ -1156,7 +1156,7 @@ func (p *Posix) PutBucketAcl(input *s3.PutBucketAclInput) error {
return err
}
if len(accList) > 0 {
return fmt.Errorf("Accounts does not exist: %s", strings.Join(accList, ", "))
return fmt.Errorf("accounts does not exist: %s", strings.Join(accList, ", "))
}
for _, elem := range grantees {
@@ -1188,7 +1188,7 @@ func (p *Posix) PutBucketAcl(input *s3.PutBucketAclInput) error {
return nil
}
func (p *Posix) GetBucketAcl(bucket string) (*s3.GetBucketAclOutput, error) {
func (p *Posix) GetBucketAcl(bucket string) (*auth.GetBucketAclOutput, error) {
var ACL auth.ACL
acl, err := xattr.Get(bucket, "user.acl")
if err != nil {
@@ -1205,11 +1205,13 @@ func (p *Posix) GetBucketAcl(bucket string) (*s3.GetBucketAclOutput, error) {
grants = append(grants, types.Grant{Grantee: &types.Grantee{ID: &elem.Access}, Permission: elem.Permission})
}
return &s3.GetBucketAclOutput{
return &auth.GetBucketAclOutput{
Owner: &types.Owner{
ID: &ACL.Owner,
},
Grants: grants,
AccessControlList: auth.AccessControlList{
Grants: grants,
},
}, nil
}

View File

@@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/versity/versitygw/backend"
"github.com/versity/versitygw/backend/auth"
"github.com/versity/versitygw/s3response"
"io"
"sync"
@@ -46,7 +47,7 @@ var _ backend.Backend = &BackendMock{}
// DeleteObjectsFunc: func(bucket string, objects *s3.DeleteObjectsInput) error {
// panic("mock out the DeleteObjects method")
// },
// GetBucketAclFunc: func(bucket string) (*s3.GetBucketAclOutput, error) {
// GetBucketAclFunc: func(bucket string) (*auth.GetBucketAclOutput, error) {
// panic("mock out the GetBucketAcl method")
// },
// GetObjectFunc: func(bucket string, object string, acceptRange string, writer io.Writer) (*s3.GetObjectOutput, error) {
@@ -147,7 +148,7 @@ type BackendMock struct {
DeleteObjectsFunc func(bucket string, objects *s3.DeleteObjectsInput) error
// GetBucketAclFunc mocks the GetBucketAcl method.
GetBucketAclFunc func(bucket string) (*s3.GetBucketAclOutput, error)
GetBucketAclFunc func(bucket string) (*auth.GetBucketAclOutput, error)
// GetObjectFunc mocks the GetObject method.
GetObjectFunc func(bucket string, object string, acceptRange string, writer io.Writer) (*s3.GetObjectOutput, error)
@@ -797,7 +798,7 @@ func (mock *BackendMock) DeleteObjectsCalls() []struct {
}
// GetBucketAcl calls GetBucketAclFunc.
func (mock *BackendMock) GetBucketAcl(bucket string) (*s3.GetBucketAclOutput, error) {
func (mock *BackendMock) GetBucketAcl(bucket string) (*auth.GetBucketAclOutput, error) {
if mock.GetBucketAclFunc == nil {
panic("BackendMock.GetBucketAclFunc: method is nil but Backend.GetBucketAcl was just called")
}

View File

@@ -28,6 +28,7 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/valyala/fasthttp"
"github.com/versity/versitygw/backend"
"github.com/versity/versitygw/backend/auth"
"github.com/versity/versitygw/s3err"
"github.com/versity/versitygw/s3response"
)
@@ -231,7 +232,7 @@ func TestS3ApiController_ListActions(t *testing.T) {
app := fiber.New()
s3ApiController := S3ApiController{be: &BackendMock{
GetBucketAclFunc: func(bucket string) (*s3.GetBucketAclOutput, error) {
GetBucketAclFunc: func(bucket string) (*auth.GetBucketAclOutput, error) {
return nil, nil
},
ListMultipartUploadsFunc: func(output *s3.ListMultipartUploadsInput) (s3response.ListMultipartUploadsResponse, error) {
@@ -337,6 +338,11 @@ func TestS3ApiController_PutBucketActions(t *testing.T) {
return nil
},
}}
// Mock ctx.Locals
app.Use(func(ctx *fiber.Ctx) error {
ctx.Locals("access", "valid access")
return ctx.Next()
})
app.Put("/:bucket", s3ApiController.PutBucketActions)
// Error case