Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion artifactory/commands/dotnet/dotnetcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ Note that JFrog CLI does not restore dependencies during a 'dotnet test' command
The initial error is:
`
noRestoreFlag = "--no-restore"

configFileFormatNoCredentials = `<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="` + SourceName + `" value="%s" protocolVersion="%s" allowInsecureConnections="%t"/>
</packageSources>
</configuration>`
)

type DotnetCommand struct {
Expand Down Expand Up @@ -321,7 +328,11 @@ func addSourceToNugetTemplate(configFile *os.File, server *config.ServerDetails,
}

// Format the templates
_, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, allowInsecureConnections, user, password)
if user == "" && password == "" {
_, err = fmt.Fprintf(configFile, configFileFormatNoCredentials, sourceUrl, protoVer, allowInsecureConnections)
} else {
_, err = fmt.Fprintf(configFile, dotnet.ConfigFileFormat, sourceUrl, protoVer, allowInsecureConnections, user, password)
}
return err
}

Expand Down
28 changes: 28 additions & 0 deletions artifactory/commands/dotnet/dotnetcommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,34 @@ func TestInitNewConfig(t *testing.T) {
</configuration>`, string(buf[:n]))
}

func TestInitNewConfigNoCredentials(t *testing.T) {
tmpDir, err := fileutils.CreateTempDir()
assert.NoError(t, err)
defer func() {
assert.NoError(t, fileutils.RemoveTempDir(tmpDir))
}()
repoName := "test-repo"
server := &config.ServerDetails{
ArtifactoryUrl: "https://server.com/artifactory",
}
configFile, err := InitNewConfig(tmpDir, repoName, server, false, false)
assert.NoError(t, err)
f, err := os.Open(filepath.Clean(configFile.Name())) // #nosec G703 -- test file path
assert.NoError(t, err)
defer func() {
assert.NoError(t, f.Close())
}()
buf := make([]byte, 1024)
n, err := f.Read(buf)
assert.NoError(t, err)
assert.Equal(t, `<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="JFrogCli" value="https://server.com/artifactory/api/nuget/v3/test-repo/index.json" protocolVersion="3" allowInsecureConnections="false"/>
</packageSources>
</configuration>`, string(buf[:n]))
}

func TestGetSourceDetails(t *testing.T) {
server := &config.ServerDetails{
ArtifactoryUrl: "https://server.com/artifactory",
Expand Down
Loading