Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor All Rego #132

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
4398e9e
Refactor long lines; refactor GetTopLevelOU function
adhilto Dec 27, 2023
8640cfd
Unify comment style
adhilto Dec 27, 2023
a339a4a
Remove 'no domain' helper rules
adhilto Dec 27, 2023
536b3c4
Change ServiceName to SettingName
adhilto Dec 27, 2023
94cdb4d
Refactor test cases
adhilto Dec 27, 2023
d61caee
Change lists to sets where possible
adhilto Dec 27, 2023
ab78f65
Chat change to for in syntax
adhilto Dec 28, 2023
57e3c05
Chat change to rule contains syntax
adhilto Dec 28, 2023
d6ac726
Refactor GetTopLevelOU function
adhilto Dec 28, 2023
24cf819
Change lists to sets where possible chat
adhilto Dec 28, 2023
48b686a
Remove trailing whitespace
adhilto Dec 28, 2023
6c7d27e
Change ServiceName to SettingName
adhilto Dec 28, 2023
39b372a
Standardize comment syntax chat
adhilto Dec 28, 2023
3090931
Refactor chat unit tests
adhilto Dec 28, 2023
c43eedc
Change to for in syntax
adhilto Dec 28, 2023
25823ad
Change to rule contains syntax classroom
adhilto Dec 28, 2023
0385689
Change ServiceName to SettingName
adhilto Dec 28, 2023
7810a05
Classroom change lists to sets where possible
adhilto Dec 28, 2023
9ca6789
Classroom standardize comments
adhilto Dec 28, 2023
6d03bc4
Refactor GetTopLevelOU function Classroom
adhilto Dec 28, 2023
439153c
Refactor Classroom unit tests
adhilto Dec 28, 2023
9edcb7d
Remove stray blank lines classroom
adhilto Dec 28, 2023
75727b3
Refactor common functions Drive
adhilto Dec 28, 2023
d548ecd
Drive change to some in syntax
adhilto Dec 28, 2023
5436193
Remove trailing whitespace
adhilto Dec 28, 2023
499489e
Remove more trailing whitespace
adhilto Dec 28, 2023
ee6a3d3
Change to rule contains syntax Drive
adhilto Dec 28, 2023
3fd46e6
Refactor long lines Drive
adhilto Dec 28, 2023
cbb38b8
Drive standardize comments
adhilto Dec 28, 2023
93180d6
Refactor Drive unit tests
adhilto Dec 28, 2023
767f7f1
Refactor drive 2 long lines
adhilto Dec 28, 2023
48ae729
Refactor groups unit tests
adhilto Dec 28, 2023
7984018
Groups standardize comments
adhilto Dec 30, 2023
b9bfb6a
Rego refactor meet
adhilto Dec 30, 2023
c36dd14
Refactor 'or' Drive
adhilto Dec 30, 2023
7a22b18
Refactor sites rego
adhilto Dec 30, 2023
02ef450
Refactor utils rego
adhilto Dec 30, 2023
99ec445
Move OUsWithEvents rule to the utils file
adhilto Dec 30, 2023
f848ca3
Calendar fill in topLevelOU in test cases with multiple OU as it cann…
adhilto Dec 30, 2023
23411c3
Chat fill in empty topLevelOU in test cases where needed
adhilto Dec 31, 2023
40912b1
Classroom fill in empty topLevelOU in test cases where needed
adhilto Dec 31, 2023
c9c10db
Drive unit tests fill in topLevelOU where required
adhilto Dec 31, 2023
46e77de
Gmail test cases add topLevelOU when needed
adhilto Dec 31, 2023
98b12dd
groups test cases add topLevelOU when needed
adhilto Dec 31, 2023
35e61dc
Meet test cases add topLevelOU when needed
adhilto Dec 31, 2023
1a11058
Move TopLevelOU rule to utils file
adhilto Dec 31, 2023
363e61d
Remove print statements
adhilto Dec 31, 2023
b99e889
Move GetLastEvent function to utils file
adhilto Dec 31, 2023
2b814b0
Moved all shared rego code to the utils file
adhilto Jan 2, 2024
e531c48
Import utils package instead of individual rules
adhilto Jan 2, 2024
906d767
push unsaved change
adhilto Jan 2, 2024
7fa34f7
Remove duplicates from list
adhilto Jan 3, 2024
bf1fc5f
Change SettingChangeEvents back to filter by log name for efficiency
adhilto Jan 3, 2024
260b199
Refactor groups 7
adhilto Jan 3, 2024
224b0c5
Ensure test names are unique
adhilto Jan 3, 2024
b36a237
Add regal config file
adhilto Jan 3, 2024
d194196
Add github workflow for regal
adhilto Jan 3, 2024
ef10861
Add missing ifs
adhilto Jan 3, 2024
e33872b
Bump the version of the regal exe
adhilto Jan 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/run_opa_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ jobs:

