Skip to content

Commit

Permalink
tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
orto17 committed Jan 6, 2025
1 parent 4dc212f commit 19d3822
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
12 changes: 6 additions & 6 deletions packagehandlers/conanpackagehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ func (conan *ConanPackageHandler) updateDirectDependency(vulnDetails *utils.Vuln
return
}

func (conan *ConanPackageHandler) updateConanFile(conanFile string, vulnDetails *utils.VulnerabilityDetails) (isFileChanged bool, err error) {
data, err := os.ReadFile(conanFile)
func (conan *ConanPackageHandler) updateConanFile(conanFilePath string, vulnDetails *utils.VulnerabilityDetails) (isFileChanged bool, err error) {
data, err := os.ReadFile(conanFilePath)
if err != nil {
return false, fmt.Errorf("an error occurred while attempting to read the requirements file '%s': %s\n", conanFile, err.Error())
return false, fmt.Errorf("an error occurred while attempting to read the requirements file '%s': %s\n", conanFilePath, err.Error())
}
currentFile := string(data)
fixedPackage := vulnDetails.ImpactedDependencyName + "/" + vulnDetails.SuggestedFixedVersion
impactedDependency := vulnDetails.ImpactedDependencyName + "/" + vulnDetails.ImpactedDependencyVersion
fixedFile := strings.Replace(currentFile, impactedDependency, strings.ToLower(fixedPackage), 1)

if fixedFile == currentFile {
log.Info(fmt.Sprintf("impacted dependency '%s' not found in descriptor '%s', moving to the next descriptor if exists...", impactedDependency, conanFile))
log.Debug(fmt.Sprintf("impacted dependency '%s' not found in descriptor '%s', moving to the next descriptor if exists...", impactedDependency, conanFilePath))
return false, nil
}
if err = os.WriteFile(conanFile, []byte(fixedFile), 0600); err != nil {
err = fmt.Errorf("an error occured while writing the fixed version of %s to the requirements file '%s': %s", conanFile, vulnDetails.ImpactedDependencyName, err.Error())
if err = os.WriteFile(conanFilePath, []byte(fixedFile), 0600); err != nil {
err = fmt.Errorf("an error occured while writing the fixed version of %s to the requirements file '%s': %s", vulnDetails.ImpactedDependencyName, conanFilePath, err.Error())
}
isFileChanged = true
return
Expand Down
21 changes: 4 additions & 17 deletions packagehandlers/packagehandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,6 @@ func TestUpdateDependency(t *testing.T) {

// Conan test cases
{
{
vulnDetails: &utils.VulnerabilityDetails{
IsDirectDependency: true,
SuggestedFixedVersion: "3.0.14",
VulnerabilityOrViolationRow: formats.VulnerabilityOrViolationRow{Technology: techutils.Conan, ImpactedDependencyDetails: formats.ImpactedDependencyDetails{ImpactedDependencyName: "openssl", ImpactedDependencyVersion: "3.0.9"}},
},
scanDetails: scanDetails,
fixSupported: true,
testDirName: "conan",
descriptorsToCheck: []string{"conanfile.txt"},
},
{
vulnDetails: &utils.VulnerabilityDetails{
SuggestedFixedVersion: "3.0.14",
Expand All @@ -367,18 +356,16 @@ func TestUpdateDependency(t *testing.T) {
scanDetails: scanDetails,
fixSupported: true,
testDirName: "conan",
descriptorsToCheck: []string{"conanfile.py"},
descriptorsToCheck: []string{"conanfile.py", "conanfile.txt"},
},
{
vulnDetails: &utils.VulnerabilityDetails{
SuggestedFixedVersion: "3.0.14",
IsDirectDependency: true,
IsDirectDependency: false,
VulnerabilityOrViolationRow: formats.VulnerabilityOrViolationRow{Technology: techutils.Conan, ImpactedDependencyDetails: formats.ImpactedDependencyDetails{ImpactedDependencyName: "openssl", ImpactedDependencyVersion: "3.0.9"}},
},
scanDetails: scanDetails,
fixSupported: true,
testDirName: "conan",
descriptorsToCheck: []string{"conanfile.py", "conanfile.txt"},
scanDetails: scanDetails,
fixSupported: false,
},
},
}
Expand Down

0 comments on commit 19d3822

Please sign in to comment.