api: Relax object name validation. (#2814)

Fixes #2812
master
Harshavardhana 8 years ago committed by GitHub
parent db3da97a50
commit 5ecba587f7
  1. 8
      cmd/bucket-notification-handlers_test.go
  2. 2
      cmd/fs-v1_test.go
  3. 2
      cmd/object-api-listobjects_test.go
  4. 4
      cmd/object-api-multipart_test.go
  5. 7
      cmd/object-utils.go
  6. 7
      cmd/object-utils_test.go
  7. 2
      cmd/server_test.go
  8. 2
      cmd/server_v2_test.go

@ -174,7 +174,7 @@ func testGetBucketNotificationHandler(obj ObjectLayer, instanceType string, t Te
// get random bucket name.
randBucket := getRandomBucketName()
noNotificationBucket := "nonotification"
invalidBucket := "Invalid^Bucket"
invalidBucket := "Invalid\\Bucket"
// Create buckets for the following test cases.
for _, bucket := range []string{randBucket, noNotificationBucket} {
@ -326,7 +326,7 @@ func TestGetBucketNotificationHandler(t *testing.T) {
}
func testPutBucketNotificationHandler(obj ObjectLayer, instanceType string, t TestErrHandler) {
invalidBucket := "Invalid^Bucket"
invalidBucket := "Invalid\\Bucket"
// get random bucket name.
randBucket := getRandomBucketName()
@ -483,7 +483,7 @@ func TestPutBucketNotificationHandler(t *testing.T) {
}
func testListenBucketNotificationHandler(obj ObjectLayer, instanceType string, t TestErrHandler) {
invalidBucket := "Invalid^Bucket"
invalidBucket := "Invalid\\Bucket"
noNotificationBucket := "nonotificationbucket"
// get random bucket name.
randBucket := getRandomBucketName()
@ -629,7 +629,7 @@ func TestListenBucketNotificationHandler(t *testing.T) {
}
func testRemoveNotificationConfig(obj ObjectLayer, instanceType string, t TestErrHandler) {
invalidBucket := "Invalid^Bucket"
invalidBucket := "Invalid\\Bucket"
// get random bucket name.
randBucket := getRandomBucketName()

@ -194,7 +194,7 @@ func TestFSDeleteObject(t *testing.T) {
t.Fatal("Unexpected error: ", err)
}
// Test with invalid object name
if err := fs.DeleteObject(bucketName, "^"); !isSameType(errorCause(err), ObjectNameInvalid{}) {
if err := fs.DeleteObject(bucketName, "\\"); !isSameType(errorCause(err), ObjectNameInvalid{}) {
t.Fatal("Unexpected error: ", err)
}
// Test with inexist bucket/object

@ -514,7 +514,7 @@ func testListObjects(obj ObjectLayer, instanceType string, t TestErrHandler) {
{"test-bucket-list-object", "/", "", "/", 10, resultCases[30], nil, true},
// Test with invalid prefix (61)
{"test-bucket-list-object", "^", "", "/", 10, resultCases[30], ObjectNameInvalid{Bucket: "test-bucket-list-object", Object: "^"}, false},
{"test-bucket-list-object", "\\", "", "/", 10, resultCases[30], ObjectNameInvalid{Bucket: "test-bucket-list-object", Object: "\\"}, false},
}
for i, testCase := range testCases {

@ -58,7 +58,7 @@ func testObjectNewMultipartUpload(obj ObjectLayer, instanceType string, t TestEr
t.Fatalf("%s : %s", instanceType, err.Error())
}
_, err = obj.NewMultipartUpload(bucket, "^", nil)
_, err = obj.NewMultipartUpload(bucket, "\\", nil)
if err == nil {
t.Fatalf("%s: Expected to fail since object name is invalid.", instanceType)
}
@ -109,7 +109,7 @@ func testObjectAbortMultipartUpload(obj ObjectLayer, instanceType string, t Test
expectedErrType error
}{
{"--", object, uploadID, BucketNameInvalid{}},
{bucket, "^", uploadID, ObjectNameInvalid{}},
{bucket, "\\", uploadID, ObjectNameInvalid{}},
{"foo", object, uploadID, BucketNotFound{}},
{bucket, object, "foo-foo", InvalidUploadID{}},
{bucket, object, uploadID, nil},

@ -75,11 +75,8 @@ func IsValidBucketName(bucket string) bool {
// Rejects strings with following characters.
//
// - Backslash ("\")
// - Caret ("^")
// - Grave accent / back tick ("`")
// - Vertical bar / pipe ("|")
//
// Minio does not support object names with trailing "/".
// additionally minio does not support object names with trailing "/".
func IsValidObjectName(object string) bool {
if len(object) == 0 {
return false
@ -103,7 +100,7 @@ func IsValidObjectPrefix(object string) bool {
return false
}
// Reject unsupported characters in object name.
if strings.ContainsAny(object, "`^|\\\"") {
if strings.ContainsAny(object, "\\") {
return false
}
return true

@ -46,7 +46,7 @@ func TestIsValidBucketName(t *testing.T) {
{"192.168.1.1", false},
{"$this-is-not-valid-too", false},
{"contains-$-dollar", false},
{"contains-^-carrot", false},
{"contains-^-carret", false},
{"contains-$-dollar", false},
{"contains-$-dollar", false},
{"......", false},
@ -89,12 +89,17 @@ func TestIsValidObjectName(t *testing.T) {
{"117Gn8rfHL2ACARPAhaFd0AGzic9pUbIA/5OCn5A", true},
{"SHØRT", true},
{"f*le", true},
{"contains-^-carret", true},
{"contains-|-pipe", true},
{"contains-\"-quote", true},
{"contains-`-tick", true},
{"There are far too many object names, and far too few bucket names!", true},
// cases for which test should fail.
// passing invalid object names.
{"", false},
{"a/b/c/", false},
{"/a/b/c", false},
{"contains-\\-backslash", false},
{string([]byte{0xff, 0xfe, 0xfd}), false},
}

@ -176,7 +176,7 @@ func (s *TestSuiteCommon) TestBucketSNSNotification(c *C) {
verifyError(c, response, "InvalidArgument", "filter rule name must be either prefix or suffix", http.StatusBadRequest)
invalidBucketNotificationBuf = `<NotificationConfiguration><TopicConfiguration><Event>s3:ObjectCreated:Put</Event><Filter><S3Key><FilterRule><Name>prefix</Name><Value>|||</Value></FilterRule></S3Key></Filter><Id>1</Id><Topic>arn:minio:sns:us-east-1:1:listen</Topic></TopicConfiguration></NotificationConfiguration>`
invalidBucketNotificationBuf = `<NotificationConfiguration><TopicConfiguration><Event>s3:ObjectCreated:Put</Event><Filter><S3Key><FilterRule><Name>prefix</Name><Value>hello\</Value></FilterRule></S3Key></Filter><Id>1</Id><Topic>arn:minio:sns:us-east-1:1:listen</Topic></TopicConfiguration></NotificationConfiguration>`
request, err = newTestSignedRequestV4("PUT", getPutNotificationURL(s.endPoint, bucketName),
int64(len(invalidBucketNotificationBuf)), bytes.NewReader([]byte(invalidBucketNotificationBuf)), s.accessKey, s.secretKey)

@ -173,7 +173,7 @@ func (s *TestSuiteCommonV2) TestBucketSNSNotification(c *C) {
verifyError(c, response, "InvalidArgument", "filter rule name must be either prefix or suffix", http.StatusBadRequest)
invalidBucketNotificationBuf = `<NotificationConfiguration><TopicConfiguration><Event>s3:ObjectCreated:Put</Event><Filter><S3Key><FilterRule><Name>prefix</Name><Value>|||</Value></FilterRule></S3Key></Filter><Id>1</Id><Topic>arn:minio:sns:us-east-1:1:listen</Topic></TopicConfiguration></NotificationConfiguration>`
invalidBucketNotificationBuf = `<NotificationConfiguration><TopicConfiguration><Event>s3:ObjectCreated:Put</Event><Filter><S3Key><FilterRule><Name>prefix</Name><Value>hello\</Value></FilterRule></S3Key></Filter><Id>1</Id><Topic>arn:minio:sns:us-east-1:1:listen</Topic></TopicConfiguration></NotificationConfiguration>`
request, err = newTestSignedRequestV2("PUT", getPutNotificationURL(s.endPoint, bucketName),
int64(len(invalidBucketNotificationBuf)), bytes.NewReader([]byte(invalidBucketNotificationBuf)), s.accessKey, s.secretKey)

Loading…
Cancel
Save