- name: Run OPA Tests
run: opa test rego/*.rego Testing/RegoTests/**/*.rego -v

- name: Setup Regal
uses: StyraInc/[email protected]
with:
version: v0.15.0

- name: Run Regal Lint
run: regal lint --format github rego Testing
60 changes: 60 additions & 0 deletions .regal/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Regal linter configuration
# All rules documented here:
# https://docs.styra.com/regal/category/rules
rules:
custom:
naming-convention:
# Codifying the conventions used in this project.
# By all means, change this to be less restrictive
# if you wish.
level: error
conventions:
- pattern: '^[A-Z]+[a-zA-Z0-9_]+$|^tests$|^test_|^check_'
targets:
- rule
- pattern: '^[A-Z]+[a-zA-Z0-9_]+$'
targets:
- function
- pattern: '^[a-z]+$'
targets:
- package
idiomatic:
no-defined-entrypoint:
# This is a good practice for documentation, and
# compilation to Wasm/IR, but not a requirement.
# Safe to ignore.
level: ignore
imports:
implicit-future-keywords:
# This rule is on it's way out anyway, as future
# versions of OPA will make these keywords standard.
level: ignore
style:
external-reference:
# This rule is quite opinionated / style preference
# safe to ignore.
level: ignore
file-length:
level: ignore
no-whitespace-comment:
# This repo is actually good about this, but frequently
# uses '#--' as a delimeter of sorts. That should be OK,
# and the next version of Regal will allow for exceptions
# like this: https://github.com/StyraInc/regal/issues/379
level: ignore
opa-fmt:
level: ignore
prefer-snake-case:
# This is the default style preference for Rego, but since
# the style of this project better matches the domain it is
# modeling, we'll ignore this rule in favor of the custom
# naming-convention rule defined above.
level: ignore
rule-length:
level: ignore
todo-comment:
level: ignore
testing:
test-outside-test-package:
# This is just a style preference
level: ignore
49 changes: 29 additions & 20 deletions Testing/RegoTests/calendar/calendar01_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test_ExtSharingPrimaryCal_Correct_V1 if {
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -66,7 +66,7 @@ test_ExtSharingPrimaryCal_Correct_V2 if {
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -102,11 +102,11 @@ test_ExtSharingPrimaryCal_Correct_V3 if {
}
]},
"tenant_info": {
"topLevelOU": ""
"topLevelOU": "Test Top-Level OU"
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -153,18 +153,18 @@ test_ExtSharingPrimaryCal_Correct_V4 if {
}
]},
"tenant_info": {
"topLevelOU": ""
"topLevelOU": "Test Top-Level OU"
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
RuleOutput[0].ReportDetails == "Requirement met in all OUs."
}

