diff --git a/tools/integration_tests/implicit_dir/list_test.go b/tools/integration_tests/implicit_dir/list_test.go index 67d70df3b2..5cc48e39c7 100644 --- a/tools/integration_tests/implicit_dir/list_test.go +++ b/tools/integration_tests/implicit_dir/list_test.go @@ -37,9 +37,16 @@ func TestListImplicitObjectsFromBucket(t *testing.T) { // testBucket/dirForImplicitDirTests/explicitFile -- File // testBucket/dirForImplicitDirTests/explicitDirectory/fileInExplicitDir1 -- File // testBucket/dirForImplicitDirTests/explicitDirectory/fileInExplicitDir2 -- File + // testBucket/dirForImplicitDirTests/.. -- Dir + // testBucket/dirForImplicitDirTests/../fileInUnsupportedImplicitDir1 -- File + // testBucket/dirForImplicitDirTests/. -- Dir + // testBucket/dirForImplicitDirTests/./fileInUnsupportedImplicitDir2 -- File + // testBucket/dirForImplicitDirTests// -- Dir + // testBucket/dirForImplicitDirTests//fileInUnsupportedImplicitDir3 -- File implicit_and_explicit_dir_setup.CreateImplicitDirectoryStructure(DirForImplicitDirTests) implicit_and_explicit_dir_setup.CreateExplicitDirectoryStructure(DirForImplicitDirTests, t) + implicit_and_explicit_dir_setup.CreateUnsupportedImplicitDirectoryStructure(DirForImplicitDirTests) err := filepath.WalkDir(testDir, func(path string, dir fs.DirEntry, err error) error { if err != nil { @@ -61,21 +68,21 @@ func TestListImplicitObjectsFromBucket(t *testing.T) { if path == testDir { // numberOfObjects - 3 if len(objs) != implicit_and_explicit_dir_setup.NumberOfTotalObjects { - t.Errorf("Incorrect number of objects in the bucket.") + t.Errorf("Incorrect number of objects in the bucket. Expected: %v, Actual: %v", implicit_and_explicit_dir_setup.NumberOfTotalObjects, len(objs)) } // testBucket/dirForImplicitDirTests/explicitDir -- Dir if objs[0].Name() != implicit_and_explicit_dir_setup.ExplicitDirectory || objs[0].IsDir() != true { - t.Errorf("Listed incorrect object") + t.Errorf("Listed incorrect object #0. Expected: %v, Actual: %v", implicit_and_explicit_dir_setup.ExplicitDirectory, objs[0].Name()) } // testBucket/dirForImplicitDirTests/explicitFile -- File if objs[1].Name() != implicit_and_explicit_dir_setup.ExplicitFile || objs[1].IsDir() != false { - t.Errorf("Listed incorrect object") + t.Errorf("Listed incorrect object #1. Expected: %v, Actual: %v", implicit_and_explicit_dir_setup.ExplicitFile, objs[1].Name()) } // testBucket/dirForImplicitDirTests/implicitDir -- Dir if objs[2].Name() != implicit_and_explicit_dir_setup.ImplicitDirectory || objs[2].IsDir() != true { - t.Errorf("Listed incorrect object") + t.Errorf("Listed incorrect object #3. Expected: %v, Actual: %v", implicit_and_explicit_dir_setup.ImplicitDirectory, objs[2].Name()) } } diff --git a/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/implicit_and_explicit_dir_setup.go b/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/implicit_and_explicit_dir_setup.go index 1d09b03a40..0010bed64e 100644 --- a/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/implicit_and_explicit_dir_setup.go +++ b/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/implicit_and_explicit_dir_setup.go @@ -40,6 +40,12 @@ const FirstFileInExplicitDirectory = "fileInExplicitDir1" const SecondFileInExplicitDirectory = "fileInExplicitDir2" const FileInImplicitDirectory = "fileInImplicitDir1" const FileInImplicitSubDirectory = "fileInImplicitDir2" +const UnsupportedImplicitDirectory1 = ".." +const FileInUnsupportedImplicitDirectory1 = "fileInUnsupportedImplicitDir1" +const UnsupportedImplicitDirectory2 = "." +const FileInUnsupportedImplicitDirectory2 = "fileInUnsupportedImplicitDir2" +const UnsupportedImplicitDirectory3 = "/" +const FileInUnsupportedImplicitDirectory3 = "fileInUnsupportedImplicitDir3" func RunTestsForImplicitDirAndExplicitDir(flags [][]string, m *testing.M) int { setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet() @@ -83,6 +89,19 @@ func CreateImplicitDirectoryStructure(testDir string) { setup.RunScriptForTestData("../util/setup/implicit_and_explicit_dir_setup/testdata/create_objects.sh", path.Join(setup.TestBucket(), testDir)) } +func CreateUnsupportedImplicitDirectoryStructure(testDir string) { + // Implicit Directory Structure + // testBucket/testDir/../ -- Dir + // testBucket/testDir/../fileInUnsupportedImplicitDir1 -- File + // testBucket/testDir/. -- Dir + // testBucket/testDir/./fileInUnsupportedImplicitDir2 -- File + // testBucket/testDir// -- Dir + // testBucket/testDir//fileInUnsupportedImplicitDir3 -- File + + // Create implicit directory in bucket for testing. + setup.RunScriptForTestData("../util/setup/implicit_and_explicit_dir_setup/testdata/create_objects_in_unsupported_directories.sh", path.Join(setup.TestBucket(), testDir)) +} + func CreateExplicitDirectoryStructure(testDir string, t *testing.T) { // Explicit Directory structure // testBucket/testDir/explicitDirectory -- Dir @@ -116,3 +135,20 @@ func CreateImplicitDirectoryInExplicitDirectoryStructure(testDir string, t *test dirPathInBucket := path.Join(setup.TestBucket(), testDir, ExplicitDirectory) setup.RunScriptForTestData("../util/setup/implicit_and_explicit_dir_setup/testdata/create_objects.sh", dirPathInBucket) } + +func CreateUnsupportedImplicitDirectoryInExplicitDirectoryStructure(testDir string, t *testing.T) { + // testBucket/testDir/explicitDirectory -- Dir + // testBucket/testDir/explictFile -- File + // testBucket/testDir/explicitDirectory/fileInExplicitDir1 -- File + // testBucket/testDir/explicitDirectory/fileInExplicitDir2 -- File + // testBucket/testDir/explicitDirectory/.. -- Dir + // testBucket/testDir/explicitDirectory/../fileInUnsupportedImplicitDir1 -- File + // testBucket/testDir/explicitDirectory/. -- Dir + // testBucket/testDir/explicitDirectory/./fileInUnsupportedImplicitDir2 -- File + // testBucket/testDir/explicitDirectory// -- Dir + // testBucket/testDir/explicitDirectory//fileInUnsupportedImplicitDir3 -- File + + CreateExplicitDirectoryStructure(testDir, t) + dirPathInBucket := path.Join(setup.TestBucket(), testDir, ExplicitDirectory) + setup.RunScriptForTestData("../util/setup/implicit_and_explicit_dir_setup/testdata/create_objects_in_unsupported_directories.sh", dirPathInBucket) +} diff --git a/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/testdata/create_objects_in_unsupported_directories.sh b/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/testdata/create_objects_in_unsupported_directories.sh new file mode 100755 index 0000000000..72823039b0 --- /dev/null +++ b/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/testdata/create_objects_in_unsupported_directories.sh @@ -0,0 +1,24 @@ +# Copyright 2023 Google Inc. All Rights Reserved. +# +# 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. + +# Here $1 refers to the testBucket/testdir argument +echo "This is from directory .. file fileInUnsupportedImplicitDir1" > fileInUnsupportedImplicitDir1 +# bucket/testdir/../fileInImplicitDir1 +gcloud storage cp fileInUnsupportedImplicitDir1 gs://$1/../ +echo "This is from directory . file fileInUnsupportedImplicitDir2" > fileInUnsupportedImplicitDir2 +# bucket/testdir/./fileInImplicitDir2 +gcloud storage cp fileInUnsupportedImplicitDir2 gs://$1/./ +echo "This is from directory \"\" file fileInUnsupportedImplicitDir3" > fileInUnsupportedImplicitDir3 +# bucket/testdir//fileInImplicitDir3 +gcloud storage cp fileInUnsupportedImplicitDir3 gs://$1//fileInUnsupportedImplicitDir3