Skip to content

Commit 9f91cb4

Browse files
Moved stix to comparison package
1 parent 6fbe289 commit 9f91cb4

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

internal/executors/condition/condition.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"soarca/logger"
77
"soarca/models/cacao"
88
"soarca/models/execution"
9-
"soarca/utils/stix"
9+
"soarca/utils/stix/expression/comparison"
1010
)
1111

1212
var component = reflect.TypeOf(Executor{}).PkgPath()
@@ -16,8 +16,8 @@ func init() {
1616
log = logger.Logger(component, logger.Info, "", logger.Json)
1717
}
1818

19-
func New(stix stix.IStix) *Executor {
20-
return &Executor{stix: stix}
19+
func New(comparison comparison.IComparison) *Executor {
20+
return &Executor{comparison: comparison}
2121
}
2222

2323
type IExecuter interface {
@@ -26,7 +26,7 @@ type IExecuter interface {
2626
}
2727

2828
type Executor struct {
29-
stix stix.IStix
29+
comparison comparison.IComparison
3030
}
3131

3232
func (executor *Executor) Execute(meta execution.Metadata, step cacao.Step, variables cacao.Variables) (string, bool, error) {
@@ -37,7 +37,7 @@ func (executor *Executor) Execute(meta execution.Metadata, step cacao.Step, vari
3737
return step.OnFailure, false, err
3838
}
3939

40-
result, err := executor.stix.Evaluate(step.Condition, variables)
40+
result, err := executor.comparison.Evaluate(step.Condition, variables)
4141
if err != nil {
4242
log.Error(err)
4343
return "", false, err

test/unittest/utils/stix/stix_test.go test/unittest/utils/stix/expression/comparison/comparison_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
package stix_test
1+
package comparison_test
22

33
import (
44
"errors"
55
"soarca/models/cacao"
6-
"soarca/utils/stix"
6+
"soarca/utils/stix/expression/comparison"
77
"testing"
88

99
"github.com/go-playground/assert/v2"
1010
)
1111

1212
func TestStringEquals(t *testing.T) {
1313

14-
stix := stix.New()
14+
stix := comparison.New()
1515

1616
var1 := cacao.Variable{Type: cacao.VariableTypeString}
1717
var1.Value = "a"
@@ -55,7 +55,7 @@ func TestStringEquals(t *testing.T) {
5555
}
5656

5757
func TestIntEquals(t *testing.T) {
58-
stix := stix.New()
58+
stix := comparison.New()
5959

6060
var1 := cacao.Variable{Type: cacao.VariableTypeLong}
6161
var1.Value = "1000"
@@ -102,7 +102,7 @@ func TestIntEquals(t *testing.T) {
102102
}
103103

104104
func TestFloatEquals(t *testing.T) {
105-
stix := stix.New()
105+
stix := comparison.New()
106106

107107
var1 := cacao.Variable{Type: cacao.VariableTypeFloat}
108108
var1.Value = "1000.0"
@@ -158,7 +158,7 @@ func TestFloatEquals(t *testing.T) {
158158
}
159159

160160
func TestIp4AddressEquals(t *testing.T) {
161-
stix := stix.New()
161+
stix := comparison.New()
162162
var1 := cacao.Variable{Type: cacao.VariableTypeIpv4Address}
163163
var1.Value = "10.0.0.30"
164164
var1.Name = "__var1__"
@@ -182,7 +182,7 @@ func TestIp4AddressEquals(t *testing.T) {
182182
}
183183

184184
func TestIp6AddressEquals(t *testing.T) {
185-
stix := stix.New()
185+
stix := comparison.New()
186186
var1 := cacao.Variable{Type: cacao.VariableTypeIpv6Address}
187187
var1.Value = "2001:db8::1"
188188
var1.Name = "__var1__"
@@ -206,7 +206,7 @@ func TestIp6AddressEquals(t *testing.T) {
206206
}
207207

208208
func TestMacAddressEquals(t *testing.T) {
209-
stix := stix.New()
209+
stix := comparison.New()
210210
var1 := cacao.Variable{Type: cacao.VariableTypeMacAddress}
211211
var1.Value = "BC-24-11-00-00-01"
212212
var1.Name = "__var1__"
@@ -240,7 +240,7 @@ func TestMacAddressEquals(t *testing.T) {
240240
}
241241

242242
func TestHashEquals(t *testing.T) {
243-
stix := stix.New()
243+
stix := comparison.New()
244244
md5 := cacao.Variable{Type: cacao.VariableTypeMd5Has}
245245
md5.Value = "d41d8cd98f00b204e9800998ecf8427e"
246246
md5.Name = "__md5__"
@@ -294,7 +294,7 @@ func TestHashEquals(t *testing.T) {
294294
}
295295

296296
func TestUriEquals(t *testing.T) {
297-
stix := stix.New()
297+
stix := comparison.New()
298298

299299
var1 := cacao.Variable{Type: cacao.VariableTypeUri}
300300
var1.Value = "https://google.com"
@@ -316,7 +316,7 @@ func TestUriEquals(t *testing.T) {
316316
}
317317

318318
func TestUuidEquals(t *testing.T) {
319-
stix := stix.New()
319+
stix := comparison.New()
320320

321321
var1 := cacao.Variable{Type: cacao.VariableTypeUuid}
322322
var1.Value = "ec887691-9a21-4ccf-8fae-360c13a819d1"

utils/stix/strix.go utils/stix/expression/comparison/comparison.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package stix
1+
package comparison
22

33
import (
44
"errors"
@@ -29,25 +29,25 @@ const (
2929
)
3030

3131
var (
32-
component = reflect.TypeOf(Stix{}).PkgPath()
32+
component = reflect.TypeOf(Comparison{}).PkgPath()
3333
log *logger.Log
3434
)
3535

3636
func init() {
3737
log = logger.Logger(component, logger.Info, "", logger.Json)
3838
}
3939

40-
type IStix interface {
40+
type IComparison interface {
4141
Evaluate(string, cacao.Variables) (bool, error)
4242
}
4343

44-
func New() *Stix {
45-
return &Stix{}
44+
func New() *Comparison {
45+
return &Comparison{}
4646
}
4747

48-
type Stix struct{}
48+
type Comparison struct{}
4949

50-
func (s *Stix) Evaluate(expression string, vars cacao.Variables) (bool, error) {
50+
func (s *Comparison) Evaluate(expression string, vars cacao.Variables) (bool, error) {
5151

5252
//"condition": "__variable__:value == '10.0.0.0/8'"
5353
//"condition": "__ip__:value/__subnet__:value == '10.0.0.0/8'"
@@ -66,6 +66,8 @@ func (s *Stix) Evaluate(expression string, vars cacao.Variables) (bool, error) {
6666

6767
parts[0] = vars.Interpolate(parts[0])
6868

69+
log.Trace(parts)
70+
6971
switch usedVariable.Type {
7072
case cacao.VariableTypeBool:
7173
return boolCompare(parts)

0 commit comments

Comments
 (0)