From fc07eaa4437dff2d489136d4881f0e7adf984603 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 14 Nov 2024 11:30:46 +0200 Subject: [PATCH 01/21] Fix Nuget Tests by setting inseucred connections to true --- buildtools/cli.go | 24 ++++++++++++++++++++++-- go.mod | 6 +++--- go.sum | 12 ++++++------ nuget_test.go | 4 ++-- utils/cliutils/commandsflags.go | 11 ++++++++--- 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/buildtools/cli.go b/buildtools/cli.go index fa7d87993..64381ab38 100644 --- a/buildtools/cli.go +++ b/buildtools/cli.go @@ -566,9 +566,18 @@ func NugetCmd(c *cli.Context) error { return err } + allowInsecureConnection, err := extractBoolFlagFromArgs(&filteredNugetArgs, "allow-insecure-connections") + if err != nil { + return err + } + nugetCmd := dotnet.NewNugetCommand() - nugetCmd.SetServerDetails(rtDetails).SetRepoName(targetRepo).SetBuildConfiguration(buildConfiguration). - SetBasicCommand(filteredNugetArgs[0]).SetUseNugetV2(useNugetV2) + nugetCmd.SetServerDetails(rtDetails). + SetRepoName(targetRepo). + SetBuildConfiguration(buildConfiguration). + SetBasicCommand(filteredNugetArgs[0]). + SetUseNugetV2(useNugetV2). + SetAllowInsecureConnections(allowInsecureConnection) // Since we are using the values of the command's arguments and flags along the buildInfo collection process, // we want to separate the actual NuGet basic command (restore/build...) from the arguments and flags if len(filteredNugetArgs) > 1 { @@ -1074,3 +1083,14 @@ func getTwineConfigPath() (configFilePath string, err error) { } return "", errorutils.CheckErrorf(getMissingConfigErrMsg("twine", "pip-config OR pipenv-config")) } + +func extractBoolFlagFromArgs(filteredNugetArgs *[]string, flagName string) (value bool, err error) { + var flagIndex int + var allowInsecureConnection bool + flagIndex, allowInsecureConnection, err = coreutils.FindBooleanFlag("--"+flagName, *filteredNugetArgs) + if err != nil { + return false, err + } + coreutils.RemoveFlagFromCommand(filteredNugetArgs, flagIndex, flagIndex) + return allowInsecureConnection, nil +} diff --git a/go.mod b/go.mod index ed6801ee3..d72531804 100644 --- a/go.mod +++ b/go.mod @@ -167,12 +167,12 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241113152357-24197a744331 +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114092639-b926209dfcc2 -// replace github.com/jfrog/jfrog-cli-security => github.com/jfrog/jfrog-cli-security v1.12.5-0.20241107141149-42cf964808a1 +replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba // replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240918081224-1c584cc334c7 -// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240918150101-ad5b10435a12 +replace github.com/jfrog/build-info-go => github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded // replace github.com/jfrog/gofrog => github.com/jfrog/gofrog dev diff --git a/go.sum b/go.sum index 1d9edb8f8..96b06d9a6 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,12 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0 github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/CycloneDX/cyclonedx-go v0.9.0 h1:inaif7qD8bivyxp7XLgxUYtOXWtDez7+j72qKTMQTb8= github.com/CycloneDX/cyclonedx-go v0.9.0/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw= +github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded h1:GMCP2b4v6N/tKZBQIwtneO2CJEOmt741VGse5288Im4= +github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE= +github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114092639-b926209dfcc2 h1:5EYfXTngSSah4stTK5zrc/2xGZKE+72B4gZvn0nMCHQ= +github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114092639-b926209dfcc2/go.mod h1:Lj9khgWhazp6RoiBk/AJts3O3iaSM4x/3OqYUfKqL54= +github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba h1:Q45EF0k22gMvkDJqWK+CVtufrw32nL/kkJ/AE/jhI0c= +github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= @@ -161,8 +167,6 @@ github.com/jedib0t/go-pretty/v6 v6.6.1 h1:iJ65Xjb680rHcikRj6DSIbzCex2huitmc7bDtx github.com/jedib0t/go-pretty/v6 v6.6.1/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E= github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI= github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw= -github.com/jfrog/build-info-go v1.10.5 h1:cW03JlPlKv7RMUU896uLUxyLWXAmCgR5Y5QX0fwgz0Q= -github.com/jfrog/build-info-go v1.10.5/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE= github.com/jfrog/froggit-go v1.16.2 h1:F//S83iXH14qsCwYzv0zB2JtjS2pJVEsUoEmYA+37dQ= github.com/jfrog/froggit-go v1.16.2/go.mod h1:5VpdQfAcbuyFl9x/x8HGm7kVk719kEtW/8YJFvKcHPA= github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s= @@ -171,12 +175,8 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= github.com/jfrog/jfrog-cli-artifactory v0.1.6 h1:bMfJsrLQJw0dZp4nqUf1xOmtY0rpCatW/I5q88x+fhQ= github.com/jfrog/jfrog-cli-artifactory v0.1.6/go.mod h1:jbNb22ebtupcjdhrdGq0VBew2vWG6VUK04xxGNDfynE= -github.com/jfrog/jfrog-cli-core/v2 v2.56.8 h1:UexulAwRVN20VmYACijkTFYKqtUq5myE4okEgmUrorw= -github.com/jfrog/jfrog-cli-core/v2 v2.56.8/go.mod h1:RY74eDpw1WBxruSfZ0HO1ax7c1NAj+rbBgA/hVOJNME= github.com/jfrog/jfrog-cli-platform-services v1.4.0 h1:g6A30+tOfXd1h6VASeNwH+5mhs5bPQJ0MFzZs/4nlvs= github.com/jfrog/jfrog-cli-platform-services v1.4.0/go.mod h1:Ky4SDXuMeaiNP/5zMT1YSzIuXG+cNYYOl8BaEA7Awbc= -github.com/jfrog/jfrog-cli-security v1.12.5 h1:2JHPyapXuHQw/qEaElGxBUGrJCZlVFLXDdxkqhf10vE= -github.com/jfrog/jfrog-cli-security v1.12.5/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU= github.com/jfrog/jfrog-client-go v1.48.0/go.mod h1:1a7bmQHkRmPEza9wva2+WVrYzrGbosrMymq57kyG5gU= github.com/jszwec/csvutil v1.10.0 h1:upMDUxhQKqZ5ZDCs/wy+8Kib8rZR8I8lOR34yJkdqhI= diff --git a/nuget_test.go b/nuget_test.go index e8b42d2bb..7e0d0e049 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -117,7 +117,7 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe assert.NoError(t, err, "Failed to get current dir") chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath) defer chdirCallback() - args = append(args, "--build-name="+buildName, "--build-number="+buildNumber) + args = append(args, "--build-name="+buildName, "--build-number="+buildNumber, "--allow-insecure-connections") err = runNuGet(t, args...) if err != nil { return @@ -227,7 +227,7 @@ func runInitNewConfig(t *testing.T, testSuite testInitNewConfigDescriptor, baseR SetUseNugetV2(testSuite.useNugetV2) // Prepare the config file with NuGet authentication - configFile, err := dotnet.InitNewConfig(tempDirPath, "", server, testSuite.useNugetV2) + configFile, err := dotnet.InitNewConfig(tempDirPath, "", server, testSuite.useNugetV2, true) if err != nil { assert.NoError(t, err) return diff --git a/utils/cliutils/commandsflags.go b/utils/cliutils/commandsflags.go index 446f84eff..2bfdb1381 100644 --- a/utils/cliutils/commandsflags.go +++ b/utils/cliutils/commandsflags.go @@ -376,7 +376,8 @@ const ( npmDetailedSummary = npmPrefix + detailedSummary // Unique nuget/dotnet config flags - nugetV2 = "nuget-v2" + nugetV2 = "nuget-v2" + allowInsecureConnections = "allow-insecure-connections" // Unique go flags noFallback = "no-fallback" @@ -1161,6 +1162,10 @@ var flagsMap = map[string]cli.Flag{ Name: nugetV2, Usage: "[Default: false] Set to true if you'd like to use the NuGet V2 protocol when restoring packages from Artifactory.` `", }, + allowInsecureConnections: cli.BoolFlag{ + Name: allowInsecureConnections, + Usage: "[Default: false] Set to true if you wish to configure NuGet sources with unsecured connections. This is recommended for testing purposes only. ` `", + }, noFallback: cli.BoolTFlag{ Name: noFallback, Usage: "[Default: false] Set to true to avoid downloading packages from the VCS, if they are missing in Artifactory.` `", @@ -1882,13 +1887,13 @@ var commandFlags = map[string][]string{ global, serverIdResolve, repoResolve, nugetV2, }, Nuget: { - buildName, buildNumber, module, Project, + buildName, buildNumber, module, Project, allowInsecureConnections, }, DotnetConfig: { global, serverIdResolve, repoResolve, nugetV2, }, Dotnet: { - buildName, buildNumber, module, Project, + buildName, buildNumber, module, Project, allowInsecureConnections, }, GoConfig: { global, serverIdResolve, serverIdDeploy, repoResolve, repoDeploy, From 9bc337df05f78bbe6cb2bef16f470626e41d3308 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 14 Nov 2024 12:23:07 +0200 Subject: [PATCH 02/21] apply only for nuget tests --- nuget_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nuget_test.go b/nuget_test.go index 7e0d0e049..2aec5fc35 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -83,7 +83,7 @@ func testNativeNugetDotnetResolve(t *testing.T, uniqueTests []testDescriptor, bu return } t.Run(test.name, func(t *testing.T) { - testNugetCmd(t, projectPath, buildName, strconv.Itoa(buildNumber), test.expectedModules, test.args, test.expectedDependencies) + testNugetCmd(t, projectPath, buildName, strconv.Itoa(buildNumber), test.expectedModules, test.args, test.expectedDependencies, projectType.String()) }) } cleanTestsHomeEnv() @@ -107,17 +107,23 @@ func TestNuGetWithGlobalConfig(t *testing.T) { assert.NoError(t, err) err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NugetRemoteRepo, "", t, project.Nuget, true) assert.NoError(t, err) - testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore"}, []int{6}) + testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore"}, []int{6}, "") cleanTestsHomeEnv() } -func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expectedModule, args []string, expectedDependencies []int) { +func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expectedModule, args []string, expectedDependencies []int, projectType string) { wd, err := os.Getwd() assert.NoError(t, err, "Failed to get current dir") chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath) defer chdirCallback() - args = append(args, "--build-name="+buildName, "--build-number="+buildNumber, "--allow-insecure-connections") + + args = append(args, "--build-name="+buildName, "--build-number="+buildNumber) + + // Add allow insecure connection for testings to work with localhost server + if projectType == "nuget" { + args = append(args, "--allow-insecure-connections") + } err = runNuGet(t, args...) if err != nil { return From 68ea28a3be022ad3ef2bbc06e45c81aaee354407 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 14 Nov 2024 12:31:43 +0200 Subject: [PATCH 03/21] Add flag for test --- nuget_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuget_test.go b/nuget_test.go index 2aec5fc35..fb657cf78 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -107,7 +107,7 @@ func TestNuGetWithGlobalConfig(t *testing.T) { assert.NoError(t, err) err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NugetRemoteRepo, "", t, project.Nuget, true) assert.NoError(t, err) - testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore"}, []int{6}, "") + testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore", "--allow-insecure-connections"}, []int{6}, "") cleanTestsHomeEnv() } From 72035eaa0cab249e2f6ed4e5e85eafc7b19e77df Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 14 Nov 2024 12:43:05 +0200 Subject: [PATCH 04/21] remove unneeded flag --- utils/cliutils/commandsflags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cliutils/commandsflags.go b/utils/cliutils/commandsflags.go index 2bfdb1381..18e6a19d8 100644 --- a/utils/cliutils/commandsflags.go +++ b/utils/cliutils/commandsflags.go @@ -1893,7 +1893,7 @@ var commandFlags = map[string][]string{ global, serverIdResolve, repoResolve, nugetV2, }, Dotnet: { - buildName, buildNumber, module, Project, allowInsecureConnections, + buildName, buildNumber, module, Project, }, GoConfig: { global, serverIdResolve, serverIdDeploy, repoResolve, repoDeploy, From 739e4270595ad3961970d4dbdd199805ac522426 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 14 Nov 2024 12:53:22 +0200 Subject: [PATCH 05/21] Refactor --- buildtools/cli.go | 1 + nuget_test.go | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/buildtools/cli.go b/buildtools/cli.go index 64381ab38..fd6ca8fa4 100644 --- a/buildtools/cli.go +++ b/buildtools/cli.go @@ -1084,6 +1084,7 @@ func getTwineConfigPath() (configFilePath string, err error) { return "", errorutils.CheckErrorf(getMissingConfigErrMsg("twine", "pip-config OR pipenv-config")) } +// Extracts the boolean flag from the args and removes it from the args. func extractBoolFlagFromArgs(filteredNugetArgs *[]string, flagName string) (value bool, err error) { var flagIndex int var allowInsecureConnection bool diff --git a/nuget_test.go b/nuget_test.go index fb657cf78..5ac497fb9 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -107,7 +107,8 @@ func TestNuGetWithGlobalConfig(t *testing.T) { assert.NoError(t, err) err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NugetRemoteRepo, "", t, project.Nuget, true) assert.NoError(t, err) - testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore", "--allow-insecure-connections"}, []int{6}, "") + // allow insecure connection for testings to work with localhost server + testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore", "--allow-insecure-connections"}, []int{6}, project.Nuget.String()) cleanTestsHomeEnv() } @@ -120,10 +121,7 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe args = append(args, "--build-name="+buildName, "--build-number="+buildNumber) - // Add allow insecure connection for testings to work with localhost server - if projectType == "nuget" { - args = append(args, "--allow-insecure-connections") - } + allowInsecureConnectionForTests(projectType, &args) err = runNuGet(t, args...) if err != nil { return @@ -158,6 +156,15 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails) } +// Add allow insecure connection for testings to work with localhost server +// dotNet also uses this cmd, and we want to apply this only for Nuget. +func allowInsecureConnectionForTests(projectType string, args *[]string) *[]string { + if projectType == project.Nuget.String() { + *args = append(*args, "--allow-insecure-connections") + } + return args +} + func assertNugetDependencies(t *testing.T, module buildInfo.Module, moduleName string) { for _, dependency := range module.Dependencies { switch dependency.Id { @@ -230,7 +237,8 @@ func runInitNewConfig(t *testing.T, testSuite testInitNewConfigDescriptor, baseR params := &dotnet.DotnetCommand{} server := &config.ServerDetails{ArtifactoryUrl: baseRtUrl, User: "user", Password: "password"} params.SetServerDetails(server). - SetUseNugetV2(testSuite.useNugetV2) + SetUseNugetV2(testSuite.useNugetV2). + SetAllowInsecureConnections(true) // Prepare the config file with NuGet authentication configFile, err := dotnet.InitNewConfig(tempDirPath, "", server, testSuite.useNugetV2, true) From a446b6836b752ccbca012916decaa37513cf81a9 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 14 Nov 2024 13:04:36 +0200 Subject: [PATCH 06/21] Update deps --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d72531804..c2fa08759 100644 --- a/go.mod +++ b/go.mod @@ -167,7 +167,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114092639-b926209dfcc2 +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114105558-ffd4d869d4b0 replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba diff --git a/go.sum b/go.sum index 96b06d9a6..f13d9bce7 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/CycloneDX/cyclonedx-go v0.9.0 h1:inaif7qD8bivyxp7XLgxUYtOXWtDez7+j72q github.com/CycloneDX/cyclonedx-go v0.9.0/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw= github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded h1:GMCP2b4v6N/tKZBQIwtneO2CJEOmt741VGse5288Im4= github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE= -github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114092639-b926209dfcc2 h1:5EYfXTngSSah4stTK5zrc/2xGZKE+72B4gZvn0nMCHQ= -github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114092639-b926209dfcc2/go.mod h1:Lj9khgWhazp6RoiBk/AJts3O3iaSM4x/3OqYUfKqL54= +github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114105558-ffd4d869d4b0 h1:KP/+ILK0qeTkV+YTG61o0QVKe6l/iczVi41u52qDcGY= +github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241114105558-ffd4d869d4b0/go.mod h1:Lj9khgWhazp6RoiBk/AJts3O3iaSM4x/3OqYUfKqL54= github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba h1:Q45EF0k22gMvkDJqWK+CVtufrw32nL/kkJ/AE/jhI0c= github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= From 3df416955ce85ba1254e3833b123ec06a629be55 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 14 Nov 2024 13:13:35 +0200 Subject: [PATCH 07/21] remove duplication --- nuget_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuget_test.go b/nuget_test.go index 5ac497fb9..c95c39a5b 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -108,7 +108,7 @@ func TestNuGetWithGlobalConfig(t *testing.T) { err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NugetRemoteRepo, "", t, project.Nuget, true) assert.NoError(t, err) // allow insecure connection for testings to work with localhost server - testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore", "--allow-insecure-connections"}, []int{6}, project.Nuget.String()) + testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore"}, []int{6}, project.Nuget.String()) cleanTestsHomeEnv() } From df2772a56385fb2b3eadb02a440931cc50d44c33 Mon Sep 17 00:00:00 2001 From: delarea Date: Mon, 18 Nov 2024 10:39:37 +0200 Subject: [PATCH 08/21] Make extract function generic --- buildtools/cli.go | 14 +------------- utils/cliutils/utils.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/buildtools/cli.go b/buildtools/cli.go index fd6ca8fa4..60ab0baf7 100644 --- a/buildtools/cli.go +++ b/buildtools/cli.go @@ -566,7 +566,7 @@ func NugetCmd(c *cli.Context) error { return err } - allowInsecureConnection, err := extractBoolFlagFromArgs(&filteredNugetArgs, "allow-insecure-connections") + allowInsecureConnection, err := cliutils.ExtractBoolFlagFromArgs(&filteredNugetArgs, "allow-insecure-connections") if err != nil { return err } @@ -1083,15 +1083,3 @@ func getTwineConfigPath() (configFilePath string, err error) { } return "", errorutils.CheckErrorf(getMissingConfigErrMsg("twine", "pip-config OR pipenv-config")) } - -// Extracts the boolean flag from the args and removes it from the args. -func extractBoolFlagFromArgs(filteredNugetArgs *[]string, flagName string) (value bool, err error) { - var flagIndex int - var allowInsecureConnection bool - flagIndex, allowInsecureConnection, err = coreutils.FindBooleanFlag("--"+flagName, *filteredNugetArgs) - if err != nil { - return false, err - } - coreutils.RemoveFlagFromCommand(filteredNugetArgs, flagIndex, flagIndex) - return allowInsecureConnection, nil -} diff --git a/utils/cliutils/utils.go b/utils/cliutils/utils.go index 17781fe50..ac43b25a8 100644 --- a/utils/cliutils/utils.go +++ b/utils/cliutils/utils.go @@ -809,3 +809,15 @@ func getDebFlag(c *cli.Context) (deb string, err error) { } return deb, nil } + +// ExtractBoolFlagFromArgs Extracts a boolean flag from the args and removes it from the slice. +func ExtractBoolFlagFromArgs(filteredArgs *[]string, flagName string) (value bool, err error) { + var flagIndex int + var boolFlag bool + flagIndex, boolFlag, err = coreutils.FindBooleanFlag("--"+flagName, *filteredArgs) + if err != nil { + return false, err + } + coreutils.RemoveFlagFromCommand(filteredArgs, flagIndex, flagIndex) + return boolFlag, nil +} From 39426e28950e4d61ab61abf36c774d60f947a780 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 12:29:35 +0200 Subject: [PATCH 09/21] Add test --- utils/cliutils/utils_test.go | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/utils/cliutils/utils_test.go b/utils/cliutils/utils_test.go index f9bf32b2e..43ce3f203 100644 --- a/utils/cliutils/utils_test.go +++ b/utils/cliutils/utils_test.go @@ -140,3 +140,88 @@ func TestShouldCheckLatestCliVersion(t *testing.T) { assert.NoError(t, err) assert.True(t, shouldCheck) } + +func TestExtractBoolFlagFromArgs(t *testing.T) { + testCases := []struct { + name string + args []string + flagName string + expectedValue bool + expectedErr bool + expectedArgs []string + }{ + { + name: "Flag present as --flagName (implied true)", + args: []string{"somecmd", "--flagName", "otherarg"}, + flagName: "flagName", + expectedValue: true, + expectedErr: false, + expectedArgs: []string{"somecmd", "otherarg"}, + }, + { + name: "Flag present as --flagName=true", + args: []string{"somecmd", "--flagName=true", "otherarg"}, + flagName: "flagName", + expectedValue: true, + expectedErr: false, + expectedArgs: []string{"somecmd", "otherarg"}, + }, + { + name: "Flag present as --flagName=false", + args: []string{"somecmd", "--flagName=false", "otherarg"}, + flagName: "flagName", + expectedValue: false, + expectedErr: false, + expectedArgs: []string{"somecmd", "otherarg"}, + }, + { + name: "Flag not present", + args: []string{"somecmd", "otherarg"}, + flagName: "flagName", + expectedValue: false, + expectedErr: false, + expectedArgs: []string{"somecmd", "otherarg"}, + }, + { + name: "Flag present with invalid value", + args: []string{"somecmd", "--flagName=invalid", "otherarg"}, + flagName: "flagName", + expectedValue: false, + expectedErr: true, + expectedArgs: []string{"somecmd", "--flagName=invalid", "otherarg"}, + }, + { + name: "Flag present as -flagName (should not be found)", + args: []string{"somecmd", "-flagName", "otherarg"}, + flagName: "flagName", + expectedValue: false, + expectedErr: false, + expectedArgs: []string{"somecmd", "-flagName", "otherarg"}, + }, + { + name: "Flag present multiple times", + args: []string{"somecmd", "--flagName", "--flagName=false", "otherarg"}, + flagName: "flagName", + expectedValue: false, + expectedErr: false, + expectedArgs: []string{"somecmd", "--flagName=false", "otherarg"}, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // Make a copy to avoid modifying the original + argsCopy := append([]string(nil), tc.args...) + value, err := ExtractBoolFlagFromArgs(&argsCopy, tc.flagName) + + if tc.expectedErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + + assert.Equal(t, tc.expectedValue, value) + assert.Equal(t, tc.expectedArgs, argsCopy) + }) + } +} From 497d2854d0a9e11c99d3710cd93f43a8127badbf Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 12:32:47 +0200 Subject: [PATCH 10/21] update deps --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index baa75f745..6b248ae97 100644 --- a/go.mod +++ b/go.mod @@ -169,7 +169,7 @@ require ( replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121102240-9fb4156b13e4 -replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba +replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 // replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240918081224-1c584cc334c7 diff --git a/go.sum b/go.sum index 1ca58f50c..541a73357 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0 github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/CycloneDX/cyclonedx-go v0.9.0 h1:inaif7qD8bivyxp7XLgxUYtOXWtDez7+j72qKTMQTb8= github.com/CycloneDX/cyclonedx-go v0.9.0/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw= -github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba h1:Q45EF0k22gMvkDJqWK+CVtufrw32nL/kkJ/AE/jhI0c= -github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241114092834-aff9aaf573ba/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= +github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 h1:oyTvu0FWw+qlEcinSd/8/U+JWR00uQSSa9y0fO+ZVAo= +github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= From 4c692f90ccdbeeaab89e14cc21480d79cb5f1604 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 12:45:41 +0200 Subject: [PATCH 11/21] fix test --- utils/cliutils/utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/cliutils/utils_test.go b/utils/cliutils/utils_test.go index 43ce3f203..e67ec46c7 100644 --- a/utils/cliutils/utils_test.go +++ b/utils/cliutils/utils_test.go @@ -202,7 +202,7 @@ func TestExtractBoolFlagFromArgs(t *testing.T) { name: "Flag present multiple times", args: []string{"somecmd", "--flagName", "--flagName=false", "otherarg"}, flagName: "flagName", - expectedValue: false, + expectedValue: true, expectedErr: false, expectedArgs: []string{"somecmd", "--flagName=false", "otherarg"}, }, From 56c14931d428c9124bec0ef8c08931375e231f4a Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 13:08:58 +0200 Subject: [PATCH 12/21] Update deps --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6b248ae97..9b711129f 100644 --- a/go.mod +++ b/go.mod @@ -167,7 +167,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121102240-9fb4156b13e4 +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121110601-986a8d3e1d2b replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 diff --git a/go.sum b/go.sum index 541a73357..bae5d264d 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0 github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/CycloneDX/cyclonedx-go v0.9.0 h1:inaif7qD8bivyxp7XLgxUYtOXWtDez7+j72qKTMQTb8= github.com/CycloneDX/cyclonedx-go v0.9.0/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw= +github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121110601-986a8d3e1d2b h1:jvU9CikkceJWTHM5Fet0jaDv1QJBiz+Ct7miAFTbupA= +github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121110601-986a8d3e1d2b/go.mod h1:zVyWxMkBpZwy/AvTohefIlaZzYKBMFje+gKKKlkunNo= github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 h1:oyTvu0FWw+qlEcinSd/8/U+JWR00uQSSa9y0fO+ZVAo= github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= @@ -173,8 +175,6 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= github.com/jfrog/jfrog-cli-artifactory v0.1.7 h1:/PBDO6nS6cf3PK+GRkd6BJtZnvYasi1PrQhRiayirso= github.com/jfrog/jfrog-cli-artifactory v0.1.7/go.mod h1:M5pZTHnsYNDmml/FAnoxxt4QiHOIUHPx91th30AtwfM= -github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121102240-9fb4156b13e4 h1:IrqTJxriMtVvENjPiOYHUv0sF+ycun2AcXGXvOfxr6k= -github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121102240-9fb4156b13e4/go.mod h1:zVyWxMkBpZwy/AvTohefIlaZzYKBMFje+gKKKlkunNo= github.com/jfrog/jfrog-cli-platform-services v1.4.0 h1:g6A30+tOfXd1h6VASeNwH+5mhs5bPQJ0MFzZs/4nlvs= github.com/jfrog/jfrog-cli-platform-services v1.4.0/go.mod h1:Ky4SDXuMeaiNP/5zMT1YSzIuXG+cNYYOl8BaEA7Awbc= github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU= From 5036989b0a600ed43c9b7826fed1dff3cf8b19a5 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 16:12:11 +0200 Subject: [PATCH 13/21] change order --- nuget_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuget_test.go b/nuget_test.go index c95c39a5b..5276f71e8 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -119,9 +119,9 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath) defer chdirCallback() + allowInsecureConnectionForTests(projectType, &args) args = append(args, "--build-name="+buildName, "--build-number="+buildNumber) - allowInsecureConnectionForTests(projectType, &args) err = runNuGet(t, args...) if err != nil { return From 07e36abe8247a69fa62199d182be35db12193533 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 16:39:07 +0200 Subject: [PATCH 14/21] test windows --- nuget_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nuget_test.go b/nuget_test.go index 5276f71e8..2f825378e 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -4,6 +4,7 @@ import ( "encoding/xml" "os" "path/filepath" + "runtime" "strconv" "strings" "testing" @@ -72,7 +73,7 @@ func testNativeNugetDotnetResolve(t *testing.T, uniqueTests []testDescriptor, bu {"multireferencewithmodulechnage", "multireference", []string{projectType.String(), "restore", "--module=" + ModuleNameJFrogTest}, []string{ModuleNameJFrogTest}, []int{6}}, {"multireferencewithslnpath", "multireference", []string{projectType.String(), "restore", "src/multireference.sln"}, []string{"proj1", "proj2"}, []int{5, 3}}, {"multireferencewithslndir", "multireference", []string{projectType.String(), "restore", "src/"}, []string{"proj1", "proj2"}, []int{5, 3}}, - {"multireferencesingleprojectcsproj", "multireference", []string{projectType.String(), "restore", "src/multireference.proj2/proj2.csproj"}, []string{"proj2"}, []int{3}}, + {"multireferencesingleprojectcsproj", "multireference", []string{projectType.String(), "restore", "--allow-insecure-connections", "src/multireference.proj2/proj2.csproj"}, []string{"proj2"}, []int{3}}, {"sln_and_proj_different_locations", "differentlocations", []string{projectType.String(), "restore", "solutions/differentlocations.sln"}, []string{"proj1", "proj2"}, []int{5, 3}}, }...) for buildNumber, test := range testDescriptors { @@ -119,8 +120,8 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath) defer chdirCallback() - allowInsecureConnectionForTests(projectType, &args) args = append(args, "--build-name="+buildName, "--build-number="+buildNumber) + allowInsecureConnectionForTests(projectType, &args) err = runNuGet(t, args...) if err != nil { @@ -159,7 +160,7 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe // Add allow insecure connection for testings to work with localhost server // dotNet also uses this cmd, and we want to apply this only for Nuget. func allowInsecureConnectionForTests(projectType string, args *[]string) *[]string { - if projectType == project.Nuget.String() { + if projectType == project.Nuget.String() || runtime.GOOS == "windows" { *args = append(*args, "--allow-insecure-connections") } return args From 4501822330f63e7a600870d36ea383baf2866553 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 16:59:29 +0200 Subject: [PATCH 15/21] revert windows --- nuget_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nuget_test.go b/nuget_test.go index 2f825378e..c9b170c66 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -4,7 +4,6 @@ import ( "encoding/xml" "os" "path/filepath" - "runtime" "strconv" "strings" "testing" @@ -160,7 +159,7 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe // Add allow insecure connection for testings to work with localhost server // dotNet also uses this cmd, and we want to apply this only for Nuget. func allowInsecureConnectionForTests(projectType string, args *[]string) *[]string { - if projectType == project.Nuget.String() || runtime.GOOS == "windows" { + if projectType == project.Nuget.String() { *args = append(*args, "--allow-insecure-connections") } return args From 0d6e6c625706675dec6ed3eb16dcb3e1e4d6de3e Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 17:03:25 +0200 Subject: [PATCH 16/21] test --- nuget_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuget_test.go b/nuget_test.go index c9b170c66..b56c5b42f 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -83,7 +83,7 @@ func testNativeNugetDotnetResolve(t *testing.T, uniqueTests []testDescriptor, bu return } t.Run(test.name, func(t *testing.T) { - testNugetCmd(t, projectPath, buildName, strconv.Itoa(buildNumber), test.expectedModules, test.args, test.expectedDependencies, projectType.String()) + testNugetCmd(t, projectPath, buildName, strconv.Itoa(buildNumber), test.expectedModules, test.args, test.expectedDependencies, project.Nuget.String()) }) } cleanTestsHomeEnv() From ed79e959f56b53657f59ad47c7c5932210c92c65 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 17:22:07 +0200 Subject: [PATCH 17/21] test --- nuget_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuget_test.go b/nuget_test.go index b56c5b42f..6ccd7a7da 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -72,7 +72,7 @@ func testNativeNugetDotnetResolve(t *testing.T, uniqueTests []testDescriptor, bu {"multireferencewithmodulechnage", "multireference", []string{projectType.String(), "restore", "--module=" + ModuleNameJFrogTest}, []string{ModuleNameJFrogTest}, []int{6}}, {"multireferencewithslnpath", "multireference", []string{projectType.String(), "restore", "src/multireference.sln"}, []string{"proj1", "proj2"}, []int{5, 3}}, {"multireferencewithslndir", "multireference", []string{projectType.String(), "restore", "src/"}, []string{"proj1", "proj2"}, []int{5, 3}}, - {"multireferencesingleprojectcsproj", "multireference", []string{projectType.String(), "restore", "--allow-insecure-connections", "src/multireference.proj2/proj2.csproj"}, []string{"proj2"}, []int{3}}, + {"multireferencesingleprojectcsproj", "multireference", []string{projectType.String(), "restore", "src/multireference.proj2/proj2.csproj"}, []string{"proj2"}, []int{3}}, {"sln_and_proj_different_locations", "differentlocations", []string{projectType.String(), "restore", "solutions/differentlocations.sln"}, []string{"proj1", "proj2"}, []int{5, 3}}, }...) for buildNumber, test := range testDescriptors { From acdb731b455c270202d5801a9117222b10734c03 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 17:24:00 +0200 Subject: [PATCH 18/21] update deps --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9b711129f..c2b9b16dc 100644 --- a/go.mod +++ b/go.mod @@ -167,7 +167,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121110601-986a8d3e1d2b +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121152206-476891797b85 replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 diff --git a/go.sum b/go.sum index bae5d264d..94e8836d0 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0 github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/CycloneDX/cyclonedx-go v0.9.0 h1:inaif7qD8bivyxp7XLgxUYtOXWtDez7+j72qKTMQTb8= github.com/CycloneDX/cyclonedx-go v0.9.0/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw= -github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121110601-986a8d3e1d2b h1:jvU9CikkceJWTHM5Fet0jaDv1QJBiz+Ct7miAFTbupA= -github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121110601-986a8d3e1d2b/go.mod h1:zVyWxMkBpZwy/AvTohefIlaZzYKBMFje+gKKKlkunNo= +github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121152206-476891797b85 h1:VkhD6xbhAITKj40Ef6ty3Lqmf2mhe2cgeFIxXno9QRo= +github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121152206-476891797b85/go.mod h1:zVyWxMkBpZwy/AvTohefIlaZzYKBMFje+gKKKlkunNo= github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 h1:oyTvu0FWw+qlEcinSd/8/U+JWR00uQSSa9y0fO+ZVAo= github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= From 463ea52aa06be01fee843fbbe22fd0f389b86c65 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 17:31:42 +0200 Subject: [PATCH 19/21] set test project type --- nuget_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nuget_test.go b/nuget_test.go index 6ccd7a7da..d9791082d 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -83,7 +83,7 @@ func testNativeNugetDotnetResolve(t *testing.T, uniqueTests []testDescriptor, bu return } t.Run(test.name, func(t *testing.T) { - testNugetCmd(t, projectPath, buildName, strconv.Itoa(buildNumber), test.expectedModules, test.args, test.expectedDependencies, project.Nuget.String()) + testNugetCmd(t, projectPath, buildName, strconv.Itoa(buildNumber), test.expectedModules, test.args, test.expectedDependencies, projectType.String()) }) } cleanTestsHomeEnv() @@ -119,8 +119,8 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath) defer chdirCallback() - args = append(args, "--build-name="+buildName, "--build-number="+buildNumber) allowInsecureConnectionForTests(projectType, &args) + args = append(args, "--build-name="+buildName, "--build-number="+buildNumber) err = runNuGet(t, args...) if err != nil { @@ -239,8 +239,8 @@ func runInitNewConfig(t *testing.T, testSuite testInitNewConfigDescriptor, baseR params.SetServerDetails(server). SetUseNugetV2(testSuite.useNugetV2). SetAllowInsecureConnections(true) - // Prepare the config file with NuGet authentication + // Prepare the config file with NuGet authentication configFile, err := dotnet.InitNewConfig(tempDirPath, "", server, testSuite.useNugetV2, true) if err != nil { assert.NoError(t, err) From 58a5308e2642b877a8efc026d3b33932ba172168 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 17:56:00 +0200 Subject: [PATCH 20/21] add dotnet flag --- buildtools/cli.go | 7 ++++++- nuget_test.go | 15 ++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/buildtools/cli.go b/buildtools/cli.go index 60ab0baf7..02eee938a 100644 --- a/buildtools/cli.go +++ b/buildtools/cli.go @@ -613,10 +613,15 @@ func DotnetCmd(c *cli.Context) error { return err } + allowInsecureConnection, err := cliutils.ExtractBoolFlagFromArgs(&filteredDotnetArgs, "allow-insecure-connections") + if err != nil { + return err + } + // Run command. dotnetCmd := dotnet.NewDotnetCoreCliCommand() dotnetCmd.SetServerDetails(rtDetails).SetRepoName(targetRepo).SetBuildConfiguration(buildConfiguration). - SetBasicCommand(filteredDotnetArgs[0]).SetUseNugetV2(useNugetV2) + SetBasicCommand(filteredDotnetArgs[0]).SetUseNugetV2(useNugetV2).SetAllowInsecureConnections(allowInsecureConnection) // Since we are using the values of the command's arguments and flags along the buildInfo collection process, // we want to separate the actual .NET basic command (restore/build...) from the arguments and flags if len(filteredDotnetArgs) > 1 { diff --git a/nuget_test.go b/nuget_test.go index d9791082d..bf1235a37 100644 --- a/nuget_test.go +++ b/nuget_test.go @@ -83,7 +83,7 @@ func testNativeNugetDotnetResolve(t *testing.T, uniqueTests []testDescriptor, bu return } t.Run(test.name, func(t *testing.T) { - testNugetCmd(t, projectPath, buildName, strconv.Itoa(buildNumber), test.expectedModules, test.args, test.expectedDependencies, projectType.String()) + testNugetCmd(t, projectPath, buildName, strconv.Itoa(buildNumber), test.expectedModules, test.args, test.expectedDependencies) }) } cleanTestsHomeEnv() @@ -108,18 +108,18 @@ func TestNuGetWithGlobalConfig(t *testing.T) { err = createConfigFileForTest([]string{jfrogHomeDir}, tests.NugetRemoteRepo, "", t, project.Nuget, true) assert.NoError(t, err) // allow insecure connection for testings to work with localhost server - testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore"}, []int{6}, project.Nuget.String()) + testNugetCmd(t, projectPath, tests.NuGetBuildName, "1", []string{"packagesconfig"}, []string{"nuget", "restore"}, []int{6}) cleanTestsHomeEnv() } -func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expectedModule, args []string, expectedDependencies []int, projectType string) { +func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expectedModule, args []string, expectedDependencies []int) { wd, err := os.Getwd() assert.NoError(t, err, "Failed to get current dir") chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath) defer chdirCallback() - allowInsecureConnectionForTests(projectType, &args) + allowInsecureConnectionForTests(&args) args = append(args, "--build-name="+buildName, "--build-number="+buildNumber) err = runNuGet(t, args...) @@ -157,11 +157,8 @@ func testNugetCmd(t *testing.T, projectPath, buildName, buildNumber string, expe } // Add allow insecure connection for testings to work with localhost server -// dotNet also uses this cmd, and we want to apply this only for Nuget. -func allowInsecureConnectionForTests(projectType string, args *[]string) *[]string { - if projectType == project.Nuget.String() { - *args = append(*args, "--allow-insecure-connections") - } +func allowInsecureConnectionForTests(args *[]string) *[]string { + *args = append(*args, "--allow-insecure-connections") return args } From ab5a372b9e57363fcaf679086d49e892ad8194e6 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 18:33:10 +0200 Subject: [PATCH 21/21] Update deps to devs --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c2b9b16dc..cfab56ecb 100644 --- a/go.mod +++ b/go.mod @@ -167,7 +167,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121152206-476891797b85 +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121163158-04daeb8132c3 replace github.com/jfrog/jfrog-cli-security => github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 diff --git a/go.sum b/go.sum index 94e8836d0..9692db858 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,6 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0 github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/CycloneDX/cyclonedx-go v0.9.0 h1:inaif7qD8bivyxp7XLgxUYtOXWtDez7+j72qKTMQTb8= github.com/CycloneDX/cyclonedx-go v0.9.0/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw= -github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121152206-476891797b85 h1:VkhD6xbhAITKj40Ef6ty3Lqmf2mhe2cgeFIxXno9QRo= -github.com/EyalDelarea/jfrog-cli-core/v2 v2.0.0-20241121152206-476891797b85/go.mod h1:zVyWxMkBpZwy/AvTohefIlaZzYKBMFje+gKKKlkunNo= github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02 h1:oyTvu0FWw+qlEcinSd/8/U+JWR00uQSSa9y0fO+ZVAo= github.com/EyalDelarea/jfrog-cli-security v0.0.0-20241121103043-02719f295f02/go.mod h1:5LBGwth7TXkEH8MO0JJXvpoRktMAV2BK7Q5nQePNrv4= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= @@ -175,6 +173,8 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= github.com/jfrog/jfrog-cli-artifactory v0.1.7 h1:/PBDO6nS6cf3PK+GRkd6BJtZnvYasi1PrQhRiayirso= github.com/jfrog/jfrog-cli-artifactory v0.1.7/go.mod h1:M5pZTHnsYNDmml/FAnoxxt4QiHOIUHPx91th30AtwfM= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121163158-04daeb8132c3 h1:cJSPTMflqE+ucC/h2/BB6BkVxz3BG8PnivCb00Dxt/Y= +github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20241121163158-04daeb8132c3/go.mod h1:zVyWxMkBpZwy/AvTohefIlaZzYKBMFje+gKKKlkunNo= github.com/jfrog/jfrog-cli-platform-services v1.4.0 h1:g6A30+tOfXd1h6VASeNwH+5mhs5bPQJ0MFzZs/4nlvs= github.com/jfrog/jfrog-cli-platform-services v1.4.0/go.mod h1:Ky4SDXuMeaiNP/5zMT1YSzIuXG+cNYYOl8BaEA7Awbc= github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU=