From 623fbfbf4a1e92d04779ddf0b0c340784904cd7f Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 29 Nov 2024 12:18:38 +0100 Subject: [PATCH 1/7] test: import package with same prefix name --- .../git_package_content_provider_test.go | 5 +++++ .../git_package_content_provider/locators.go | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go index a5ac4cceca..43e450d672 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go @@ -610,6 +610,11 @@ func Test_isSamePackageLocalAbsoluteLocator_TestDetectionInDifferentSubdirectori require.True(t, result) } +func Test_isNotSamePackageLocalAbsoluteLocator_TestRepositoriesWithSamePrefixNames(t *testing.T) { + result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package2/main.star", "github.com/author/package/main.star", "github.com/author/package/") + require.False(t, result) +} + func Test_getPathToPackageRoot(t *testing.T) { githubUrlWithKurtosisPackageInSubfolder := "github.com/sample/sample-package/folder/subpackage" parsedGitUrl, err := shared_utils.ParseGitURL(githubUrlWithKurtosisPackageInSubfolder) diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go index c5472eb361..bed6d7baa3 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go @@ -20,10 +20,8 @@ func isLocalLocator(locator string) bool { } func shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage(relativeOrAbsoluteLocator string, sourceModuleLocator string, rootPackageId string) bool { - isSourceModuleInRootPackage := strings.HasPrefix(sourceModuleLocator, rootPackageId) isAbsoluteLocatorInRootPackage := strings.HasPrefix(relativeOrAbsoluteLocator, rootPackageId) - return isSourceModuleInRootPackage && isAbsoluteLocatorInRootPackage } From f30d535f0725dcd793f10f8e54d108645d9fd6fc Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 29 Nov 2024 13:09:06 +0100 Subject: [PATCH 2/7] test: add `GetAbsoluteLocator` test --- .../git_package_content_provider_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go index 43e450d672..490ffb2f9d 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go @@ -600,6 +600,17 @@ func TestGetAbsoluteLocator_AbsoluteLocatorIsInRootPackageButSourceIsNotShouldNo require.Nil(t, err) } +func TestGetAbsoluteLocator_RepositoriesWithSamePrefixNameShouldNotBeBlocked(t *testing.T) { + provider := NewGitPackageContentProvider("", "", NewGitHubPackageAuthProvider(""), nil) + + packageId := "github.com/main-package" + locatorOfModuleInWhichThisBuiltInIsBeingCalled := "github.com/main-package-xyz/main.star" // same package prefix + maybeRelativeLocator := "github.com/main-package/file.star" + + _, err := provider.GetAbsoluteLocator(packageId, locatorOfModuleInWhichThisBuiltInIsBeingCalled, maybeRelativeLocator, noPackageReplaceOptions) + require.Nil(t, err) +} + func Test_isSamePackageLocalAbsoluteLocator_TestDetectionInSubpath(t *testing.T) { result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package/bang/lib.star", "github.com/author/package/main.star", "github.com/author/package/") require.True(t, result) From 9b65b300b0959588b003be9b51242a8c7a6d88ad Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 29 Nov 2024 13:15:39 +0100 Subject: [PATCH 3/7] test --- .../git_package_content_provider_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go index 490ffb2f9d..b1fae524d4 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go @@ -612,17 +612,17 @@ func TestGetAbsoluteLocator_RepositoriesWithSamePrefixNameShouldNotBeBlocked(t * } func Test_isSamePackageLocalAbsoluteLocator_TestDetectionInSubpath(t *testing.T) { - result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package/bang/lib.star", "github.com/author/package/main.star", "github.com/author/package/") + result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package/bang/lib.star", "github.com/author/package/main.star", "github.com/author/package") require.True(t, result) } func Test_isSamePackageLocalAbsoluteLocator_TestDetectionInDifferentSubdirectories(t *testing.T) { - result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package/subdir1/file1.star", "github.com/author/package/subdir2/file2.star", "github.com/author/package/") + result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package/subdir1/file1.star", "github.com/author/package/subdir2/file2.star", "github.com/author/package") require.True(t, result) } func Test_isNotSamePackageLocalAbsoluteLocator_TestRepositoriesWithSamePrefixNames(t *testing.T) { - result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package2/main.star", "github.com/author/package/main.star", "github.com/author/package/") + result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package2/main.star", "github.com/author/package/main.star", "github.com/author/package") require.False(t, result) } From f3a167aff232635c4fd8bff7b5dd4c81c1d71b51 Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 29 Nov 2024 13:22:46 +0100 Subject: [PATCH 4/7] fix: importing package with same prefix name --- .../startosis_packages/git_package_content_provider/locators.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go index bed6d7baa3..3ddc1dedad 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go @@ -20,6 +20,8 @@ func isLocalLocator(locator string) bool { } func shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage(relativeOrAbsoluteLocator string, sourceModuleLocator string, rootPackageId string) bool { + // Make sure the root package id ends with a trailing slash. + rootPackageId = strings.TrimPrefix(rootPackageId, "/") + "/" isSourceModuleInRootPackage := strings.HasPrefix(sourceModuleLocator, rootPackageId) isAbsoluteLocatorInRootPackage := strings.HasPrefix(relativeOrAbsoluteLocator, rootPackageId) return isSourceModuleInRootPackage && isAbsoluteLocatorInRootPackage From eed3599ae955123de74bab63da7bb0c100d837ca Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 29 Nov 2024 13:25:36 +0100 Subject: [PATCH 5/7] test: with and without root package id trailing slash --- .../git_package_content_provider_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go index b1fae524d4..37418e0d33 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go @@ -612,18 +612,33 @@ func TestGetAbsoluteLocator_RepositoriesWithSamePrefixNameShouldNotBeBlocked(t * } func Test_isSamePackageLocalAbsoluteLocator_TestDetectionInSubpath(t *testing.T) { + // Without root package id trailing slash. result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package/bang/lib.star", "github.com/author/package/main.star", "github.com/author/package") require.True(t, result) + + // With root package id trailing slash. + result = shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package/bang/lib.star", "github.com/author/package/main.star", "github.com/author/package/") + require.True(t, result) } func Test_isSamePackageLocalAbsoluteLocator_TestDetectionInDifferentSubdirectories(t *testing.T) { + // Without root package id trailing slash. result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package/subdir1/file1.star", "github.com/author/package/subdir2/file2.star", "github.com/author/package") require.True(t, result) + + // With root package id trailing slash. + result = shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package/subdir1/file1.star", "github.com/author/package/subdir2/file2.star", "github.com/author/package/") + require.True(t, result) } func Test_isNotSamePackageLocalAbsoluteLocator_TestRepositoriesWithSamePrefixNames(t *testing.T) { + // Without root package id trailing slash. result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package2/main.star", "github.com/author/package/main.star", "github.com/author/package") require.False(t, result) + + // With root package id trailing slash. + result = shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package2/main.star", "github.com/author/package/main.star", "github.com/author/package/") + require.False(t, result) } func Test_getPathToPackageRoot(t *testing.T) { From 948f57369bddaec282c6b9dfe783898c2ff99840 Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 29 Nov 2024 13:28:56 +0100 Subject: [PATCH 6/7] fix: typo --- .../startosis_packages/git_package_content_provider/locators.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go index 3ddc1dedad..b81d745c6d 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/locators.go @@ -21,7 +21,7 @@ func isLocalLocator(locator string) bool { func shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage(relativeOrAbsoluteLocator string, sourceModuleLocator string, rootPackageId string) bool { // Make sure the root package id ends with a trailing slash. - rootPackageId = strings.TrimPrefix(rootPackageId, "/") + "/" + rootPackageId = strings.TrimSuffix(rootPackageId, "/") + "/" isSourceModuleInRootPackage := strings.HasPrefix(sourceModuleLocator, rootPackageId) isAbsoluteLocatorInRootPackage := strings.HasPrefix(relativeOrAbsoluteLocator, rootPackageId) return isSourceModuleInRootPackage && isAbsoluteLocatorInRootPackage From c1fdd3717bfb6ede069f4d991de106e412b668d4 Mon Sep 17 00:00:00 2001 From: leovct Date: Fri, 29 Nov 2024 13:40:07 +0100 Subject: [PATCH 7/7] chore: nit --- .../git_package_content_provider_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go index 37418e0d33..76bad1797b 100644 --- a/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go +++ b/core/server/api_container/server/startosis_engine/startosis_packages/git_package_content_provider/git_package_content_provider_test.go @@ -2,6 +2,10 @@ package git_package_content_provider import ( "fmt" + "os" + "path" + "testing" + "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/shared_utils" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/database_accessors/enclave_db" "github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/docker_compose_transpiler" @@ -12,9 +16,6 @@ import ( "github.com/kurtosis-tech/stacktrace" "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" - "os" - "path" - "testing" ) const ( @@ -600,7 +601,7 @@ func TestGetAbsoluteLocator_AbsoluteLocatorIsInRootPackageButSourceIsNotShouldNo require.Nil(t, err) } -func TestGetAbsoluteLocator_RepositoriesWithSamePrefixNameShouldNotBeBlocked(t *testing.T) { +func TestGetAbsoluteLocator_ImportPackageWithSamePrefixNameAsRootPackageShouldNotBeBlocked(t *testing.T) { provider := NewGitPackageContentProvider("", "", NewGitHubPackageAuthProvider(""), nil) packageId := "github.com/main-package" @@ -631,7 +632,7 @@ func Test_isSamePackageLocalAbsoluteLocator_TestDetectionInDifferentSubdirectori require.True(t, result) } -func Test_isNotSamePackageLocalAbsoluteLocator_TestRepositoriesWithSamePrefixNames(t *testing.T) { +func Test_isNotSamePackageLocalAbsoluteLocator_TestImportPackageWithSamePrefixNameAsRootPackages(t *testing.T) { // Without root package id trailing slash. result := shouldBlockAbsoluteLocatorBecauseIsInTheSameSourceModuleLocatorPackage("github.com/author/package2/main.star", "github.com/author/package/main.star", "github.com/author/package") require.False(t, result)