Skip to content

Commit

Permalink
cocoapods-audit
Browse files Browse the repository at this point in the history
  • Loading branch information
barv-jfrog committed Sep 30, 2024
1 parent 08e3bd5 commit 895ccfa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions commands/audit/sca/cocoapods/cocoapods.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ func GetTechDependencyLocation(directDependencyName, directDependencyVersion str
snippet = lines[startLine][startCol:endCol]
} else {
for snippetLine := range endLine - startLine + 1 {
if snippetLine == 0 {
switch snippetLine {
case 0:
snippet += "\n" + lines[snippetLine][startLine:]
} else if snippetLine == endLine-startLine {
case endLine - startLine:
snippet += "\n" + lines[snippetLine][:endCol]
} else {
default:
snippet += "\n" + lines[snippetLine]
}
}
Expand Down Expand Up @@ -123,7 +124,7 @@ func GetPodDependenciesGraph(data string) (map[string][]string, map[string]strin
dependencyMap := make(map[string][]string, len(lines))
versionMap := make(map[string]string, len(lines))
for _, line := range lines {
line = strings.Replace(line, "\"", "", -1)
line = strings.ReplaceAll(line, "\"", "")
mainDepMatch := mainDepRegex.FindStringSubmatch(line)
if len(mainDepMatch) == 3 {
versionMatch := versionRegex.FindStringSubmatch(line)
Expand Down Expand Up @@ -182,13 +183,13 @@ func GetDependenciesData(exePath, currentDir string) (string, error) {
func BuildDependencyTree(params utils.AuditParams) (dependencyTree []*xrayUtils.GraphNode, uniqueDeps []string, err error) {
currentDir, err := coreutils.GetWorkingDirectory()
if err != nil {
return
return nil, nil, err
}

clearResolutionServerFunc, err := configPodResolutionServerIfNeeded(params)
if err != nil {
err = fmt.Errorf("failed while configuring a resolution server: %s", err.Error())
return
return nil, nil, err
}
defer func() {
if clearResolutionServerFunc != nil {
Expand All @@ -206,7 +207,7 @@ func BuildDependencyTree(params utils.AuditParams) (dependencyTree []*xrayUtils.
// Calculate pod dependencies
data, err := GetDependenciesData(podExecutablePath, currentDir)
if err != nil {
return
return nil, nil, err
}
uniqueDepsSet := datastructures.MakeSet[string]()
dependenciesGraph, versionMap := GetPodDependenciesGraph(data)
Expand Down
1 change: 1 addition & 0 deletions commands/audit/sca/cocoapods/cocoapods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func TestFixTechDependency(t *testing.T) {
currentDir, err := coreutils.GetWorkingDirectory()
assert.NoError(t, err)
err = FixTechDependency("GoogleSignIn", "6.2.4", "6.2.5", filepath.Join(currentDir, "Podfile"))
assert.NoError(t, err)
file, err := os.ReadFile(filepath.Join(currentDir, "Podfile"))
assert.NoError(t, err)
lines := strings.Split(string(file), "\n")
Expand Down

0 comments on commit 895ccfa

Please sign in to comment.