From b926209dfcc24aab02988b0670f08ba04a38adec Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 14 Nov 2024 11:26:39 +0200 Subject: [PATCH 1/3] Fix Nuget tests by setting insecured TLS for localhost testings --- artifactory/commands/dotnet/dotnetcommand.go | 33 +++++++++++-------- .../commands/dotnet/dotnetcommand_test.go | 19 ++++++----- go.mod | 2 +- go.sum | 4 +-- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/artifactory/commands/dotnet/dotnetcommand.go b/artifactory/commands/dotnet/dotnetcommand.go index a51d62c2e..0264dc730 100644 --- a/artifactory/commands/dotnet/dotnetcommand.go +++ b/artifactory/commands/dotnet/dotnetcommand.go @@ -30,14 +30,16 @@ The initial error is: ) type DotnetCommand struct { - toolchainType dotnet.ToolchainType - subCommand string - argAndFlags []string - repoName string - solutionPath string - useNugetV2 bool - buildConfiguration *commonBuild.BuildConfiguration - serverDetails *config.ServerDetails + toolchainType dotnet.ToolchainType + subCommand string + argAndFlags []string + repoName string + solutionPath string + useNugetV2 bool + // Used mostly for testings, allow insecured conntions sources. + allowInsecureConnections bool + buildConfiguration *commonBuild.BuildConfiguration + serverDetails *config.ServerDetails } func (dc *DotnetCommand) SetServerDetails(serverDetails *config.ServerDetails) *DotnetCommand { @@ -70,6 +72,11 @@ func (dc *DotnetCommand) SetUseNugetV2(useNugetV2 bool) *DotnetCommand { return dc } +func (dc *DotnetCommand) SetAllowInsecureConnections(allowInsecureConnections bool) *DotnetCommand { + dc.allowInsecureConnections = allowInsecureConnections + return dc +} + func (dc *DotnetCommand) SetArgAndFlags(argAndFlags []string) *DotnetCommand { dc.argAndFlags = argAndFlags return dc @@ -219,7 +226,7 @@ func (dc *DotnetCommand) prepareConfigFileIfNeeded() (cleanup func() error, err return fileutils.RemoveTempDir(tempDirPath) } - configFile, err := InitNewConfig(tempDirPath, dc.repoName, dc.serverDetails, dc.useNugetV2) + configFile, err := InitNewConfig(tempDirPath, dc.repoName, dc.serverDetails, dc.useNugetV2, dc.allowInsecureConnections) if err == nil { dc.argAndFlags = append(dc.argAndFlags, dc.GetToolchain().GetTypeFlagPrefix()+"configfile", configFile.Name()) } @@ -246,7 +253,7 @@ func getFlagValueIfExists(cmdFlag string, argAndFlags []string) (string, error) } // InitNewConfig is used when neither of the flags were provided, and we need to init our own config. -func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails, useNugetV2 bool) (configFile *os.File, err error) { +func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails, useNugetV2, allowInsecureConnections bool) (configFile *os.File, err error) { // Initializing a new NuGet config file that NuGet will use into a temp file configFile, err = os.CreateTemp(configDirPath, configFilePattern) if errorutils.CheckError(err) != nil { @@ -260,12 +267,12 @@ func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails, // We would prefer to write the NuGet configuration using the `nuget add source` command, // but the NuGet configuration utility doesn't currently allow setting protocolVersion. // Until that is supported, the templated method must be used. - err = addSourceToNugetTemplate(configFile, server, useNugetV2, repoName) + err = addSourceToNugetTemplate(configFile, server, useNugetV2, repoName, allowInsecureConnections) return } // Adds a source to the nuget config template -func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails, useNugetV2 bool, repoName string) error { +func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails, useNugetV2 bool, repoName string, allowInsecureConnections bool) error { sourceUrl, user, password, err := getSourceDetails(server, repoName, useNugetV2) if err != nil { return err @@ -278,7 +285,7 @@ func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails, } // Format the templates - _, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, user, password) + _, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, allowInsecureConnections, user, password) return err } diff --git a/artifactory/commands/dotnet/dotnetcommand_test.go b/artifactory/commands/dotnet/dotnetcommand_test.go index a89fade31..86f3c7649 100644 --- a/artifactory/commands/dotnet/dotnetcommand_test.go +++ b/artifactory/commands/dotnet/dotnetcommand_test.go @@ -74,7 +74,7 @@ func TestInitNewConfig(t *testing.T) { User: "user", Password: "pass", } - configFile, err := InitNewConfig(tmpDir, repoName, server, false) + configFile, err := InitNewConfig(tmpDir, repoName, server, false, true) assert.NoError(t, err) f, err := os.Open(configFile.Name()) assert.NoError(t, err) @@ -87,7 +87,7 @@ func TestInitNewConfig(t *testing.T) { assert.Equal(t, ` - + @@ -98,7 +98,7 @@ func TestInitNewConfig(t *testing.T) { `, string(buf[:n])) server.Password = "" server.AccessToken = "abc123" - configFile, err = InitNewConfig(tmpDir, repoName, server, true) + configFile, err = InitNewConfig(tmpDir, repoName, server, true, false) assert.NoError(t, err) updatedConfigFile, err := os.Open(configFile.Name()) assert.NoError(t, err) @@ -111,7 +111,7 @@ func TestInitNewConfig(t *testing.T) { assert.Equal(t, ` - + @@ -164,11 +164,12 @@ func testPrepareDotnetBuildInfoModule(t *testing.T, subCommand string, flags []s }() module := createNewDotnetModule(t, tmpDir) cmd := DotnetCommand{ - toolchainType: dotnet.DotnetCore, - subCommand: subCommand, - argAndFlags: flags, - buildConfiguration: buildUtils.NewBuildConfiguration("", "", "mod", ""), - serverDetails: &config.ServerDetails{ArtifactoryUrl: "https://my-instance.jfrog.io"}, + toolchainType: dotnet.DotnetCore, + subCommand: subCommand, + argAndFlags: flags, + buildConfiguration: buildUtils.NewBuildConfiguration("", "", "mod", ""), + serverDetails: &config.ServerDetails{ArtifactoryUrl: "https://my-instance.jfrog.io"}, + allowInsecureConnections: true, } callbackFunc, err := cmd.prepareDotnetBuildInfoModule(module) if !assert.NoError(t, err) { diff --git a/go.mod b/go.mod index 88b7368e4..812532ade 100644 --- a/go.mod +++ b/go.mod @@ -98,6 +98,6 @@ require ( // replace github.com/jfrog/jfrog-client-go => github.com/eyalbe4/jfrog-client-go v1.28.1-0.20241103083749-45c13ff7fe16 -// replace github.com/jfrog/build-info-go => github.com/galusben/build-info-go v0.0.0-20240930113238-ac3b31030284 +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 v1.3.3-0.20231223133729-ef57bd08cedc diff --git a/go.sum b/go.sum index 26c80cd3a..7f60be0ee 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,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/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/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= @@ -89,8 +91,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/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s= github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4= github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU= From ffd4d869d4b03919d10f5ec262990f24ab2dfda9 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 14 Nov 2024 12:55:58 +0200 Subject: [PATCH 2/3] Edit comment --- artifactory/commands/dotnet/dotnetcommand.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/artifactory/commands/dotnet/dotnetcommand.go b/artifactory/commands/dotnet/dotnetcommand.go index 0264dc730..c8d35a4d6 100644 --- a/artifactory/commands/dotnet/dotnetcommand.go +++ b/artifactory/commands/dotnet/dotnetcommand.go @@ -36,7 +36,7 @@ type DotnetCommand struct { repoName string solutionPath string useNugetV2 bool - // Used mostly for testings, allow insecured conntions sources. + // By default, package sources are required to use HTTPS. This option allows sources to use HTTP. allowInsecureConnections bool buildConfiguration *commonBuild.BuildConfiguration serverDetails *config.ServerDetails From f72a875c7e23efd6cf50289e42234f83b0af74c3 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 21 Nov 2024 12:10:51 +0200 Subject: [PATCH 3/3] update deps --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 812532ade..b186c18ea 100644 --- a/go.mod +++ b/go.mod @@ -98,6 +98,6 @@ require ( // replace github.com/jfrog/jfrog-client-go => github.com/eyalbe4/jfrog-client-go v1.28.1-0.20241103083749-45c13ff7fe16 -replace github.com/jfrog/build-info-go => github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded +replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd // replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.3.3-0.20231223133729-ef57bd08cedc diff --git a/go.sum b/go.sum index 7f60be0ee..b93e2e890 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,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/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/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= @@ -91,6 +89,8 @@ 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.8.9-0.20241121100855-e7a75ceee2bd h1:PzxnJ1mjHIL4bAC4RPm87WnJ1TZXFBicyOhtIHRQH6g= +github.com/jfrog/build-info-go v1.8.9-0.20241121100855-e7a75ceee2bd/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE= github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s= github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4= github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU=