Skip to content
Open
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
3 changes: 2 additions & 1 deletion commands/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -1100,7 +1101,7 @@ func processScanResults(params *AuditParams, cmdResults *results.SecurityCommand
if err != nil {
return cmdResults.AddGeneralError(fmt.Errorf("failed to upload scan results to Artifactory: %s", err.Error()), false)
}
cmdResults.SetUploadedArtifactPath(filepath.Join(params.GetRtResultRepositoryWithProjectKey(), uploadPath))
cmdResults.SetUploadedArtifactPath(path.Join(params.GetRtResultRepositoryWithProjectKey(), uploadPath))
if uiRoute, err := getScanResultsUiRoute(params, uploadPath); err != nil {
log.Warn(fmt.Sprintf("failed to get scan results UI route: %s", err.Error()))
} else if uiRoute != "" {
Expand Down
13 changes: 7 additions & 6 deletions utils/results/output/reportartifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package output
import (
"fmt"
"net/url"
"path/filepath"
"path"
"strings"

"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
Expand Down Expand Up @@ -87,13 +88,13 @@ func uploadViaArtifactoryDirect(serverDetails *config.ServerDetails, rtResultRep
SetContentToUpload(cdxResults).
SetFilePrefix(string(cmdType)).
SetServerDetails(serverDetails).
SetUploadRepository(filepath.ToSlash(filepath.Join(rtResultRepository, artifactFinalRepoPath))).
SetUploadRepository(path.Join(rtResultRepository, artifactFinalRepoPath)).
SetProjectKey(projectKey)
artifactName, err := uploadCmd.Upload()
if err != nil {
return "", fmt.Errorf("failed uploading the scan results: %w", err)
}
return filepath.ToSlash(filepath.Join(artifactFinalRepoPath, artifactName)), nil
return path.Join(artifactFinalRepoPath, artifactName), nil
}

func GetCommandResultsPlatformUrlMessage(cmdResults *results.SecurityCommandResults, pretty bool) string {
Expand Down Expand Up @@ -141,10 +142,10 @@ func getGitContextArtifactPath(gitContext *services.XscGitInfoContext) (string,
}
if gitContext.PullRequest != nil && gitContext.Target != nil {
// pull request, return the path with source and target commit hashes
return filepath.ToSlash(filepath.Join(artifactPath, "PR")), nil
return path.Join(artifactPath, "PR"), nil
}
// not a pull request, just return the source commit path
return filepath.ToSlash(filepath.Join(artifactPath, "commits")), nil
return path.Join(artifactPath, "commits"), nil
}

func extractBaseGitPath(gitCloneUrl, sourceBranchName string) (string, error) {
Expand All @@ -154,5 +155,5 @@ func extractBaseGitPath(gitCloneUrl, sourceBranchName string) (string, error) {
return "", err
}
// Extract the host and path, removing any .git suffix
return gitUrlParsed.Host + "/" + gitUrlParsed.Path[:len(gitUrlParsed.Path)-len(filepath.Ext(gitUrlParsed.Path))] + "/" + sourceBranchName, nil
return path.Join(gitUrlParsed.Host, strings.TrimSuffix(gitUrlParsed.Path, ".git"), sourceBranchName), nil
}
49 changes: 49 additions & 0 deletions utils/results/output/reportartifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,55 @@ func TestUploadViaXrayApi_ServerError_ReturnsError(t *testing.T) {
assert.Error(t, err)
}

func TestGetGitContextArtifactPath(t *testing.T) {
testCases := []struct {
name string
gitContext *clientservices.XscGitInfoContext
expectedResult string
}{
{
name: "commit scan",
gitContext: &clientservices.XscGitInfoContext{
Source: clientservices.CommitContext{GitRepoHttpsCloneUrl: "https://github.com/org/repo.git", BranchName: "main"},
},
expectedResult: "github.com/org/repo/main/commits",
},
{
name: "commit scan with a dotted repo name and no .git suffix",
gitContext: &clientservices.XscGitInfoContext{
Source: clientservices.CommitContext{GitRepoHttpsCloneUrl: "https://github.com/socketio/socket.io", BranchName: "main"},
},
expectedResult: "github.com/socketio/socket.io/main/commits",
},
{
name: "commit scan with a port in the clone url",
gitContext: &clientservices.XscGitInfoContext{
Source: clientservices.CommitContext{GitRepoHttpsCloneUrl: "https://git.example.com:8443/collection/repo.git", BranchName: "main"},
},
expectedResult: "git.example.com:8443/collection/repo/main/commits",
},
{
name: "pull request scan with a port in the clone url",
gitContext: &clientservices.XscGitInfoContext{
Source: clientservices.CommitContext{GitRepoHttpsCloneUrl: "https://git.example.com:8443/collection/repo.git", BranchName: "feature"},
GitDiffContext: clientservices.GitDiffContext{
Target: &clientservices.CommitContext{GitRepoHttpsCloneUrl: "https://git.example.com:8443/collection/repo.git", BranchName: "main"},
PullRequest: &clientservices.PullRequestContext{PullRequestId: 1},
},
},
expectedResult: "git.example.com:8443/collection/repo/feature/PR",
},
}

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
result, err := getGitContextArtifactPath(testCase.gitContext)
require.NoError(t, err)
assert.Equal(t, testCase.expectedResult, result)
})
}
}

func TestGetLocalArtifactPath(t *testing.T) {
testCases := []struct {
name string
Expand Down
Loading