Skip to content

Commit

Permalink
Fixed action executor test
Browse files Browse the repository at this point in the history
  • Loading branch information
MaartendeKruijf committed Jul 24, 2024
1 parent 120f836 commit cb58720
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
55 changes: 50 additions & 5 deletions test/unittest/executor/action/action_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func TestExecuteStep(t *testing.T) {
expectedCommand,
expectedAuth,
expectedTarget,
cacao.NewVariables(expectedVariables)).
cacao.NewVariables(expectedVariables),
step.InArgs,
step.OutArgs).
Return(cacao.NewVariables(expectedVariables),
nil)

Expand Down Expand Up @@ -132,12 +134,25 @@ func TestExecuteActionStep(t *testing.T) {
Name: "ssh",
}

step := cacao.Step{
Type: cacao.StepTypeAction,
Name: "action test",
ID: stepId,
Description: "",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Agent: "mock-ssh",
Targets: []string{"target1"},
}

mock_ssh.On("Execute",
metadata,
expectedCommand,
expectedAuth,
expectedTarget,
cacao.NewVariables(expectedVariables)).
cacao.NewVariables(expectedVariables),
step.InArgs,
step.OutArgs).
Return(cacao.NewVariables(expectedVariables),
nil)

Expand All @@ -146,6 +161,7 @@ func TestExecuteActionStep(t *testing.T) {
expectedAuth,
expectedTarget,
cacao.NewVariables(expectedVariables),
step,
agent)

assert.Equal(t, err, nil)
Expand Down Expand Up @@ -189,12 +205,22 @@ func TestNonExistingCapabilityStep(t *testing.T) {
Type: "ssh",
Name: "non-existing",
}

step := cacao.Step{
Type: cacao.StepTypeAction,
Name: "action test",
ID: stepId,
Description: "",
StepVariables: cacao.NewVariables(expectedVariables),
Commands: []cacao.Command{expectedCommand},
Agent: "mock-ssh",
Targets: []string{"target1"},
}
_, err := executerObject.ExecuteActionStep(metadata,
expectedCommand,
expectedAuth,
expectedTarget,
cacao.NewVariables(expectedVariables),
step,
agent)

assert.Equal(t, err, errors.New("capability: non-existing is not available in soarca"))
Expand Down Expand Up @@ -325,15 +351,31 @@ func TestVariableInterpolation(t *testing.T) {
expectedCommand,
expectedAuth,
expectedTarget,
cacao.NewVariables(var1, var2, var3, varUser, varPassword, varOauth, varPrivateKey, varToken, varUserId)).
cacao.NewVariables(var1, var2, var3, varUser, varPassword, varOauth, varPrivateKey, varToken, varUserId),
[]string{"__in_one__", "__in_two__"},
[]string{"__out_one__", "__out_two__"}).
Return(cacao.NewVariables(var1),
nil)

step := cacao.Step{
Type: cacao.StepTypeAction,
Name: "action test",
ID: stepId,
Description: "",
StepVariables: cacao.NewVariables(var1, var2, var3, varUser, varPassword, varOauth, varPrivateKey, varToken, varUserId),
Commands: []cacao.Command{expectedCommand},
Agent: "mock-ssh",
Targets: []string{"target1"},
InArgs: []string{"__in_one__", "__in_two__"},
OutArgs: []string{"__out_one__", "__out_two__"},
}

_, err := executerObject.ExecuteActionStep(metadata,
inputCommand,
inputAuth,
inputTarget,
cacao.NewVariables(var1, var2, var3, varUser, varPassword, varOauth, varPrivateKey, varToken, varUserId),
step,
agent)

assert.Equal(t, err, nil)
Expand Down Expand Up @@ -361,7 +403,9 @@ func TestVariableInterpolation(t *testing.T) {
expectedHttpCommand,
expectedAuth,
expectedTarget,
cacao.NewVariables(varHttpContent)).
cacao.NewVariables(varHttpContent),
[]string{"__in_one__", "__in_two__"},
[]string{"__out_one__", "__out_two__"}).
Return(cacao.NewVariables(var1),
nil)

Expand All @@ -370,6 +414,7 @@ func TestVariableInterpolation(t *testing.T) {
expectedAuth,
expectedTarget,
cacao.NewVariables(varHttpContent),
step,
agent)

assert.Equal(t, err, nil)
Expand Down
6 changes: 4 additions & 2 deletions test/unittest/mocks/mock_capability/mock_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ func (capability *Mock_Capability) Execute(metadata execution.Metadata,
command cacao.Command,
authentication cacao.AuthenticationInformation,
target cacao.AgentTarget,
inputVariables cacao.Variables,
outputVariables cacao.Variables) (cacao.Variables, error) {
variables cacao.Variables,
inputVariables []string,
outputVariables []string) (cacao.Variables, error) {
args := capability.Called(metadata,
command,
authentication,
target,
variables,
inputVariables,
outputVariables)
return args.Get(0).(cacao.Variables), args.Error(1)
Expand Down

0 comments on commit cb58720

Please sign in to comment.