2023-07-19 14:18:55 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2024-04-10 06:41:07 +00:00
|
|
|
"encoding/xml"
|
2024-05-16 05:16:27 +00:00
|
|
|
"fmt"
|
2024-04-10 06:41:07 +00:00
|
|
|
"io"
|
2023-07-19 14:18:55 +00:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
2024-04-10 06:41:07 +00:00
|
|
|
apiErrors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
2023-07-19 14:18:55 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
2024-02-26 13:18:34 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/accessbox"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
|
|
|
bearertest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer/test"
|
2024-03-01 14:07:08 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2024-04-16 08:20:35 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2024-02-26 13:18:34 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2023-07-19 14:18:55 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-11-30 08:25:05 +00:00
|
|
|
const FrostfsNamespaceHeader = "X-Frostfs-Namespace"
|
|
|
|
|
2024-02-26 13:18:34 +00:00
|
|
|
type poolStatisticMock struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *poolStatisticMock) Statistic() pool.Statistic {
|
|
|
|
return pool.Statistic{}
|
|
|
|
}
|
|
|
|
|
2023-07-19 14:18:55 +00:00
|
|
|
type centerMock struct {
|
2024-05-16 05:16:27 +00:00
|
|
|
t *testing.T
|
|
|
|
anon bool
|
|
|
|
noAuthHeader bool
|
|
|
|
isError bool
|
|
|
|
attrs []object.Attribute
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
2023-10-05 08:05:21 +00:00
|
|
|
func (c *centerMock) Authenticate(*http.Request) (*middleware.Box, error) {
|
2024-05-16 05:16:27 +00:00
|
|
|
if c.noAuthHeader {
|
|
|
|
return nil, middleware.ErrNoAuthorizationHeader
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.isError {
|
|
|
|
return nil, fmt.Errorf("some error")
|
|
|
|
}
|
|
|
|
|
2024-02-26 13:18:34 +00:00
|
|
|
var token *bearer.Token
|
|
|
|
|
|
|
|
if !c.anon {
|
|
|
|
bt := bearertest.Token()
|
|
|
|
token = &bt
|
|
|
|
key, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(c.t, err)
|
|
|
|
require.NoError(c.t, token.Sign(key.PrivateKey))
|
|
|
|
}
|
|
|
|
|
|
|
|
return &middleware.Box{
|
2024-02-21 14:41:57 +00:00
|
|
|
AuthHeaders: &middleware.AuthHeader{},
|
2024-02-26 13:18:34 +00:00
|
|
|
AccessBox: &accessbox.Box{
|
|
|
|
Gate: &accessbox.GateData{
|
|
|
|
BearerToken: token,
|
|
|
|
},
|
|
|
|
},
|
2024-04-16 08:20:35 +00:00
|
|
|
Attributes: c.attrs,
|
2024-02-26 13:18:34 +00:00
|
|
|
}, nil
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
2023-12-05 12:49:13 +00:00
|
|
|
type middlewareSettingsMock struct {
|
2024-07-31 06:45:46 +00:00
|
|
|
denyByDefault bool
|
|
|
|
sourceIPHeader string
|
|
|
|
domains []string
|
|
|
|
vhsEnabled bool
|
|
|
|
vhsNamespacesEnabled map[string]bool
|
2023-12-05 12:49:13 +00:00
|
|
|
}
|
2023-11-30 08:25:05 +00:00
|
|
|
|
2024-04-17 14:08:55 +00:00
|
|
|
func (r *middlewareSettingsMock) SourceIPHeader() string {
|
2024-04-17 15:21:21 +00:00
|
|
|
return r.sourceIPHeader
|
2024-04-17 14:08:55 +00:00
|
|
|
}
|
|
|
|
|
2023-11-30 08:25:05 +00:00
|
|
|
func (r *middlewareSettingsMock) NamespaceHeader() string {
|
|
|
|
return FrostfsNamespaceHeader
|
|
|
|
}
|
2023-11-16 12:10:51 +00:00
|
|
|
|
2023-11-30 08:25:05 +00:00
|
|
|
func (r *middlewareSettingsMock) ResolveNamespaceAlias(ns string) string {
|
|
|
|
return ns
|
2023-11-16 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2023-12-05 12:49:13 +00:00
|
|
|
func (r *middlewareSettingsMock) PolicyDenyByDefault() bool {
|
|
|
|
return r.denyByDefault
|
|
|
|
}
|
|
|
|
|
2024-07-31 06:45:46 +00:00
|
|
|
func (r *middlewareSettingsMock) Domains() []string {
|
|
|
|
return r.domains
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *middlewareSettingsMock) GlobalVHS() bool {
|
|
|
|
return r.vhsEnabled
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *middlewareSettingsMock) VHSNamespacesEnabled() map[string]bool {
|
|
|
|
return r.vhsNamespacesEnabled
|
|
|
|
}
|
|
|
|
|
2024-02-26 13:18:34 +00:00
|
|
|
type frostFSIDMock struct {
|
2024-05-16 05:16:27 +00:00
|
|
|
tags map[string]string
|
|
|
|
validateError bool
|
|
|
|
userGroupsError bool
|
2024-02-26 13:18:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *frostFSIDMock) ValidatePublicKey(*keys.PublicKey) error {
|
2024-05-16 05:16:27 +00:00
|
|
|
if f.validateError {
|
|
|
|
return fmt.Errorf("some error")
|
|
|
|
}
|
|
|
|
|
2024-02-26 13:18:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-04-12 08:59:05 +00:00
|
|
|
func (f *frostFSIDMock) GetUserGroupIDsAndClaims(util.Uint160) ([]string, map[string]string, error) {
|
2024-05-16 05:16:27 +00:00
|
|
|
if f.userGroupsError {
|
|
|
|
return nil, nil, fmt.Errorf("some error")
|
|
|
|
}
|
2024-04-12 08:59:05 +00:00
|
|
|
return []string{}, f.tags, nil
|
2024-02-26 13:18:34 +00:00
|
|
|
}
|
|
|
|
|
2024-04-10 06:41:07 +00:00
|
|
|
type xmlMock struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *xmlMock) NewXMLDecoder(r io.Reader) *xml.Decoder {
|
|
|
|
return xml.NewDecoder(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
type resourceTaggingMock struct {
|
2024-05-16 05:16:27 +00:00
|
|
|
bucketTags map[string]string
|
|
|
|
objectTags map[string]string
|
|
|
|
noSuchObjectKey bool
|
|
|
|
noSuchBucketKey bool
|
2024-04-10 06:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *resourceTaggingMock) GetBucketTagging(context.Context, *data.BucketInfo) (map[string]string, error) {
|
2024-05-16 05:16:27 +00:00
|
|
|
if m.noSuchBucketKey {
|
|
|
|
return nil, apiErrors.GetAPIError(apiErrors.ErrNoSuchKey)
|
|
|
|
}
|
2024-04-10 06:41:07 +00:00
|
|
|
return m.bucketTags, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *resourceTaggingMock) GetObjectTagging(context.Context, *data.GetObjectTaggingParams) (string, map[string]string, error) {
|
2024-05-16 05:16:27 +00:00
|
|
|
if m.noSuchObjectKey {
|
2024-04-10 06:41:07 +00:00
|
|
|
return "", nil, apiErrors.GetAPIError(apiErrors.ErrNoSuchKey)
|
|
|
|
}
|
|
|
|
return "", m.objectTags, nil
|
|
|
|
}
|
|
|
|
|
2023-07-19 14:18:55 +00:00
|
|
|
type handlerMock struct {
|
2024-02-27 09:45:37 +00:00
|
|
|
t *testing.T
|
|
|
|
cfg *middlewareSettingsMock
|
|
|
|
buckets map[string]*data.BucketInfo
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type handlerResult struct {
|
|
|
|
Method string
|
|
|
|
ReqInfo *middleware.ReqInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) HeadObjectHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetObjectACLHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutObjectACLHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetObjectTaggingHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutObjectTaggingHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) DeleteObjectTaggingHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) SelectObjectContentHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetObjectRetentionHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetObjectLegalHoldHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-04-10 06:41:07 +00:00
|
|
|
func (h *handlerMock) GetObjectHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := &handlerResult{
|
|
|
|
Method: middleware.GetObjectOperation,
|
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetObjectAttributesHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) CopyObjectHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutObjectRetentionHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutObjectLegalHoldHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutObjectHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := &handlerResult{
|
2023-11-30 08:25:05 +00:00
|
|
|
Method: middleware.PutObjectOperation,
|
2023-07-19 14:18:55 +00:00
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
|
|
|
}
|
|
|
|
|
2024-05-16 05:16:27 +00:00
|
|
|
func (h *handlerMock) DeleteObjectHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := &handlerResult{
|
|
|
|
Method: middleware.DeleteObjectOperation,
|
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketLocationHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-03-05 06:56:12 +00:00
|
|
|
func (h *handlerMock) GetBucketPolicyStatusHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2023-07-19 14:18:55 +00:00
|
|
|
func (h *handlerMock) GetBucketPolicyHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketLifecycleHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketEncryptionHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketACLHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutBucketACLHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketCorsHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutBucketCorsHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) DeleteBucketCorsHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketWebsiteHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketAccelerateHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketRequestPaymentHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketLoggingHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketReplicationHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketTaggingHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) DeleteBucketWebsiteHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) DeleteBucketTaggingHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketObjectLockConfigHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketVersioningHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) GetBucketNotificationHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) ListenBucketNotificationHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) ListObjectsV2MHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2023-07-20 09:08:45 +00:00
|
|
|
func (h *handlerMock) ListObjectsV2Handler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := &handlerResult{
|
|
|
|
Method: "ListObjectsV2",
|
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) ListBucketObjectVersionsHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2023-07-20 09:08:45 +00:00
|
|
|
func (h *handlerMock) ListObjectsV1Handler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := &handlerResult{
|
|
|
|
Method: "ListObjectsV1",
|
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutBucketLifecycleHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutBucketEncryptionHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutBucketPolicyHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutBucketObjectLockConfigHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-04-10 06:41:07 +00:00
|
|
|
func (h *handlerMock) PutBucketTaggingHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := &handlerResult{
|
|
|
|
Method: middleware.PutBucketTaggingOperation,
|
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutBucketVersioningHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PutBucketNotificationHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2024-02-27 09:45:37 +00:00
|
|
|
func (h *handlerMock) CreateBucketHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
reqInfo := middleware.GetReqInfo(r.Context())
|
|
|
|
|
|
|
|
h.buckets[reqInfo.Namespace+reqInfo.BucketName] = &data.BucketInfo{
|
2024-05-28 12:50:34 +00:00
|
|
|
Name: reqInfo.BucketName,
|
2024-02-27 09:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res := &handlerResult{
|
|
|
|
Method: middleware.CreateBucketOperation,
|
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
2023-12-19 09:47:28 +00:00
|
|
|
func (h *handlerMock) HeadBucketHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := &handlerResult{
|
|
|
|
Method: middleware.HeadBucketOperation,
|
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) PostObject(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) DeleteMultipleObjectsHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) DeleteBucketPolicyHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) DeleteBucketLifecycleHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) DeleteBucketEncryptionHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) DeleteBucketHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2023-12-19 09:47:28 +00:00
|
|
|
func (h *handlerMock) ListBucketsHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := &handlerResult{
|
|
|
|
Method: middleware.ListBucketsOperation,
|
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) Preflight(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) AppendCORSHeaders(http.ResponseWriter, *http.Request) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) CreateMultipartUploadHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) UploadPartHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := &handlerResult{
|
|
|
|
Method: "UploadPart",
|
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) UploadPartCopy(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) CompleteMultipartUploadHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) AbortMultipartUploadHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handlerMock) ListPartsHandler(http.ResponseWriter, *http.Request) {
|
|
|
|
//TODO implement me
|
|
|
|
panic("implement me")
|
|
|
|
}
|
|
|
|
|
2023-07-20 09:08:45 +00:00
|
|
|
func (h *handlerMock) ListMultipartUploadsHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
res := &handlerResult{
|
|
|
|
Method: "ListMultipartUploads",
|
|
|
|
ReqInfo: middleware.GetReqInfo(r.Context()),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.writeResponse(w, res)
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 09:45:37 +00:00
|
|
|
func (h *handlerMock) ResolveBucket(ctx context.Context, name string) (*data.BucketInfo, error) {
|
|
|
|
reqInfo := middleware.GetReqInfo(ctx)
|
|
|
|
bktInfo, ok := h.buckets[reqInfo.Namespace+name]
|
|
|
|
if !ok {
|
2024-04-10 06:41:07 +00:00
|
|
|
return nil, apiErrors.GetAPIError(apiErrors.ErrNoSuchBucket)
|
2024-02-27 09:45:37 +00:00
|
|
|
}
|
|
|
|
return bktInfo, nil
|
2023-07-19 14:18:55 +00:00
|
|
|
}
|
|
|
|
|
2024-03-01 14:07:08 +00:00
|
|
|
func (h *handlerMock) ResolveCID(ctx context.Context, bucket string) (cid.ID, error) {
|
|
|
|
bktInfo, err := h.ResolveBucket(ctx, bucket)
|
|
|
|
if err != nil {
|
|
|
|
return cid.ID{}, err
|
|
|
|
}
|
|
|
|
return bktInfo.CID, nil
|
|
|
|
}
|
|
|
|
|
2023-07-19 14:18:55 +00:00
|
|
|
func (h *handlerMock) writeResponse(w http.ResponseWriter, resp *handlerResult) {
|
|
|
|
respData, err := json.Marshal(resp)
|
|
|
|
require.NoError(h.t, err)
|
|
|
|
|
|
|
|
_, err = w.Write(respData)
|
|
|
|
require.NoError(h.t, err)
|
|
|
|
}
|