Skip to content

Commit

Permalink
Merge pull request #141 from armosec/fix-since-until
Browse files Browse the repository at this point in the history
update armo infra
  • Loading branch information
Bezbran authored Jul 18, 2024
2 parents 92561ed + 7a06371 commit c80f2fe
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.5

require (
github.com/armosec/armoapi-go v0.0.432
github.com/armosec/armosec-infra v0.0.47
github.com/armosec/armosec-infra v0.0.48
github.com/aws/smithy-go v1.13.5
github.com/chidiwilliams/flatbson v0.3.0
github.com/dchest/uniuri v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/armosec/armoapi-go v0.0.432 h1:gBPiEIdIhNkKbk3WvCdIoO8utJvXaaNHMU5Irrw55U0=
github.com/armosec/armoapi-go v0.0.432/go.mod h1:mpok+lZaolcN5XRz/JxpwhfF8nln1OEKnGuvwAN+7Lo=
github.com/armosec/armosec-infra v0.0.47 h1:Gwdr3HFEO9Q34fnGQ7q8pgjorkZq4WxVy6M0/XectQY=
github.com/armosec/armosec-infra v0.0.47/go.mod h1:hwa40wxMdXDnn1LtV9r/ItN2MT7yFnELksVhiEjHe2Q=
github.com/armosec/armosec-infra v0.0.48 h1:ey8P/FkbYFU5F1E19iEFsPkZlOij2457cXqDbWwMcjE=
github.com/armosec/armosec-infra v0.0.48/go.mod h1:hwa40wxMdXDnn1LtV9r/ItN2MT7yFnELksVhiEjHe2Q=
github.com/armosec/gojay v1.2.17 h1:VSkLBQzD1c2V+FMtlGFKqWXNsdNvIKygTKJI9ysY8eM=
github.com/armosec/gojay v1.2.17/go.mod h1:vuvX3DlY0nbVrJ0qCklSS733AWMoQboq3cFyuQW9ybc=
github.com/armosec/utils-go v0.0.57 h1:0RaqexK+t7HeKWfldBv2C1JiLLGuUx9FP0DGWDNRJpg=
Expand Down
42 changes: 41 additions & 1 deletion service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import (
//go:embed test_data/clusters.json
var clustersJson []byte

//go:embed test_data/runtimeIncidentPolicyReq1.json
var runtimeIncidentPolicyReq1 []byte

//go:embed test_data/runtimeIncidentPolicyReq2.json
var runtimeIncidentPolicyReq2 []byte

var newClusterCompareFilter = cmp.FilterPath(func(p cmp.Path) bool {
switch p.String() {
case "PortalBase.GUID", "SubscriptionDate", "LastLoginDate", "PortalBase.UpdatedTime", "ExpirationDate":
Expand Down Expand Up @@ -2071,7 +2077,7 @@ func (suite *MainTestSuite) TestRuntimeIncidentPolicies() {
IncidentPolicy: policy,
})
}
for _, policy := range defaultPolicies {
for _, policy := range defaultPolicies { // double the policies for testing
defaultPoliciesPtr = append(defaultPoliciesPtr, &types.IncidentPolicy{
IncidentPolicy: policy,
})
Expand All @@ -2090,6 +2096,40 @@ func (suite *MainTestSuite) TestRuntimeIncidentPolicies() {
p.String() == "CreationDate" || p.String() == "IncidentPolicy.PortalBase.UpdatedTime" || p.String() == "UpdatedTime"
}, cmp.Ignore())
commonTestWithOptions(suite, consts.RuntimeIncidentPolicyPath, defaultPoliciesPtr, modifyDocFunc, testOpts, ignore, ignoreTime)

// test request example from event ingester
for _, policy := range defaultPolicies { // triple the policies for testing
policy.Scope.RiskFactors = []armotypes.RiskFactor{"risk1", "risk2"}
policy.Name += "-riskFactors"
defaultPoliciesPtr = append(defaultPoliciesPtr, &types.IncidentPolicy{
IncidentPolicy: policy,
})
}
testBulkPostDocs(suite, consts.RuntimeIncidentPolicyPath, defaultPoliciesPtr, ignore, ignoreTime)
w := suite.doRequest(http.MethodPost, consts.RuntimeIncidentPolicyPath+"/query", runtimeIncidentPolicyReq1)
suite.Equal(http.StatusOK, w.Code)
newDoc, err := decodeResponse[armotypes.V2ListResponseGeneric[[]*kdr.IncidentPolicy]](w)
if err != nil {
suite.FailNow(err.Error())
}
suite.Len(newDoc.Response, newDoc.Total.Value)
suite.Len(newDoc.Response, 2)
for _, doc := range newDoc.Response {
suite.NotNil(doc.GUID)
suite.Equal("Anomaly", doc.Name)
}
w = suite.doRequest(http.MethodPost, consts.RuntimeIncidentPolicyPath+"/query", runtimeIncidentPolicyReq2)
suite.Equal(http.StatusOK, w.Code)
newDoc, err = decodeResponse[armotypes.V2ListResponseGeneric[[]*kdr.IncidentPolicy]](w)
if err != nil {
suite.FailNow(err.Error())
}
suite.Len(newDoc.Response, newDoc.Total.Value)
suite.Len(newDoc.Response, 3)
for _, doc := range newDoc.Response {
suite.NotNil(doc.GUID)
suite.Equal("Anomaly", doc.Name[:7])
}
}

func (suite *MainTestSuite) TestIntegrationReference() {
Expand Down
32 changes: 32 additions & 0 deletions test_data/runtimeIncidentPolicyReq1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"pageSize": 100,
"pageNum": 0,
"innerFilters": [
{
"enabled": "true",
"managedRuleSetIDs": "c9fe6345-c393-4595-bd7b-22110dbafe61",
"ruleSetType": "Managed",
"scope.designators.cluster": "gke_elated-pottery-310110_us-central1-c_bez-longrun-3,|missing",
"scope.designators.kind": "Deployment,|missing",
"scope.designators.labels": ",|missing",
"scope.designators.name": "redis-sleep,|missing",
"scope.designators.namespace": "systest-ns-o9zz,|missing",
"scope.riskFactors": "|missing"
},
{
"enabled": "true",
"incidentTypeIDs": "I013,|missing",
"ruleSetType": "Custom",
"scope.designators.cluster": "gke_elated-pottery-310110_us-central1-c_bez-longrun-3,|missing",
"scope.designators.kind": "Deployment,|missing",
"scope.designators.labels": ",|missing",
"scope.designators.name": "redis-sleep,|missing",
"scope.designators.namespace": "systest-ns-o9zz,|missing",
"scope.riskFactors": "|missing"
}
],
"includeFields": [
"guid",
"name"
]
}
32 changes: 32 additions & 0 deletions test_data/runtimeIncidentPolicyReq2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"pageSize": 100,
"pageNum": 0,
"innerFilters": [
{
"enabled": "true",
"managedRuleSetIDs": "c9fe6345-c393-4595-bd7b-22110dbafe61",
"ruleSetType": "Managed",
"scope.designators.cluster": "gke_elated-pottery-310110_us-central1-c_bez-longrun-3,|missing",
"scope.designators.kind": "Deployment,|missing",
"scope.designators.labels": ",|missing",
"scope.designators.name": "redis-sleep,|missing",
"scope.designators.namespace": "systest-ns-o9zz,|missing",
"scope.riskFactors": "risk1,|missing"
},
{
"enabled": "true",
"incidentTypeIDs": "I013,|missing",
"ruleSetType": "Custom",
"scope.designators.cluster": "gke_elated-pottery-310110_us-central1-c_bez-longrun-3,|missing",
"scope.designators.kind": "Deployment,|missing",
"scope.designators.labels": ",|missing",
"scope.designators.name": "redis-sleep,|missing",
"scope.designators.namespace": "systest-ns-o9zz,|missing",
"scope.riskFactors": "|missing"
}
],
"includeFields": [
"guid",
"name"
]
}

0 comments on commit c80f2fe

Please sign in to comment.