Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 5 additions & 8 deletions output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"regexp"
"runtime/debug"
"strings"

"time"

"github.com/certinia/asist/config"
Expand Down Expand Up @@ -64,17 +64,14 @@ func DisplayOutput(finalResult *finding.Output, scanTime *ScanTime) {
}

/**
* extractRepoNameFromURL - method used to extract repoFolder/repoName from a sshUrl of repository
* extractRepoNameFromURL - method used to extract repoName from a sshUrl of repository
*/
func extractRepoNameFromURL(url string) string {
if url != "" {
findRepoNameRegexp := regexp.MustCompile(`(?i)[a-z0-9-_.]+/[a-z0-9-_.]+\.git$`)
findRepoNameRegexp := regexp.MustCompile(`(?i)([a-z0-9-_.]+)\.git$`)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for safe side I would suggest to add a / before the regex.

Suggested change
findRepoNameRegexp := regexp.MustCompile(`(?i)([a-z0-9-_.]+)\.git$`)
findRepoNameRegexp := regexp.MustCompile(`(?i)/([a-z0-9-_.]+)\.git$`)

match := findRepoNameRegexp.FindStringSubmatch(url)
if len(match) > 0 {
parts := strings.Split(match[0], ".git")
if len(parts) > 1 {
return parts[0]
}
if len(match) > 1 {
return match[1]
}
}
return ""
Expand Down
4 changes: 2 additions & 2 deletions output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ func TestCreateBaselineOutput(t *testing.T) {
baselineOutputContent := finding.BaselineOutputContent{FindingID: "431d4935962ceb80271200", IsCustom: false, IsFalsePositive: false, Id: "ExposedMessageChannel", Severity: "High", RuleCategory: "Security"}
expectedBaselineOutput := []finding.BaselineOutput{
{
RepositoryName: "test/test",
RepositoryName: "test",
RepositoryURL: sshUrl,
RecordType: "Finding",
Content: baselineOutputContent,
},
{
RepositoryName: "test/test",
RepositoryName: "test",
RepositoryURL: sshUrl,
RecordType: "Config",
Content: config.GetConfigInstance(),
Expand Down
Loading