From 135da4ec9f492f71a1d4b5672062a8c7e3e136b1 Mon Sep 17 00:00:00 2001 From: yhjiango Date: Wed, 10 Jan 2024 11:18:53 +0800 Subject: [PATCH] refactor(object): add CubeFS's statement comment Signed-off-by: yhjiango --- objectnode/auth_signature_chunk_test.go | 14 +++++++ objectnode/auth_signature_v2.go | 53 ++++++++++++------------- objectnode/auth_signature_v4.go | 38 +++++++++--------- objectnode/cors.go | 22 ++++++++-- objectnode/cors_handler.go | 14 +++++++ objectnode/policy.go | 29 ++++++-------- objectnode/policy_action.go | 29 ++++++-------- objectnode/policy_condition.go | 29 ++++++-------- objectnode/policy_ipaddressop_test.go | 14 +++++++ objectnode/policy_statement.go | 47 ++++++++++------------ objectnode/policy_statement_test.go | 38 ++++++++++++------ objectnode/policy_stringlikeop_test.go | 14 +++++++ objectnode/policy_stringset_test.go | 14 +++++++ objectnode/policy_valueset_test.go | 26 +++++++++--- 14 files changed, 239 insertions(+), 142 deletions(-) diff --git a/objectnode/auth_signature_chunk_test.go b/objectnode/auth_signature_chunk_test.go index 2b226260f..0f875e32f 100644 --- a/objectnode/auth_signature_chunk_test.go +++ b/objectnode/auth_signature_chunk_test.go @@ -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 ( diff --git a/objectnode/auth_signature_v2.go b/objectnode/auth_signature_v2.go index 6547d9e04..eb3f720f3 100644 --- a/objectnode/auth_signature_v2.go +++ b/objectnode/auth_signature_v2.go @@ -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 { diff --git a/objectnode/auth_signature_v4.go b/objectnode/auth_signature_v4.go index 38fcd0da3..ff432c3b7 100644 --- a/objectnode/auth_signature_v4.go +++ b/objectnode/auth_signature_v4.go @@ -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 { diff --git a/objectnode/cors.go b/objectnode/cors.go index f99403291..c5921e22b 100644 --- a/objectnode/cors.go +++ b/objectnode/cors.go @@ -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) diff --git a/objectnode/cors_handler.go b/objectnode/cors_handler.go index b006dc527..3ff2c3499 100644 --- a/objectnode/cors_handler.go +++ b/objectnode/cors_handler.go @@ -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 diff --git a/objectnode/policy.go b/objectnode/policy.go index 326f97ba7..167d8b9e3 100644 --- a/objectnode/policy.go +++ b/objectnode/policy.go @@ -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 diff --git a/objectnode/policy_action.go b/objectnode/policy_action.go index 635b291cd..cfcc4551e 100644 --- a/objectnode/policy_action.go +++ b/objectnode/policy_action.go @@ -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 diff --git a/objectnode/policy_condition.go b/objectnode/policy_condition.go index 143b6a06b..66939edd6 100644 --- a/objectnode/policy_condition.go +++ b/objectnode/policy_condition.go @@ -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 diff --git a/objectnode/policy_ipaddressop_test.go b/objectnode/policy_ipaddressop_test.go index 25d40b1f2..871135d07 100644 --- a/objectnode/policy_ipaddressop_test.go +++ b/objectnode/policy_ipaddressop_test.go @@ -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" diff --git a/objectnode/policy_statement.go b/objectnode/policy_statement.go index d9042f9e4..f44698f06 100644 --- a/objectnode/policy_statement.go +++ b/objectnode/policy_statement.go @@ -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 diff --git a/objectnode/policy_statement_test.go b/objectnode/policy_statement_test.go index 042787a09..73795545b 100644 --- a/objectnode/policy_statement_test.go +++ b/objectnode/policy_statement_test.go @@ -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/*"}}`, diff --git a/objectnode/policy_stringlikeop_test.go b/objectnode/policy_stringlikeop_test.go index 78d21bd0f..e8285f07c 100644 --- a/objectnode/policy_stringlikeop_test.go +++ b/objectnode/policy_stringlikeop_test.go @@ -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 ( diff --git a/objectnode/policy_stringset_test.go b/objectnode/policy_stringset_test.go index d788b2ff7..bea2d2cee 100644 --- a/objectnode/policy_stringset_test.go +++ b/objectnode/policy_stringset_test.go @@ -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 ( diff --git a/objectnode/policy_valueset_test.go b/objectnode/policy_valueset_test.go index 7c56dc56e..0453df90a 100644 --- a/objectnode/policy_valueset_test.go +++ b/objectnode/policy_valueset_test.go @@ -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},