mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
refactor(object): add CubeFS's statement comment
Signed-off-by: yhjiango <jiangyunhua@oppo.com>
This commit is contained in:
parent
cae5f00182
commit
135da4ec9f
@ -1,3 +1,17 @@
|
||||
// Copyright 2023 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
import (
|
||||
|
||||
@ -1,19 +1,16 @@
|
||||
/*
|
||||
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
||||
* Modifications copyright 2019 The CubeFS Authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2019 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
@ -76,22 +73,24 @@ func buildStringToSignV2(method, date, canonicalizedResource string, header http
|
||||
}
|
||||
|
||||
func buildCanonicalizedAmzHeadersV2(headers http.Header) string {
|
||||
var keys []string
|
||||
keyval := make(map[string]string)
|
||||
xAmzKeys := make([]string, 0)
|
||||
xAmzHeaders := make(map[string]string)
|
||||
for key := range headers {
|
||||
lkey := strings.ToLower(key)
|
||||
if !strings.HasPrefix(lkey, "x-amz-") {
|
||||
lowKey := strings.ToLower(key)
|
||||
if !strings.HasPrefix(lowKey, "x-amz-") {
|
||||
continue
|
||||
}
|
||||
keys = append(keys, lkey)
|
||||
keyval[lkey] = strings.Join(headers[key], ",")
|
||||
xAmzKeys = append(xAmzKeys, lowKey)
|
||||
xAmzHeaders[lowKey] = strings.Join(headers[key], ",")
|
||||
}
|
||||
sort.Strings(keys)
|
||||
var canonicalHeaders []string
|
||||
for _, key := range keys {
|
||||
canonicalHeaders = append(canonicalHeaders, key+":"+keyval[key])
|
||||
sort.Strings(xAmzKeys)
|
||||
|
||||
canonicalizedHeaders := make([]string, 0, len(xAmzKeys))
|
||||
for _, key := range xAmzKeys {
|
||||
canonicalizedHeaders = append(canonicalizedHeaders, key+":"+xAmzHeaders[key])
|
||||
}
|
||||
return strings.Join(canonicalHeaders, "\n")
|
||||
|
||||
return strings.Join(canonicalizedHeaders, "\n")
|
||||
}
|
||||
|
||||
func buildCanonicalizedResourceQueryV2(resource string, query url.Values) string {
|
||||
|
||||
@ -1,19 +1,16 @@
|
||||
/*
|
||||
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
||||
* Modifications copyright 2019 The CubeFS Authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2019 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
@ -89,12 +86,13 @@ func buildCanonicalRequest(r *http.Request, signedHeaders []string, presign bool
|
||||
}
|
||||
|
||||
func buildSignedHeaders(signedHeaders []string) string {
|
||||
var headers []string
|
||||
var lowerHeaders []string
|
||||
for _, k := range signedHeaders {
|
||||
headers = append(headers, strings.ToLower(k))
|
||||
lowerHeaders = append(lowerHeaders, strings.ToLower(k))
|
||||
}
|
||||
sort.Strings(headers)
|
||||
return strings.Join(headers, ";")
|
||||
sort.Strings(lowerHeaders)
|
||||
|
||||
return strings.Join(lowerHeaders, ";")
|
||||
}
|
||||
|
||||
func buildCanonicalHeaders(req *http.Request, signedHeaders []string) string {
|
||||
|
||||
@ -1,3 +1,17 @@
|
||||
// Copyright 2020 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
// https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html
|
||||
@ -69,25 +83,25 @@ func valid(r CORSRule) *ErrorCode {
|
||||
if len(r.AllowedMethod) == 0 {
|
||||
return NewError("InvalidCORSRule", "Missing AllowedMethods.", 400)
|
||||
}
|
||||
//check origin, at most contain one *
|
||||
// check origin, at most contain one *
|
||||
for _, origin := range r.AllowedOrigin {
|
||||
if strings.Count(origin, "*") > 1 {
|
||||
return NewError("InvalidCORSRule", "AllowedOrigin can not have more than one wildcard: "+origin, 400)
|
||||
}
|
||||
}
|
||||
//AllowedMethod is case sensitive
|
||||
// AllowedMethod is case sensitive
|
||||
for _, method := range r.AllowedMethod {
|
||||
if !StringListContain(methodsRequest, method) {
|
||||
return NewError("InvalidCORSRule", "AllowedMethod is unsupport: "+method, 400)
|
||||
}
|
||||
}
|
||||
//check allowedheaders, at most contain one *
|
||||
// check allowedheaders, at most contain one *
|
||||
for _, header := range r.AllowedHeader {
|
||||
if strings.Count(header, "*") > 1 {
|
||||
return NewError("InvalidCORSRule", "AllowedHeaders can not have more than one wildcard: "+header, 400)
|
||||
}
|
||||
}
|
||||
//exposed headers can't include *
|
||||
// exposed headers can't include *
|
||||
for _, exheader := range r.ExposeHeader {
|
||||
if strings.Contains(exheader, "*") {
|
||||
return NewError("InvalidCORSRule", "ExposedHeaders can not include wildcard: "+exheader, 400)
|
||||
|
||||
@ -1,3 +1,17 @@
|
||||
// Copyright 2020 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
// https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/dev/EnableCorsUsingREST.html
|
||||
|
||||
@ -1,19 +1,16 @@
|
||||
/*
|
||||
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
||||
* Modifications copyright 2019 The CubeFS Authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2019 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
|
||||
@ -1,19 +1,16 @@
|
||||
/*
|
||||
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
||||
* Modifications copyright 2019 The CubeFS Authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2019 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
|
||||
@ -1,19 +1,16 @@
|
||||
/*
|
||||
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
||||
* Modifications copyright 2019 The CubeFS Authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2019 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
|
||||
@ -1,3 +1,17 @@
|
||||
// Copyright 2023 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
import "testing"
|
||||
|
||||
@ -1,19 +1,16 @@
|
||||
/*
|
||||
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
||||
* Modifications copyright 2019 The CubeFS Authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2019 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
@ -26,7 +23,7 @@ import (
|
||||
// https://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
|
||||
|
||||
// https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
|
||||
//https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/dev/example-bucket-policies.html
|
||||
// https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/dev/example-bucket-policies.html
|
||||
|
||||
type Principal map[string]StringSet
|
||||
type Resource string
|
||||
@ -61,7 +58,7 @@ func (s *Statement) isValid(bucket string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
//step2: check each field
|
||||
// step2: check each field
|
||||
if !s.isEffectValid() {
|
||||
return false, ErrInvalidEffectValue
|
||||
}
|
||||
@ -78,7 +75,7 @@ func (s *Statement) isValid(bucket string) (bool, error) {
|
||||
return false, ErrInvalidResourceInPolicy
|
||||
}
|
||||
|
||||
//step3: check action & resource valid combination
|
||||
// step3: check action & resource valid combination
|
||||
if !s.isValidCombination() {
|
||||
return false, ErrInvalidActionResourceCombination
|
||||
}
|
||||
@ -110,7 +107,7 @@ func (s *Statement) isEffectValid() bool {
|
||||
|
||||
// "Principal": "*" or "Principal" : {"AWS":"111122223333"} or "Principal" : {"AWS":["111122223333","444455556666"]}
|
||||
func (s *Statement) isPrincipalValid() bool {
|
||||
//principal: uid must be "*" or uint32, and can't be 0
|
||||
// principal: uid must be "*" or uint32, and can't be 0
|
||||
switch s.Principal.(type) {
|
||||
case string: // "*" or "123"
|
||||
p := s.Principal.(string)
|
||||
@ -165,10 +162,10 @@ func (p PrincipalElementType) valid() bool {
|
||||
|
||||
func (s *Statement) isActionValid() bool {
|
||||
switch s.Action.(type) {
|
||||
case []interface{}: //["s3:PutObject", "s3:GetObject","s3:DeleteObject"]
|
||||
case []interface{}: // ["s3:PutObject", "s3:GetObject","s3:DeleteObject"]
|
||||
actions := s.Action.([]interface{})
|
||||
return ActionType(actions).valid()
|
||||
case string: //"s3:ListBucket"
|
||||
case string: // "s3:ListBucket"
|
||||
action := s.Action.(string)
|
||||
return ActionElementType(action).valid()
|
||||
default:
|
||||
@ -231,7 +228,7 @@ func (r ResourceElementType) valid(bucketId string) bool {
|
||||
if len(bucket_key) < 2 {
|
||||
return r == ResourceElementType(bucketId)
|
||||
}
|
||||
if bucket_key[0] != bucketId { //bucketId in resource list must be same with current bucketId
|
||||
if bucket_key[0] != bucketId { // bucketId in resource list must be same with current bucketId
|
||||
return false
|
||||
}
|
||||
if bucket_key[1] == "" { // key can't be empty when bucket is followed by a slash
|
||||
@ -241,7 +238,7 @@ func (r ResourceElementType) valid(bucketId string) bool {
|
||||
}
|
||||
|
||||
func (s *Statement) isValidCombination() bool {
|
||||
//check action & resource valid combination
|
||||
// check action & resource valid combination
|
||||
hasBucketFormat, hasObjectFormat := s.getResourceFormat()
|
||||
switch s.Action.(type) {
|
||||
case string:
|
||||
@ -270,7 +267,7 @@ func (actions ActionType) matchResource(hasBucketFormat, hasObjectFormat bool) b
|
||||
if len(actions) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, a := range actions { //every action should match
|
||||
for _, a := range actions { // every action should match
|
||||
if a1, ok := a.(string); ok {
|
||||
if !ActionElementType(a1).matchResource(hasBucketFormat, hasObjectFormat) {
|
||||
return false
|
||||
|
||||
@ -1,3 +1,17 @@
|
||||
// Copyright 2023 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
import (
|
||||
@ -130,7 +144,7 @@ func TestEffectFormat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResourceFormat(t *testing.T) {
|
||||
//bad: "arn:aws:s3:::bucket/" , or "arn:aws:s3:::/keyname" or "arn:aws:s3:::/" or "arn:aws:s3:::wrongbucket/key" or [ ] empty
|
||||
// bad: "arn:aws:s3:::bucket/" , or "arn:aws:s3:::/keyname" or "arn:aws:s3:::/" or "arn:aws:s3:::wrongbucket/key" or [ ] empty
|
||||
bucketId := "examplebucket"
|
||||
var s Statement
|
||||
|
||||
@ -152,14 +166,14 @@ func TestResourceFormat(t *testing.T) {
|
||||
}
|
||||
|
||||
invalidResources := []string{
|
||||
`["arn:aws:s3:::examplebucket/","arn:aws:s3:::examplebucket/key"]`, //first one is invaid
|
||||
`["arn:aws:s3:::examplebucket/","arn:aws:s3:::examplebucket/key"]`, // first one is invaid
|
||||
`["arn:aws:s3:::*/keyname"]`,
|
||||
`["arn:aws:s3:::/keyname"]`,
|
||||
`["arn:aws:s3:::/"]`,
|
||||
`["arn:aws:s3:::/*"]`,
|
||||
`["arn:aws:s3:::wrongbucket/key"]`,
|
||||
`["arn:aws:s3:::wrongbucket"]`,
|
||||
`["Arn:aws:s3:::examplebucket"]`, //Arn is invalid, should be arn
|
||||
`["Arn:aws:s3:::examplebucket"]`, // Arn is invalid, should be arn
|
||||
`[]`,
|
||||
`""`,
|
||||
`"arn:aws:s3:::exampl*bucket"`,
|
||||
@ -196,11 +210,11 @@ func TestPrincipalFormat(t *testing.T) {
|
||||
|
||||
invalidPrincipal := []string{
|
||||
`{}`,
|
||||
`{"aws":"11"}`, //must be "AWS", not "aws"
|
||||
`{"AWS":11}`, //must be string, not number, 11 should be "11"
|
||||
`{"aws":"11"}`, // must be "AWS", not "aws"
|
||||
`{"AWS":11}`, // must be string, not number, 11 should be "11"
|
||||
`{"AWS":[]}`,
|
||||
`{"AWS":["11",22]}`,
|
||||
`["11"]`, //currently, aws not support [] for principal
|
||||
`["11"]`, // currently, aws not support [] for principal
|
||||
}
|
||||
for _, p := range invalidPrincipal {
|
||||
err := json.Unmarshal([]byte(p), &s.Principal)
|
||||
@ -231,7 +245,7 @@ func TestActionFormat(t *testing.T) {
|
||||
`["s3:GetBucketPolicy"]`,
|
||||
`["s3:PutBucketPolicy"]`,
|
||||
`[]`,
|
||||
`["s3:PutObject","s3:invalid"]`, //second is invalid
|
||||
`["s3:PutObject","s3:invalid"]`, // second is invalid
|
||||
}
|
||||
for _, a := range invalidAction {
|
||||
err := json.Unmarshal([]byte(a), &s.Action)
|
||||
@ -262,14 +276,14 @@ func TestConditionFormat(t *testing.T) {
|
||||
}
|
||||
|
||||
invalidCondition := []string{
|
||||
`{"ipAddress":{"aws:SourceIp":["1.1.1.1/24"]}}`, //should be "IpAddress"
|
||||
`{"notIpAddress":{"aws:SourceIp":["1.1.1.3"]}}`, //should be "NotIpAddress"
|
||||
`{"IpAddress":{"SourceIp":["1.1.1.3"]}}`, //should be "aws:SourceIp"
|
||||
`{"StringLik":{"aws:Referer":"http://*.example.com/*"}}`, //should be "aws:StringLike"
|
||||
`{"ipAddress":{"aws:SourceIp":["1.1.1.1/24"]}}`, // should be "IpAddress"
|
||||
`{"notIpAddress":{"aws:SourceIp":["1.1.1.3"]}}`, // should be "NotIpAddress"
|
||||
`{"IpAddress":{"SourceIp":["1.1.1.3"]}}`, // should be "aws:SourceIp"
|
||||
`{"StringLik":{"aws:Referer":"http://*.example.com/*"}}`, // should be "aws:StringLike"
|
||||
`{"StringLike":{"aws:SourceIP":"http://*.example.com/*"}}`,
|
||||
`{"StringLike":{"aws:referer":"http://*.example.com/*"}}`,
|
||||
`{"StringLike":{"aws:host":"http://*.example.com/*"}}`,
|
||||
`{"StringNotLik":{"aws:Referer":"http://*.example.com/*"}}`, //should be "aws:StringLike"
|
||||
`{"StringNotLik":{"aws:Referer":"http://*.example.com/*"}}`, // should be "aws:StringLike"
|
||||
`{"StringNotLike":{"aws:SourceIP":"http://*.example.com/*"}}`,
|
||||
`{"StringNotLike":{"aws:referer":"http://*.example.com/*"}}`,
|
||||
`{"StringNotLike":{"aws:host":"http://*.example.com/*"}}`,
|
||||
|
||||
@ -1,3 +1,17 @@
|
||||
// Copyright 2023 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,17 @@
|
||||
// Copyright 2023 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,17 @@
|
||||
// Copyright 2023 The CubeFS Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
// implied. See the License for the specific language governing
|
||||
// permissions and limitations under the License.
|
||||
|
||||
package objectnode
|
||||
|
||||
import (
|
||||
@ -112,12 +126,12 @@ func TestValueSet_UnmarshalJSON(t *testing.T) {
|
||||
expectedResult ValueSet
|
||||
expectErr bool
|
||||
}{
|
||||
//test duplicate value
|
||||
// test duplicate value
|
||||
{[]byte(`["www.example.com","foo","foo"]`), NewValueSet(NewStringValue("www.example.com"), NewStringValue("foo"), NewStringValue("foo")), true},
|
||||
//test empty value
|
||||
// test empty value
|
||||
{[]byte(`[]`), NewValueSet(), true},
|
||||
{[]byte(`["www.example.com",["foo"]]`), NewValueSet(NewStringValue("www.example.com")), true},
|
||||
//test correct multiple value
|
||||
// test correct multiple value
|
||||
{[]byte(`["www.example.com","foo","bar"]`), NewValueSet(NewStringValue("www.example.com"), NewStringValue("foo"), NewStringValue("bar")), false},
|
||||
{[]byte(`["www.example.com"]`), NewValueSet(NewStringValue("www.example.com")), false},
|
||||
{[]byte(`"www.example.com"`), NewValueSet(NewStringValue("www.example.com")), false},
|
||||
@ -144,12 +158,12 @@ func TestValueSet_MarshalJSON(t *testing.T) {
|
||||
expectedResult []byte
|
||||
expectErr bool
|
||||
}{
|
||||
//test duplicate value
|
||||
// test duplicate value
|
||||
{NewValueSet(NewStringValue("www.example.com"), NewStringValue("foo"), NewStringValue("foo")), []byte(`["www.example.com","foo"]`), false},
|
||||
//test empty value
|
||||
// test empty value
|
||||
{NewValueSet(), []byte(`[]`), true},
|
||||
|
||||
//test correct multiple value
|
||||
// test correct multiple value
|
||||
{NewValueSet(NewStringValue("www.example.com"), NewStringValue("foo"), NewStringValue("bar")), []byte(`["www.example.com","foo","bar"]`), false},
|
||||
{NewValueSet(NewStringValue("www.example.com")), []byte(`["www.example.com"]`), false},
|
||||
{NewValueSet(NewStringValue("www.example.com"), NewIntValue(1), NewBoolValue(true)), []byte(`["www.example.com",1,true]`), false},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user