Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSCS as scan type for the triage command (AST-72075) #1022

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

cx-ruio
Copy link
Collaborator

@cx-ruio cx-ruio commented Jan 28, 2025

By submitting a PR to this repository, you agree to the terms within the Checkmarx Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.

Description

SSCS triaging capabilities.

References

https://checkmarx.atlassian.net/browse/AST-72075

Testing

Checklist

  • I have added documentation for new/changed functionality in this PR (if applicable).
  • I have updated the CLI help for new/changed functionality in this PR (if applicable).
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used

Copy link

github-actions bot commented Jan 28, 2025

Logo
Checkmarx One – Scan Summary & Detailsebdbdb16-195d-4ea7-af76-5cd3eb6f4041

Great job, no security vulnerabilities found in this Pull Request

@cx-ruio cx-ruio force-pushed the feature/AST-72075-cli-add-sscs-as-scan-type-for-the-triage-command branch from 1a51196 to c22a73a Compare January 28, 2025 18:03
type ScanOverviewHTTPWrapper struct {
path string
}

func NewHTTPScanOverviewWrapper(path string) ScanOverviewWrapper {
validPath := configurePath(path)
Copy link

Choose a reason for hiding this comment

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

The configurePath function is not defined within the provided diff. Ensure that the function exists and is properly implemented to handle the path parameter. If it's defined in another file, make sure it is correctly imported and accessible in this context.

internal/wrappers/scan-overview-http.go Outdated Show resolved Hide resolved

// configurePath checks if the path is the default path, if not it writes the default path to the config file
func configurePath(path string) string {
if path != defaultPath {
Copy link

Choose a reason for hiding this comment

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

The condition if path != defaultPath is misleading because the function always returns defaultPath regardless of the input path. Consider returning the actual path that is set in the configuration.

internal/wrappers/scan-overview-http.go Outdated Show resolved Hide resolved
func configurePath(path string) string {
if path != defaultPath {
viper.Set(commonParams.ScsScanOverviewPathKey, defaultPath)
configFilePath, err := configuration.GetConfigFilePath()
Copy link

Choose a reason for hiding this comment

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

The error from configuration.GetConfigFilePath() is logged but not handled. If the config file path cannot be retrieved, the function should not attempt to write to it and should handle the error appropriately.

if err != nil {
logger.PrintfIfVerbose("Error getting config file path: %v", err)
}
err = configuration.SafeWriteSingleConfigKeyString(configFilePath, commonParams.ScsScanOverviewPathKey, defaultPath)
Copy link

Choose a reason for hiding this comment

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

The error from configuration.SafeWriteSingleConfigKeyString is logged but not handled. Consider what should happen if the configuration cannot be updated. Should the function return an error, or should there be a fallback mechanism?

internal/commands/util/configuration_test.go Show resolved Hide resolved
func TestWriteSingleConfigKeyStringNonExistingFile_CreatingTheFileAndWritesTheKey_Success(t *testing.T) {
configFilePath := "non-existing-file"

file, err := os.Open(configFilePath)
Copy link

Choose a reason for hiding this comment

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

The file handle file is not closed after opening. Consider deferring the close operation immediately after checking the error from os.Open to avoid resource leaks.

asserts.NotNil(t, err)
asserts.Nil(t, file)

err = configuration.SafeWriteSingleConfigKeyString(configFilePath, cxScsScanOverviewPath, defaultScsScanOverviewPath)
Copy link

Choose a reason for hiding this comment

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

The test function name TestWriteSingleConfigKeyStringNonExistingFile_CreatingTheFileAndWritesTheKey_Success is misleading as it implies success, but the test does not assert any conditions to verify the success of the operation. Consider adding assertions to check that the key was written successfully.

internal/commands/util/configuration_test.go Show resolved Hide resolved
internal/commands/util/configuration_test.go Show resolved Hide resolved
internal/wrappers/scan-overview-http.go Show resolved Hide resolved
// setDefaultPath checks if the path is the default path, if not it writes the default path to the config file
func setDefaultPath(path string) string {
if path != defaultPath {
configFilePath, err := configuration.GetConfigFilePath()
Copy link

Choose a reason for hiding this comment

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

The viper.Set call has been removed, which means the new default path is not being set in the configuration. Ensure that the configuration is updated with the new default path if this is the intended behavior.

@cx-ruio cx-ruio force-pushed the feature/AST-72075-cli-add-sscs-as-scan-type-for-the-triage-command branch from 86b550a to 2375f6f Compare February 6, 2025 11:53
internal/commands/predicates.go Show resolved Hide resolved
const (
cxAscaPort = "cx_asca_port"
cxScsScanOverviewPath = "cx_scs_scan_overview_path"
defaultScsScanOverviewPath = "api/micro-engines/read/scans/%s/scan-overview"
Copy link

Choose a reason for hiding this comment

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

The constant defaultScsScanOverviewPath is defined but not used anywhere in the code. Please ensure that it is utilized appropriately or remove it if it's not needed.

internal/commands/util/configuration_test.go Show resolved Hide resolved
internal/commands/util/configuration_test.go Show resolved Hide resolved
internal/commands/util/configuration_test.go Show resolved Hide resolved
@@ -58,3 +63,18 @@ func (r *ScanOverviewHTTPWrapper) GetSCSOverviewByScanID(scanID string) (
return nil, nil, errors.Errorf("response status code %d", resp.StatusCode)
}
}

// setDefaultPath checks if the path is the default path, if not it writes the default path to the config file
Copy link

Choose a reason for hiding this comment

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

The function setDefaultPath does not seem to be related to the SSCS triaging capabilities as described in the PR. Please ensure that this function is necessary for the feature being implemented and clarify its purpose in the context of SSCS triaging.


// setDefaultPath checks if the path is the default path, if not it writes the default path to the config file
func setDefaultPath(path string) string {
if path != defaultPath {
Copy link

Choose a reason for hiding this comment

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

The function setDefaultPath always returns defaultPath regardless of the input path. This behavior is not intuitive based on the function name and description. Consider returning the actual path set (either the input path or defaultPath) or renaming the function to reflect its behavior more accurately.

// setDefaultPath checks if the path is the default path, if not it writes the default path to the config file
func setDefaultPath(path string) string {
if path != defaultPath {
configFilePath, err := configuration.GetConfigFilePath()
Copy link

Choose a reason for hiding this comment

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

The check if path != defaultPath should be followed by a return statement if the condition is false, to avoid unnecessary operations when the path is already set to the default.

if err != nil {
logger.PrintfIfVerbose("Error getting config file path: %v", err)
}
err = configuration.SafeWriteSingleConfigKeyString(configFilePath, commonParams.ScsScanOverviewPathKey, defaultPath)
Copy link

Choose a reason for hiding this comment

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

The function configuration.SafeWriteSingleConfigKeyString is called without handling the case where the configFilePath could not be retrieved due to an error. This could lead to unexpected behavior. Ensure that the function is not called if configFilePath cannot be determined.

}
err = configuration.SafeWriteSingleConfigKeyString(configFilePath, commonParams.ScsScanOverviewPathKey, defaultPath)
if err != nil {
logger.PrintfIfVerbose("Error writing Scan Overview path to config file: %v", err)
Copy link

Choose a reason for hiding this comment

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

Logging the error using logger.PrintfIfVerbose might not be sufficient for error handling. Consider propagating the error up to the caller of setDefaultPath so that it can be handled appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants