From 895ccfa43178fc28625f35dd9ff468efb2f9893d Mon Sep 17 00:00:00 2001 From: barv Date: Mon, 30 Sep 2024 15:05:04 +0300 Subject: [PATCH] cocoapods-audit --- commands/audit/sca/cocoapods/cocoapods.go | 15 ++++++++------- commands/audit/sca/cocoapods/cocoapods_test.go | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/commands/audit/sca/cocoapods/cocoapods.go b/commands/audit/sca/cocoapods/cocoapods.go index 945d54ab..a92fa56d 100644 --- a/commands/audit/sca/cocoapods/cocoapods.go +++ b/commands/audit/sca/cocoapods/cocoapods.go @@ -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] } } @@ -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) @@ -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 { @@ -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) diff --git a/commands/audit/sca/cocoapods/cocoapods_test.go b/commands/audit/sca/cocoapods/cocoapods_test.go index 7b363bed..4ac6eaab 100644 --- a/commands/audit/sca/cocoapods/cocoapods_test.go +++ b/commands/audit/sca/cocoapods/cocoapods_test.go @@ -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")