I’m trying to write a sentinel policy that will read a date provided in structured data. After reading the docs a few times I’m still unclear what the best approach is. I basically need to have the policy fail if the date is within two weeks. Using the sentinel simulator I’m failing to mock or otherwise provide a date as part of the test configuration.
The test policy I’m using is this.
import "time"
time_now = time.now
print(" Time Now :",time_now.rfc3339)
time_loaded = time.load("3030-08-28T00:00:00Z")
print("Time Loaded :",time_loaded.rfc3339)
if time_now.rfc3339 matches time_loaded.rfc3339 {
matching_times = true
} else {
matching_times = false
}
main = rule {
matching_times
}
Setting the time as a global in test file like so…
{
"global": {
"time": {
"now": {
"day": 28,
"hour": 0,
"minute": 0,
"month": 8,
"month_name": "August",
"rfc3339": "3030-08-28T00:00:00Z",
"second": 0,
"unix": 33471014400,
"unix_nano": -3422473747419103232,
"weekday": 6,
"weekday_name": "Saturday",
"year": 3030,
"zone": 0,
"zone_string": "+00:00"
}
},
"test": {
"main": true
}
}
}
This test fails and the date is not being passed to time.now
FAIL - time_mock.sentinel
FAIL - test/time_mock/global_time.json
expected "main" to be true, got: false
logs:
Time Now : 2019-10-29T21:13:08.563419362Z
Time Loaded : 3030-08-28T00:00:00Z
trace:
FALSE - time_mock.sentinel:16:1 - Rule "main"
Here is the test config file for doing a mock date.
{
"mock": {
"time": {
"now": {
"day": 28,
"hour": 0,
"minute": 0,
"month": 8,
"month_name": "August",
"rfc3339": "3030-08-28T00:00:00Z",
"second": 0,
"unix": 33471014400,
"unix_nano": -3422473747419103232,
"weekday": 6,
"weekday_name": "Saturday",
"year": 3030,
"zone": 0,
"zone_string": "+00:00"
}
}
},
"test": {
"main": true
}
}
On the test I configured to mock the date it’s failing strangely. The time is correct but the time.load() is failing for some reason.
ERROR - test/time_mock/mock_time.json
Error: time_mock.sentinel:7:15: key "load" doesn't support function calls
logs:
Time Now : 3030-08-28T00:00:00Z
trace:
The code is stored in this repo https://github.com/trodemaster/sentinel-sandbox Looking for suggestions on how to create the policy and test it with dates included in the config file.
Thanks,
Blake