-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fail properly while parsing duplicate tags (#1701)
AWS S3 API expects duplicate keys to be rejected, due to our usage of url.ParseQuery() this was skipped since url query parser simply appends duplicate keys as key with multiple values, this is not desirable. Add more input validation and restrictions as per AWS S3 API.
- Loading branch information
1 parent
43459b0
commit 0a38a12
Showing
3 changed files
with
172 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* MinIO Go Library for Amazon S3 Compatible Cloud Storage | ||
* Copyright 2022 MinIO, Inc. | ||
* | ||
* 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 tags | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestParseTags(t *testing.T) { | ||
testCases := []struct { | ||
tags string | ||
expectedErr bool | ||
}{ | ||
{ | ||
"key1=value1&key2=value2", | ||
false, | ||
}, | ||
{ | ||
fmt.Sprintf("%0128d=%0256d", 1, 1), | ||
false, | ||
}, | ||
// Failure cases - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-restrictions | ||
{ | ||
"key1=value1&key1=value2", | ||
true, | ||
}, | ||
{ | ||
"key$=value1", | ||
true, | ||
}, | ||
{ | ||
"key1=value$", | ||
true, | ||
}, | ||
{ | ||
fmt.Sprintf("%0128d=%0257d", 1, 1), | ||
true, | ||
}, | ||
{ | ||
fmt.Sprintf("%0129d=%0256d", 1, 1), | ||
true, | ||
}, | ||
{ | ||
fmt.Sprintf("%0129d=%0257d", 1, 1), | ||
true, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
testCase := testCase | ||
t.Run(testCase.tags, func(t *testing.T) { | ||
tt, err := ParseObjectTags(testCase.tags) | ||
if !testCase.expectedErr && err != nil { | ||
t.Errorf("Expected success but failed with %v", err) | ||
} | ||
if testCase.expectedErr && err == nil { | ||
t.Error("Expected failure but found success") | ||
} | ||
if err == nil { | ||
t.Logf("%s", tt) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkParseTags(b *testing.B) { | ||
b.ResetTimer() | ||
b.ReportAllocs() | ||
|
||
for i := 0; i < b.N; i++ { | ||
ParseObjectTags("key1=value1&key2=value2") | ||
} | ||
} |