Skip to content

Commit

Permalink
Refactor Exo Rego Code (#662)
Browse files Browse the repository at this point in the history
* first round of cleanup

first round of cleanup

* create helper funtion for conditions filter code

create helper funtion for conditions filter code

* add comments pt 1

add comments pt 1

add comments pt 2

add comments pt 2

* update syntax for constant

update syntax for constant

* update for test package

update for test package

* fix policy indicated comments

fix policy indicated comments

* fix json formatting & rego formatting

fix json formatting & rego formatting

* refactor out duplicate code in tests

refactor out duplicate code in tests

* remove unused imports

remove unused imports

* remove unused var

remove unused var

* remove constant
  • Loading branch information
Sloane4 authored and james-garriss committed Dec 14, 2023
1 parent 535c9ef commit 2c9c7a5
Show file tree
Hide file tree
Showing 18 changed files with 1,677 additions and 1,395 deletions.
969 changes: 553 additions & 416 deletions Rego/EXOConfig.rego

Large diffs are not rendered by default.

95 changes: 48 additions & 47 deletions Testing/Unit/Rego/EXO/EXOConfig_01_test.rego
Original file line number Diff line number Diff line change
@@ -1,94 +1,95 @@
package exo
package exo_test
import future.keywords
import data.exo
import data.report.utils.ReportDetailsBoolean


CorrectTestResult(PolicyId, Output, ReportDetailString) := true if {
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]

count(RuleOutput) == 1
RuleOutput[0].RequirementMet == true
RuleOutput[0].ReportDetails == ReportDetailString
} else := false

IncorrectTestResult(PolicyId, Output, ReportDetailString) := true if {
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]

count(RuleOutput) == 1
RuleOutput[0].RequirementMet == false
RuleOutput[0].ReportDetails == ReportDetailString
} else := false

PASS := ReportDetailsBoolean(true)


#
# Policy 1
#--
test_AutoForwardEnabled_Correct if {
PolicyId := "MS.EXO.1.1v1"

Output := tests with input as {
Output := exo.tests with input as {
"remote_domains": [
{
"AutoForwardEnabled" : false,
"DomainName" : "Test name"
"AutoForwardEnabled": false,
"DomainName": "Test name"
}
]
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]

count(RuleOutput) == 1
RuleOutput[0].RequirementMet
RuleOutput[0].ReportDetails == "Requirement met"
CorrectTestResult("MS.EXO.1.1v1", Output, PASS) == true
}

test_AutoForwardEnabled_Incorrect_V1 if {
PolicyId := "MS.EXO.1.1v1"

Output := tests with input as {
Output := exo.tests with input as {
"remote_domains": [
{
"AutoForwardEnabled" : true,
"DomainName" : "Test name"
"AutoForwardEnabled": true,
"DomainName": "Test name"
}
]
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]

count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
RuleOutput[0].ReportDetails == "1 remote domain(s) that allows automatic forwarding: Test name"
ReportDetailString := "1 remote domain(s) that allows automatic forwarding: Test name"
IncorrectTestResult("MS.EXO.1.1v1", Output, ReportDetailString) == true
}

test_AutoForwardEnabled_Incorrect_V2 if {
PolicyId := "MS.EXO.1.1v1"

Output := tests with input as {
Output := exo.tests with input as {
"remote_domains": [
{
"AutoForwardEnabled" : true,
"DomainName" : "Test name"
"AutoForwardEnabled": true,
"DomainName": "Test name"
},
{
"AutoForwardEnabled" : true,
"DomainName" : "Test name 2"
"AutoForwardEnabled": true,
"DomainName": "Test name 2"
}
]
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]

count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
RuleOutput[0].ReportDetails == "2 remote domain(s) that allows automatic forwarding: Test name, Test name 2"
ReportDetailString := "2 remote domain(s) that allows automatic forwarding: Test name, Test name 2"
IncorrectTestResult("MS.EXO.1.1v1", Output, ReportDetailString) == true
}

test_AutoForwardEnabled_Incorrect_V3 if {
PolicyId := "MS.EXO.1.1v1"

Output := tests with input as {
Output := exo.tests with input as {
"remote_domains": [
{
"AutoForwardEnabled" : true,
"DomainName" : "Test name"
"AutoForwardEnabled": true,
"DomainName": "Test name"
},
{
"AutoForwardEnabled" : true,
"DomainName" : "Test name 2"
"AutoForwardEnabled": true,
"DomainName": "Test name 2"
},
{
"AutoForwardEnabled" : false,
"DomainName" : "Test name 3"
"AutoForwardEnabled": false,
"DomainName": "Test name 3"
}
]
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]

count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
RuleOutput[0].ReportDetails == "2 remote domain(s) that allows automatic forwarding: Test name, Test name 2"
ReportDetailString := "2 remote domain(s) that allows automatic forwarding: Test name, Test name 2"
IncorrectTestResult("MS.EXO.1.1v1", Output, ReportDetailString) == true
}
#--
Loading

0 comments on commit 2c9c7a5

Please sign in to comment.