test_ExtSharingPrimaryCal_Correct_V4 if {
test_ExtSharingPrimaryCal_Correct_V5 if {
# Test external sharing for primary, inherit from parent
PolicyId := "GWS.CALENDAR.1.1v0.1"
Output := tests with input as {
Expand Down Expand Up @@ -204,11 +204,11 @@ test_ExtSharingPrimaryCal_Correct_V4 if {
}
]},
"tenant_info": {
"topLevelOU": ""
"topLevelOU": "Test Top-Level OU"
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -237,11 +237,15 @@ test_ExtSharingPrimaryCal_Incorrect_V1 if {
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
RuleOutput[0].NoSuchEvent
RuleOutput[0].ReportDetails == "No relevant event in the current logs for the top-level OU, Test Top-Level OU. While we are unable to determine the state from the logs, the default setting is non-compliant; manual check recommended."
RuleOutput[0].ReportDetails == concat("", [
"No relevant event in the current logs for the top-level OU, Test Top-Level OU. ",
"While we are unable to determine the state from the logs, the default setting ",
"is non-compliant; manual check recommended."
])
}

test_ExtSharingPrimaryCal_Incorrect_V2 if {
Expand All @@ -266,7 +270,7 @@ test_ExtSharingPrimaryCal_Incorrect_V2 if {
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -306,15 +310,16 @@ test_ExtSharingPrimaryCal_Incorrect_V3 if {
},
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
RuleOutput[0].ReportDetails == "Requirement failed in Test Top-Level OU."
}

test_ExtSharingPrimaryCal_Incorrect_V4 if {
# Test external sharing for primary calendars when there is no event for the Top-level OU but there is one for a different OU
# Test external sharing for primary calendars when there is no event for the Top-level OU
# but there is one for a different OU
PolicyId := "GWS.CALENDAR.1.1v0.1"
Output := tests with input as {
"calendar_logs": {"items": [
Expand All @@ -335,15 +340,20 @@ test_ExtSharingPrimaryCal_Incorrect_V4 if {
},
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
RuleOutput[0].NoSuchEvent
RuleOutput[0].ReportDetails == "No relevant event in the current logs for the top-level OU, Test Top-Level OU. While we are unable to determine the state from the logs, the default setting is non-compliant; manual check recommended."
RuleOutput[0].ReportDetails == concat("", [
"No relevant event in the current logs for the top-level OU, Test Top-Level OU. ",
"While we are unable to determine the state from the logs, the default setting ",
"is non-compliant; manual check recommended."
])
}

test_ExtSharingPrimaryCal_Incorrect_V5 if {
# Test external sharing for primary calendars when the Top-Level OU is compliant, but a secondary OU is non-compliant
# Test external sharing for primary calendars when the Top-Level OU is compliant,
# but a secondary OU is non-compliant
PolicyId := "GWS.CALENDAR.1.1v0.1"
Output := tests with input as {
"calendar_logs": {"items": [
Expand Down Expand Up @@ -375,11 +385,10 @@ test_ExtSharingPrimaryCal_Incorrect_V5 if {
},
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
print(RuleOutput[0].ReportDetails)
RuleOutput[0].ReportDetails == "Requirement failed in Secondary OU."

}
Expand All @@ -399,7 +408,7 @@ test_External_Sharing_Options_V1 if {
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
RuleOutput[0].NoSuchEvent
Expand Down
35 changes: 21 additions & 14 deletions Testing/RegoTests/calendar/calendar02_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test_ExtInvitationsWarning_Correct_V1 if {
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -66,7 +66,7 @@ test_ExtInvitationsWarning_Correct_V2 if {
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -102,11 +102,11 @@ test_ExtInvitationsWarning_Correct_V3 if {
}
]},
"tenant_info": {
"topLevelOU": ""
"topLevelOU": "Test Top-Level OU"
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -153,11 +153,11 @@ test_ExtInvitationsWarning_Correct_V4 if {
}
]},
"tenant_info": {
"topLevelOU": ""
"topLevelOU": "Test Top-Level OU"
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -186,11 +186,15 @@ test_ExtInvitationsWarning_Incorrect_V1 if {
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
RuleOutput[0].NoSuchEvent
RuleOutput[0].ReportDetails == "No relevant event in the current logs for the top-level OU, Test Top-Level OU. While we are unable to determine the state from the logs, the default setting is non-compliant; manual check recommended."
RuleOutput[0].ReportDetails == concat("", [
"No relevant event in the current logs for the top-level OU, Test Top-Level OU. ",
"While we are unable to determine the state from the logs, the default setting ",
"is non-compliant; manual check recommended."
])
}

test_ExtInvitationsWarning_Incorrect_V2 if {
Expand All @@ -215,7 +219,7 @@ test_ExtInvitationsWarning_Incorrect_V2 if {
}
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -255,7 +259,7 @@ test_ExtInvitationsWarning_Incorrect_V3 if {
},
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
Expand Down Expand Up @@ -284,11 +288,15 @@ test_ExtInvitationsWarning_Incorrect_V4 if {
},
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
RuleOutput[0].NoSuchEvent
RuleOutput[0].ReportDetails == "No relevant event in the current logs for the top-level OU, Test Top-Level OU. While we are unable to determine the state from the logs, the default setting is non-compliant; manual check recommended."
RuleOutput[0].ReportDetails == concat("", [
"No relevant event in the current logs for the top-level OU, Test Top-Level OU. ",
"While we are unable to determine the state from the logs, the default setting ",
"is non-compliant; manual check recommended."
])
}

test_ExtInvitationsWarning_Incorrect_V5 if {
Expand Down Expand Up @@ -324,11 +332,10 @@ test_ExtInvitationsWarning_Incorrect_V5 if {
},
}

RuleOutput := [Result | Result = Output[_]; Result.PolicyId == PolicyId]
RuleOutput := [Result | some Result in Output; Result.PolicyId == PolicyId]
count(RuleOutput) == 1
not RuleOutput[0].RequirementMet
not RuleOutput[0].NoSuchEvent
RuleOutput[0].ReportDetails == "Requirement failed in Secondary OU."
}

#--
Loading