Functional Weave
Code in Rust

monitor.cert-expiry@1.0.0

vectors.json

2,598 bytes · view raw

[
  {"name": "sixty days left is ok", "args": [1767225600, 1762041600, 30, 7], "expect": {"state": "ok", "secondsLeft": 5184000, "daysLeft": 60}},
  {"name": "exactly thirty days left is not fewer than thirty: still ok", "args": [1767225600, 1764633600, 30, 7], "expect": {"state": "ok", "secondsLeft": 2592000, "daysLeft": 30}},
  {"name": "one second under thirty days is a warning", "args": [1767225600, 1764633601, 30, 7], "expect": {"state": "warning", "secondsLeft": 2591999, "daysLeft": 29}},
  {"name": "exactly seven days left is a warning, not critical", "args": [1767225600, 1766620800, 30, 7], "expect": {"state": "warning", "secondsLeft": 604800, "daysLeft": 7}},
  {"name": "one second under seven days is critical", "args": [1767225600, 1766620801, 30, 7], "expect": {"state": "critical", "secondsLeft": 604799, "daysLeft": 6}},
  {"name": "the notAfter second itself is still valid (RFC 5280: inclusive)", "args": [1767225600, 1767225600, 30, 7], "expect": {"state": "critical", "secondsLeft": 0, "daysLeft": 0}},
  {"name": "one second after notAfter is expired", "args": [1767225600, 1767225601, 30, 7], "expect": {"state": "expired", "secondsLeft": 0, "daysLeft": 0}},
  {"name": "long expired shows zero, never negative", "args": [1767225600, 1853625600, 30, 7], "expect": {"state": "expired", "secondsLeft": 0, "daysLeft": 0}},
  {"name": "with no thresholds the last second is ok", "args": [1767225600, 1767225599, 0, 0], "expect": {"state": "ok", "secondsLeft": 1, "daysLeft": 0}},
  {"name": "equal warn and critical days: never a warning, straight to critical", "args": [1767225600, 1766361600, 14, 14], "expect": {"state": "critical", "secondsLeft": 864000, "daysLeft": 10}},
  {"name": "half a day is zero whole days, critical", "args": [1767225600, 1767182400, 30, 1], "expect": {"state": "critical", "secondsLeft": 43200, "daysLeft": 0}},
  {"name": "the RFC 5280 no-expiry notAfter 99991231235959Z is ok for millions of days", "args": [253402300799, 1767225600, 30, 7], "expect": {"state": "ok", "secondsLeft": 251635075199, "daysLeft": 2912442}},
  {"name": "a negative criticalDays is an error", "args": [1767225600, 1767225600, 30, -1], "expectError": "criticalDays must be a whole number 0 or more, received -1"},
  {"name": "warnDays below criticalDays is an error", "args": [1767225600, 1767225600, 7, 14], "expectError": "warnDays must be a whole number at least criticalDays (14), received 7"},
  {"name": "a fractional now is an error", "args": [1767225600, 1.5, 30, 7], "expectError": "notAfter and now must be whole seconds, received 1767225600 and 1.5"}
]