Skip to content

Commit b926209

Browse files
committed
Fix Nuget tests by setting insecured TLS for localhost testings
1 parent 24197a7 commit b926209

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

artifactory/commands/dotnet/dotnetcommand.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ The initial error is:
3030
)
3131

3232
type DotnetCommand struct {
33-
toolchainType dotnet.ToolchainType
34-
subCommand string
35-
argAndFlags []string
36-
repoName string
37-
solutionPath string
38-
useNugetV2 bool
39-
buildConfiguration *commonBuild.BuildConfiguration
40-
serverDetails *config.ServerDetails
33+
toolchainType dotnet.ToolchainType
34+
subCommand string
35+
argAndFlags []string
36+
repoName string
37+
solutionPath string
38+
useNugetV2 bool
39+
// Used mostly for testings, allow insecured conntions sources.
40+
allowInsecureConnections bool
41+
buildConfiguration *commonBuild.BuildConfiguration
42+
serverDetails *config.ServerDetails
4143
}
4244

4345
func (dc *DotnetCommand) SetServerDetails(serverDetails *config.ServerDetails) *DotnetCommand {
@@ -70,6 +72,11 @@ func (dc *DotnetCommand) SetUseNugetV2(useNugetV2 bool) *DotnetCommand {
7072
return dc
7173
}
7274

75+
func (dc *DotnetCommand) SetAllowInsecureConnections(allowInsecureConnections bool) *DotnetCommand {
76+
dc.allowInsecureConnections = allowInsecureConnections
77+
return dc
78+
}
79+
7380
func (dc *DotnetCommand) SetArgAndFlags(argAndFlags []string) *DotnetCommand {
7481
dc.argAndFlags = argAndFlags
7582
return dc
@@ -219,7 +226,7 @@ func (dc *DotnetCommand) prepareConfigFileIfNeeded() (cleanup func() error, err
219226
return fileutils.RemoveTempDir(tempDirPath)
220227
}
221228

222-
configFile, err := InitNewConfig(tempDirPath, dc.repoName, dc.serverDetails, dc.useNugetV2)
229+
configFile, err := InitNewConfig(tempDirPath, dc.repoName, dc.serverDetails, dc.useNugetV2, dc.allowInsecureConnections)
223230
if err == nil {
224231
dc.argAndFlags = append(dc.argAndFlags, dc.GetToolchain().GetTypeFlagPrefix()+"configfile", configFile.Name())
225232
}
@@ -246,7 +253,7 @@ func getFlagValueIfExists(cmdFlag string, argAndFlags []string) (string, error)
246253
}
247254

248255
// InitNewConfig is used when neither of the flags were provided, and we need to init our own config.
249-
func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails, useNugetV2 bool) (configFile *os.File, err error) {
256+
func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails, useNugetV2, allowInsecureConnections bool) (configFile *os.File, err error) {
250257
// Initializing a new NuGet config file that NuGet will use into a temp file
251258
configFile, err = os.CreateTemp(configDirPath, configFilePattern)
252259
if errorutils.CheckError(err) != nil {
@@ -260,12 +267,12 @@ func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails,
260267
// We would prefer to write the NuGet configuration using the `nuget add source` command,
261268
// but the NuGet configuration utility doesn't currently allow setting protocolVersion.
262269
// Until that is supported, the templated method must be used.
263-
err = addSourceToNugetTemplate(configFile, server, useNugetV2, repoName)
270+
err = addSourceToNugetTemplate(configFile, server, useNugetV2, repoName, allowInsecureConnections)
264271
return
265272
}
266273

267274
// Adds a source to the nuget config template
268-
func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails, useNugetV2 bool, repoName string) error {
275+
func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails, useNugetV2 bool, repoName string, allowInsecureConnections bool) error {
269276
sourceUrl, user, password, err := getSourceDetails(server, repoName, useNugetV2)
270277
if err != nil {
271278
return err
@@ -278,7 +285,7 @@ func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails,
278285
}
279286

280287
// Format the templates
281-
_, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, user, password)
288+
_, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, allowInsecureConnections, user, password)
282289
return err
283290
}
284291

