diff --git a/cmd/posix-utils_nix.go b/cmd/posix-utils_nix.go deleted file mode 100644 index f62a4aef2..000000000 --- a/cmd/posix-utils_nix.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build !windows - -/* - * Minio Cloud Storage, (C) 2016, 2017 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 cmd - -// isValidVolname verifies a volname name in accordance with object -// layer requirements. -func isValidVolname(volname string) bool { - return !(len(volname) < 3) -} diff --git a/cmd/posix-utils_test.go b/cmd/posix-utils_test.go deleted file mode 100644 index a6428139a..000000000 --- a/cmd/posix-utils_test.go +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Minio Cloud Storage, (C) 2016 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 cmd - -import "testing" - -// Tests validate volume name. -func TestIsValidVolname(t *testing.T) { - testCases := []struct { - volName string - shouldPass bool - }{ - // Cases which should pass the test. - // passing in valid bucket names. - {"lol", true}, - {"1-this-is-valid", true}, - {"1-this-too-is-valid-1", true}, - {"this.works.too.1", true}, - {"1234567", true}, - {"123", true}, - {"s3-eu-west-1.amazonaws.com", true}, - {"ideas-are-more-powerful-than-guns", true}, - {"testbucket", true}, - {"1bucket", true}, - {"bucket1", true}, - {"$this-is-not-valid-too", true}, - {"contains-$-dollar", true}, - {"contains-^-carrot", true}, - {"contains-$-dollar", true}, - {"contains-$-dollar", true}, - {".starts-with-a-dot", true}, - {"ends-with-a-dot.", true}, - {"ends-with-a-dash-", true}, - {"-starts-with-a-dash", true}, - {"THIS-BEINGS-WITH-UPPERCASe", true}, - {"tHIS-ENDS-WITH-UPPERCASE", true}, - {"ThisBeginsAndEndsWithUpperCase", true}, - {"una ñina", true}, - {"lalalallalallalalalallalallalala-theString-size-is-greater-than-64", true}, - // cases for which test should fail. - // passing invalid bucket names. - {"", false}, - {"/", false}, - {"a", false}, - {"ab", false}, - {"ab/", true}, - {"......", true}, - } - - for i, testCase := range testCases { - isValidVolname := isValidVolname(testCase.volName) - if testCase.shouldPass && !isValidVolname { - t.Errorf("Test case %d: Expected \"%s\" to be a valid bucket name", i+1, testCase.volName) - } - if !testCase.shouldPass && isValidVolname { - t.Errorf("Test case %d: Expected bucket name \"%s\" to be invalid", i+1, testCase.volName) - } - } -} diff --git a/cmd/posix-utils_windows.go b/cmd/posix-utils_windows.go deleted file mode 100644 index f1ac25397..000000000 --- a/cmd/posix-utils_windows.go +++ /dev/null @@ -1,33 +0,0 @@ -// +build windows - -/* - * Minio Cloud Storage, (C) 2017 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 cmd - -import ( - "strings" -) - -// isValidVolname verifies a volname name in accordance with object -// layer requirements. -func isValidVolname(volname string) bool { - if len(volname) < 3 { - return false - } - // Volname shouldn't have reserved characters on windows in it. - return !strings.ContainsAny(volname, `\:*?\"<>|`) -} diff --git a/cmd/posix.go b/cmd/posix.go index b47e09a2d..a9e41545d 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -42,6 +42,21 @@ const ( maxAllowedIOError = 5 ) +// isValidVolname verifies a volname name in accordance with object +// layer requirements. +func isValidVolname(volname string) bool { + if len(volname) < 3 { + return false + } + + if runtime.GOOS == "windows" { + // Volname shouldn't have reserved characters in Windows. + return !strings.ContainsAny(volname, `\:*?\"<>|`) + } + + return true +} + // posix - implements StorageAPI interface. type posix struct { // Disk usage metrics diff --git a/cmd/posix_test.go b/cmd/posix_test.go index 54aff5077..03d0ec23e 100644 --- a/cmd/posix_test.go +++ b/cmd/posix_test.go @@ -33,6 +33,60 @@ import ( "github.com/minio/minio/pkg/disk" ) +// Tests validate volume name. +func TestIsValidVolname(t *testing.T) { + testCases := []struct { + volName string + shouldPass bool + }{ + // Cases which should pass the test. + // passing in valid bucket names. + {"lol", true}, + {"1-this-is-valid", true}, + {"1-this-too-is-valid-1", true}, + {"this.works.too.1", true}, + {"1234567", true}, + {"123", true}, + {"s3-eu-west-1.amazonaws.com", true}, + {"ideas-are-more-powerful-than-guns", true}, + {"testbucket", true}, + {"1bucket", true}, + {"bucket1", true}, + {"$this-is-not-valid-too", true}, + {"contains-$-dollar", true}, + {"contains-^-carrot", true}, + {"contains-$-dollar", true}, + {"contains-$-dollar", true}, + {".starts-with-a-dot", true}, + {"ends-with-a-dot.", true}, + {"ends-with-a-dash-", true}, + {"-starts-with-a-dash", true}, + {"THIS-BEINGS-WITH-UPPERCASe", true}, + {"tHIS-ENDS-WITH-UPPERCASE", true}, + {"ThisBeginsAndEndsWithUpperCase", true}, + {"una ñina", true}, + {"lalalallalallalalalallalallalala-theString-size-is-greater-than-64", true}, + // cases for which test should fail. + // passing invalid bucket names. + {"", false}, + {"/", false}, + {"a", false}, + {"ab", false}, + {"ab/", true}, + {"......", true}, + } + + for i, testCase := range testCases { + isValidVolname := isValidVolname(testCase.volName) + if testCase.shouldPass && !isValidVolname { + t.Errorf("Test case %d: Expected \"%s\" to be a valid bucket name", i+1, testCase.volName) + } + if !testCase.shouldPass && isValidVolname { + t.Errorf("Test case %d: Expected bucket name \"%s\" to be invalid", i+1, testCase.volName) + } + } +} + // creates a temp dir and sets up posix layer. // returns posix layer, temp dir path to be used for the purpose of tests. func newPosixTestSetup() (StorageAPI, string, error) { diff --git a/cmd/posix-utils_nix_test.go b/cmd/posix_unix_test.go similarity index 100% rename from cmd/posix-utils_nix_test.go rename to cmd/posix_unix_test.go diff --git a/cmd/posix-utils_windows_test.go b/cmd/posix_windows_test.go similarity index 100% rename from cmd/posix-utils_windows_test.go rename to cmd/posix_windows_test.go