[#535] Support public access block operations

Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
This commit is contained in:
Marina Biryukova 2025-04-03 13:51:16 +03:00 committed by Alexey Vanin
parent 4f0f2ca7bd
commit a7ce40d745
23 changed files with 940 additions and 87 deletions

View file

@ -133,12 +133,12 @@ type frostFSIDMock struct {
userGroupsError bool
}
func (f *frostFSIDMock) ValidatePublicKey(*keys.PublicKey) error {
func (f *frostFSIDMock) GetUserNamespace(*keys.PublicKey) (string, error) {
if f.validateError {
return fmt.Errorf("some error")
return "", fmt.Errorf("some error")
}
return nil
return "", nil
}
func (f *frostFSIDMock) GetUserGroupIDsAndClaims(util.Uint160) ([]string, map[string]string, error) {
@ -176,9 +176,10 @@ func (m *resourceTaggingMock) GetObjectTagging(context.Context, *data.GetObjectT
}
type handlerMock struct {
t *testing.T
cfg *middlewareSettingsMock
buckets map[string]*data.BucketInfo
t *testing.T
cfg *middlewareSettingsMock
buckets map[string]*data.BucketInfo
restrict map[string]error
}
type handlerResult struct {
@ -577,6 +578,37 @@ func (h *handlerMock) PatchObjectHandler(http.ResponseWriter, *http.Request) {
panic("implement me")
}
func (h *handlerMock) PutPublicAccessBlockHandler(w http.ResponseWriter, r *http.Request) {
cfg := new(data.PublicAccessBlockConfiguration)
err := xml.NewDecoder(r.Body).Decode(cfg)
require.NoError(h.t, err)
if cfg.RestrictPublicBuckets {
reqInfo := middleware.GetReqInfo(r.Context())
h.restrict[reqInfo.Namespace+reqInfo.BucketName] = apierr.GetAPIError(apierr.ErrAccessDenied)
}
res := &handlerResult{
Method: "PutPublicAccessBlock",
ReqInfo: middleware.GetReqInfo(r.Context()),
}
h.writeResponse(w, res)
}
func (h *handlerMock) GetPublicAccessBlockHandler(http.ResponseWriter, *http.Request) {
panic("implement me")
}
func (h *handlerMock) DeletePublicAccessBlockHandler(http.ResponseWriter, *http.Request) {
panic("implement me")
}
func (h *handlerMock) CheckRestrictPublicBuckets(ctx context.Context) error {
reqInfo := middleware.GetReqInfo(ctx)
return h.restrict[reqInfo.Namespace+reqInfo.BucketName]
}
func (h *handlerMock) ResolveBucket(ctx context.Context, name string) (*data.BucketInfo, error) {
reqInfo := middleware.GetReqInfo(ctx)
bktInfo, ok := h.buckets[reqInfo.Namespace+name]