artifactory/commands/dotnet/dotnetcommand_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestInitNewConfig(t *testing.T) {
7474
User: "user",
7575
Password: "pass",
7676
}
77-
configFile, err := InitNewConfig(tmpDir, repoName, server, false)
77+
configFile, err := InitNewConfig(tmpDir, repoName, server, false, true)
7878
assert.NoError(t, err)
7979
f, err := os.Open(configFile.Name())
8080
assert.NoError(t, err)
@@ -87,7 +87,7 @@ func TestInitNewConfig(t *testing.T) {
8787
assert.Equal(t, `<?xml version="1.0" encoding="utf-8"?>
8888
<configuration>
8989
<packageSources>
90-
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/v3/test-repo" protocolVersion="3" />
90+
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/v3/test-repo" protocolVersion="3" allowInsecureConnections="true"/>
9191
</packageSources>
9292
<packageSourceCredentials>
9393
<JFrogCli>
@@ -98,7 +98,7 @@ func TestInitNewConfig(t *testing.T) {
9898
</configuration>`, string(buf[:n]))
9999
server.Password = ""
100100
server.AccessToken = "abc123"
101-
configFile, err = InitNewConfig(tmpDir, repoName, server, true)
101+
configFile, err = InitNewConfig(tmpDir, repoName, server, true, false)
102102
assert.NoError(t, err)
103103
updatedConfigFile, err := os.Open(configFile.Name())
104104
assert.NoError(t, err)
@@ -111,7 +111,7 @@ func TestInitNewConfig(t *testing.T) {
111111
assert.Equal(t, `<?xml version="1.0" encoding="utf-8"?>
112112
<configuration>
113113
<packageSources>
114-
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/test-repo" protocolVersion="2" />
114+
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/test-repo" protocolVersion="2" allowInsecureConnections="false"/>
115115
</packageSources>
116116
<packageSourceCredentials>
117117
<JFrogCli>
@@ -164,11 +164,12 @@ func testPrepareDotnetBuildInfoModule(t *testing.T, subCommand string, flags []s
164164
}()
165165
module := createNewDotnetModule(t, tmpDir)
166166
cmd := DotnetCommand{
167-
toolchainType: dotnet.DotnetCore,
168-
subCommand: subCommand,
169-
argAndFlags: flags,
170-
buildConfiguration: buildUtils.NewBuildConfiguration("", "", "mod", ""),
171-
serverDetails: &config.ServerDetails{ArtifactoryUrl: "https://my-instance.jfrog.io"},
167+
toolchainType: dotnet.DotnetCore,
168+
subCommand: subCommand,
169+
argAndFlags: flags,
170+
buildConfiguration: buildUtils.NewBuildConfiguration("", "", "mod", ""),
171+
serverDetails: &config.ServerDetails{ArtifactoryUrl: "https://my-instance.jfrog.io"},
172+
allowInsecureConnections: true,
172173
}
173174
callbackFunc, err := cmd.prepareDotnetBuildInfoModule(module)
174175
if !assert.NoError(t, err) {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,6 @@ require (
9898

9999
// replace github.com/jfrog/jfrog-client-go => github.com/eyalbe4/jfrog-client-go v1.28.1-0.20241103083749-45c13ff7fe16
100100

101-
// replace github.com/jfrog/build-info-go => github.com/galusben/build-info-go v0.0.0-20240930113238-ac3b31030284
101+
replace github.com/jfrog/build-info-go => github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded
102102

103103
// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.3.3-0.20231223133729-ef57bd08cedc

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0
44
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
55
github.com/CycloneDX/cyclonedx-go v0.9.0 h1:inaif7qD8bivyxp7XLgxUYtOXWtDez7+j72qKTMQTb8=
66
github.com/CycloneDX/cyclonedx-go v0.9.0/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw=
7+
github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded h1:GMCP2b4v6N/tKZBQIwtneO2CJEOmt741VGse5288Im4=
8+
github.com/EyalDelarea/build-info-go v0.0.0-20241114092335-1c47774e5ded/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
79
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
810
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
911
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
8991
github.com/jedib0t/go-pretty/v6 v6.6.1/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
9092
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
9193
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
92-
github.com/jfrog/build-info-go v1.10.5 h1:cW03JlPlKv7RMUU896uLUxyLWXAmCgR5Y5QX0fwgz0Q=
93-
github.com/jfrog/build-info-go v1.10.5/go.mod h1:JcISnovFXKx3wWf3p1fcMmlPdt6adxScXvoJN4WXqIE=
9494
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
9595
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
9696
github.com/jfrog/jfrog-client-go v1.48.0 h1:hx5B7+Wnobmzq4aFVZtALtbEVDFcjpn0Wb4q2m6H4KU=

0 commit comments

Comments
 (0)