Skip to content

Commit

Permalink
Merge pull request #871 from Checkmarx/miryamFoifer/Update-Vorpal-Nam…
Browse files Browse the repository at this point in the history
…e-AST-65647

Update Vorpal Name to ASCA(AST-65647)
  • Loading branch information
miryamfoiferCX authored Sep 19, 2024
2 parents 88c2d70 + ab9ecf2 commit 059e5c8
Show file tree
Hide file tree
Showing 28 changed files with 371 additions and 370 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vorpal
package asca

import (
"github.com/checkmarx/ast-cli/internal/commands/util/printer"
Expand All @@ -10,24 +10,24 @@ import (
"github.com/spf13/viper"
)

func RunScanVorpalCommand(jwtWrapper wrappers.JWTWrapper, featureFlagsWrapper wrappers.FeatureFlagsWrapper) func(cmd *cobra.Command, args []string) error {
func RunScanASCACommand(jwtWrapper wrappers.JWTWrapper, featureFlagsWrapper wrappers.FeatureFlagsWrapper) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
vorpalLatestVersion, _ := cmd.Flags().GetBool(commonParams.VorpalLatestVersion)
ASCALatestVersion, _ := cmd.Flags().GetBool(commonParams.ASCALatestVersion)
fileSourceFlag, _ := cmd.Flags().GetString(commonParams.SourcesFlag)
agent, _ := cmd.Flags().GetString(commonParams.AgentFlag)
var port = viper.GetInt(commonParams.VorpalPortKey)
vorpalWrapper := grpcs.NewVorpalGrpcWrapper(port)
vorpalParams := services.VorpalScanParams{
FilePath: fileSourceFlag,
VorpalUpdateVersion: vorpalLatestVersion,
IsDefaultAgent: agent == commonParams.DefaultAgent,
var port = viper.GetInt(commonParams.ASCAPortKey)
ASCAWrapper := grpcs.NewASCAGrpcWrapper(port)
ASCAParams := services.AscaScanParams{
FilePath: fileSourceFlag,
ASCAUpdateVersion: ASCALatestVersion,
IsDefaultAgent: agent == commonParams.DefaultAgent,
}
wrapperParams := services.VorpalWrappersParam{
wrapperParams := services.AscaWrappersParam{
JwtWrapper: jwtWrapper,
FeatureFlagsWrapper: featureFlagsWrapper,
VorpalWrapper: vorpalWrapper,
ASCAWrapper: ASCAWrapper,
}
scanResult, err := services.CreateVorpalScanRequest(vorpalParams, wrapperParams)
scanResult, err := services.CreateASCAScanRequest(ASCAParams, wrapperParams)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vorpal
package asca

import (
"reflect"
Expand All @@ -12,10 +12,10 @@ import (
"github.com/spf13/cobra"
)

func Test_ExecuteVorpalScan(t *testing.T) {
func Test_ExecuteAscaScan(t *testing.T) {
type args struct {
fileSourceFlag string
vorpalUpdateVersion bool
fileSourceFlag string
ASCAUpdateVersion bool
}
tests := []struct {
name string
Expand All @@ -27,37 +27,37 @@ func Test_ExecuteVorpalScan(t *testing.T) {
{
name: "Test with empty fileSource flag should not return error",
args: args{
fileSourceFlag: "",
vorpalUpdateVersion: true,
fileSourceFlag: "",
ASCAUpdateVersion: true,
},
want: &grpcs.ScanResult{
Message: services.FilePathNotProvided,
},
wantErr: false,
},
{
name: "Test with valid flags. vorpalUpdateVersion set to true",
name: "Test with valid flags. ASCAUpdateVersion set to true",
args: args{
fileSourceFlag: "../data/python-vul-file.py",
vorpalUpdateVersion: true,
fileSourceFlag: "../data/python-vul-file.py",
ASCAUpdateVersion: true,
},
want: mock.ReturnSuccessfulResponseMock(),
wantErr: false,
},
{
name: "Test with valid flags. vorpalUpdateVersion set to false",
name: "Test with valid flags. ASCAUpdateVersion set to false",
args: args{
fileSourceFlag: "../data/python-vul-file.py",
vorpalUpdateVersion: false,
fileSourceFlag: "../data/python-vul-file.py",
ASCAUpdateVersion: false,
},
want: mock.ReturnSuccessfulResponseMock(),
wantErr: false,
},
{
name: "Test with valid flags. vorpal scan failed",
name: "Test with valid flags. asca scan failed",
args: args{
fileSourceFlag: "../data/csharp-no-vul.cs",
vorpalUpdateVersion: false,
fileSourceFlag: "../data/csharp-no-vul.cs",
ASCAUpdateVersion: false,
},
want: mock.ReturnFailureResponseMock(),
wantErr: false,
Expand All @@ -66,32 +66,32 @@ func Test_ExecuteVorpalScan(t *testing.T) {
for _, tt := range tests {
ttt := tt
t.Run(ttt.name, func(t *testing.T) {
vorpalParams := services.VorpalScanParams{
FilePath: ttt.args.fileSourceFlag,
VorpalUpdateVersion: ttt.args.vorpalUpdateVersion,
IsDefaultAgent: true,
ASCAParams := services.AscaScanParams{
FilePath: ttt.args.fileSourceFlag,
ASCAUpdateVersion: ttt.args.ASCAUpdateVersion,
IsDefaultAgent: true,
}
wrapperParams := services.VorpalWrappersParam{
wrapperParams := services.AscaWrappersParam{
JwtWrapper: &mock.JWTMockWrapper{},
FeatureFlagsWrapper: &mock.FeatureFlagsMockWrapper{},
VorpalWrapper: &mock.VorpalMockWrapper{},
ASCAWrapper: &mock.ASCAMockWrapper{},
}
got, err := services.CreateVorpalScanRequest(vorpalParams, wrapperParams)
got, err := services.CreateASCAScanRequest(ASCAParams, wrapperParams)
if (err != nil) != ttt.wantErr {
t.Errorf("executeVorpalScan() error = %v, wantErr %v", err, ttt.wantErr)
t.Errorf("executeASCAScan() error = %v, wantErr %v", err, ttt.wantErr)
return
}
if ttt.wantErr && err.Error() != ttt.wantErrMsg {
t.Errorf("executeVorpalScan() error message = %v, wantErrMsg %v", err.Error(), ttt.wantErrMsg)
t.Errorf("executeASCAScan() error message = %v, wantErrMsg %v", err.Error(), ttt.wantErrMsg)
}
if !reflect.DeepEqual(got, ttt.want) {
t.Errorf("executeVorpalScan() got = %v, want %v", got, ttt.want)
t.Errorf("executeASCAScan() got = %v, want %v", got, ttt.want)
}
})
}
}

func Test_runScanVorpalCommand(t *testing.T) {
func Test_runScanASCACommand(t *testing.T) {
tests := []struct {
name string
sourceFlag string
Expand All @@ -108,14 +108,14 @@ func Test_runScanVorpalCommand(t *testing.T) {
want: nil,
},
{
name: "Test with valid fileSource Flag and vorpalUpdateVersion flag set false ",
name: "Test with valid fileSource Flag and ASCAUpdateVersion flag set false ",
sourceFlag: "data/python-vul-file.py",
engineFlag: false,
want: nil,
wantErr: false,
},
{
name: "Test with valid fileSource Flag and vorpalUpdateVersion flag set true ",
name: "Test with valid fileSource Flag and ASCAUpdateVersion flag set true ",
sourceFlag: "data/python-vul-file.py",
engineFlag: true,
want: nil,
Expand All @@ -127,16 +127,16 @@ func Test_runScanVorpalCommand(t *testing.T) {
t.Run(ttt.name, func(t *testing.T) {
cmd := &cobra.Command{}
cmd.Flags().String(commonParams.SourcesFlag, ttt.sourceFlag, "")
cmd.Flags().Bool(commonParams.VorpalLatestVersion, ttt.engineFlag, "")
cmd.Flags().Bool(commonParams.ASCALatestVersion, ttt.engineFlag, "")
cmd.Flags().String(commonParams.FormatFlag, printer.FormatJSON, "")
runFunc := RunScanVorpalCommand(&mock.JWTMockWrapper{}, &mock.FeatureFlagsMockWrapper{})
runFunc := RunScanASCACommand(&mock.JWTMockWrapper{}, &mock.FeatureFlagsMockWrapper{})
err := runFunc(cmd, []string{})
if (err != nil) != ttt.wantErr {
t.Errorf("RunScanVorpalCommand() error = %v, wantErr %v", err, ttt.wantErr)
t.Errorf("RunScanASCACommand() error = %v, wantErr %v", err, ttt.wantErr)
return
}
if ttt.wantErr && err.Error() != ttt.wantErrMsg {
t.Errorf("RunScanVorpalCommand() error message = %v, wantErrMsg %v", err.Error(), ttt.wantErrMsg)
t.Errorf("RunScanASCACommand() error message = %v, wantErrMsg %v", err.Error(), ttt.wantErrMsg)
}
})
}
Expand Down
51 changes: 51 additions & 0 deletions internal/commands/asca/asca_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package asca

import (
"os"
"testing"

"gotest.tools/assert"

ascaconfig "github.com/checkmarx/ast-cli/internal/commands/asca/ascaconfig"
"github.com/checkmarx/ast-cli/internal/services/osinstaller"
)

func TestInstallOrUpgrade_firstInstallation_Success(t *testing.T) {
err := firstInstallation()
assert.NilError(t, err, "Error on first installation of asca")
fileExists, _ := osinstaller.FileExists(ascaconfig.Params.ExecutableFilePath())
assert.Assert(t, fileExists, "Executable file not found")
fileExists, _ = osinstaller.FileExists(ascaconfig.Params.HashFilePath())
assert.Assert(t, fileExists, "Hash file not found")
}

func firstInstallation() error {
os.RemoveAll(ascaconfig.Params.WorkingDir())
_, err := osinstaller.InstallOrUpgrade(&ascaconfig.Params)
return err
}

func TestInstallOrUpgrade_installationIsUpToDate_Success(t *testing.T) {
err := firstInstallation()
assert.NilError(t, err, "Error on first installation of asca")
_, err = osinstaller.InstallOrUpgrade(&ascaconfig.Params)
assert.NilError(t, err, "Error when not need to upgrade")
}

func TestInstallOrUpgrade_installationIsNotUpToDate_Success(t *testing.T) {
err := firstInstallation()
assert.NilError(t, err, "Error on first installation of asca")
changeHashFile()
_, err = osinstaller.InstallOrUpgrade(&ascaconfig.Params)
assert.NilError(t, err, "Error when need to upgrade")
fileExists, _ := osinstaller.FileExists(ascaconfig.Params.ExecutableFilePath())
assert.Assert(t, fileExists, "Executable file not found")
fileExists, _ = osinstaller.FileExists(ascaconfig.Params.HashFilePath())
assert.Assert(t, fileExists, "Hash file not found")
}

func changeHashFile() {
content, _ := os.ReadFile(ascaconfig.Params.HashFilePath())
content[0]++
_ = os.WriteFile(ascaconfig.Params.HashFilePath(), content, os.ModePerm)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build linux && amd64

package vorpalconfig
package ascaconfig

import (
"github.com/checkmarx/ast-cli/internal/services/osinstaller"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build linux && (arm64 || arm)

package vorpalconfig
package ascaconfig

import (
"github.com/checkmarx/ast-cli/internal/services/osinstaller"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build darwin && amd64

package vorpalconfig
package ascaconfig

import (
"github.com/checkmarx/ast-cli/internal/services/osinstaller"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build darwin && arm64

package vorpalconfig
package ascaconfig

import (
"github.com/checkmarx/ast-cli/internal/services/osinstaller"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build windows

package vorpalconfig
package ascaconfig

import (
"github.com/checkmarx/ast-cli/internal/services/osinstaller"
Expand Down
28 changes: 14 additions & 14 deletions internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"strings"
"time"

"github.com/checkmarx/ast-cli/internal/commands/asca"
"github.com/checkmarx/ast-cli/internal/commands/scarealtime"
"github.com/checkmarx/ast-cli/internal/commands/util"
"github.com/checkmarx/ast-cli/internal/commands/util/printer"
"github.com/checkmarx/ast-cli/internal/commands/vorpal"
"github.com/checkmarx/ast-cli/internal/constants"
errorConstants "github.com/checkmarx/ast-cli/internal/constants/errors"
exitCodes "github.com/checkmarx/ast-cli/internal/constants/exit-codes"
Expand Down Expand Up @@ -187,7 +187,7 @@ func NewScanCommand(

showScanCmd := scanShowSubCommand(scansWrapper)

scanVorpalCmd := scanVorpalSubCommand(jwtWrapper, featureFlagsWrapper)
scanASCACmd := scanASCASubCommand(jwtWrapper, featureFlagsWrapper)

workflowScanCmd := scanWorkflowSubCommand(scansWrapper)

Expand All @@ -212,7 +212,7 @@ func NewScanCommand(
)
scanCmd.AddCommand(
createScanCmd,
scanVorpalCmd,
scanASCACmd,
showScanCmd,
workflowScanCmd,
listScansCmd,
Expand Down Expand Up @@ -400,15 +400,15 @@ func scanShowSubCommand(scansWrapper wrappers.ScansWrapper) *cobra.Command {
return showScanCmd
}

func scanVorpalSubCommand(jwtWrapper wrappers.JWTWrapper, featureFlagsWrapper wrappers.FeatureFlagsWrapper) *cobra.Command {
scanVorpalCmd := &cobra.Command{
func scanASCASubCommand(jwtWrapper wrappers.JWTWrapper, featureFlagsWrapper wrappers.FeatureFlagsWrapper) *cobra.Command {
scanASCACmd := &cobra.Command{
Hidden: true,
Use: "vorpal",
Short: "Run a Vorpal scan",
Long: "Running a Vorpal scan is a fast and efficient way to identify vulnerabilities in a specific file.",
Use: "asca",
Short: "Run a ASCA scan",
Long: "Running a ASCA scan is a fast and efficient way to identify vulnerabilities in a specific file.",
Example: heredoc.Doc(
`
$ cx scan vorpal --file-source <path to a single file> --vorpal-latest-version
$ cx scan asca --file-source <path to a single file> --asca-latest-version
`,
),
Annotations: map[string]string{
Expand All @@ -418,19 +418,19 @@ func scanVorpalSubCommand(jwtWrapper wrappers.JWTWrapper, featureFlagsWrapper wr
`,
),
},
RunE: vorpal.RunScanVorpalCommand(jwtWrapper, featureFlagsWrapper),
RunE: asca.RunScanASCACommand(jwtWrapper, featureFlagsWrapper),
}

scanVorpalCmd.PersistentFlags().Bool(commonParams.VorpalLatestVersion, false,
"Use this flag to update to the latest version of the Vorpal scanner."+
scanASCACmd.PersistentFlags().Bool(commonParams.ASCALatestVersion, false,
"Use this flag to update to the latest version of the ASCA scanner."+
"Otherwise, we will check if there is an existing installation that can be used.")
scanVorpalCmd.PersistentFlags().StringP(
scanASCACmd.PersistentFlags().StringP(
commonParams.SourcesFlag,
commonParams.SourcesFlagSh,
"",
"The file source should be the path to a single file",
)
return scanVorpalCmd
return scanASCACmd
}

func scanListSubCommand(scansWrapper wrappers.ScansWrapper, sastMetadataWrapper wrappers.SastMetadataWrapper) *cobra.Command {
Expand Down
Loading

0 comments on commit 059e5c8

Please sign in to comment.