45 lines
3.5 KiB
C#
45 lines
3.5 KiB
C#
namespace UCVL.VPNPlus;
|
|
|
|
internal static class ConnectionAuthorizationSelfTest
|
|
{
|
|
internal static Dictionary<string, bool> Check()
|
|
{
|
|
var checks = new Dictionary<string, bool>();
|
|
var now = DateTimeOffset.Parse("2026-11-05T00:00:00Z");
|
|
var lease = new ConnectionAuthorizationLease();
|
|
lease.Reset(null, now, 1000);
|
|
checks["unknown_deadline_does_not_expire_existing_core"] = lease.AccountIsValid(now.AddDays(1), 86_401_000);
|
|
lease.AcceptProfile("active", null, now, 1000);
|
|
checks["explicit_long_term_profile_has_no_invented_expiry"] = lease.CanRetain(now.AddDays(100), 8_640_001_000, false, 0);
|
|
checks["valid_private_lease_can_be_retained_during_api_outage"] = lease.CanRetain(now, 1000, true, 2000);
|
|
checks["expired_private_lease_cannot_be_retained"] = !lease.CanRetain(now, 2000, true, 2000);
|
|
checks["private_expiry_does_not_mark_account_expired_or_shadow_renewal"] = lease.AccountIsValid(now, 2000);
|
|
lease.AcceptProfile("active", now.AddSeconds(10), now, 1000);
|
|
checks["known_subscription_expiry_is_enforced"] = lease.AccountIsValid(now.AddSeconds(9), 10_000)
|
|
&& !lease.AccountIsValid(now.AddSeconds(10), 11_000);
|
|
checks["clock_rollback_cannot_extend_known_subscription"] = !lease.AccountIsValid(now.AddDays(-1), 11_000);
|
|
lease.AcceptProfile("active", now.AddSeconds(10), now.AddDays(-1), 11_000);
|
|
checks["same_profile_refresh_cannot_extend_deadline_after_clock_rollback"] = !lease.AccountIsValid(now.AddDays(-1), 11_000);
|
|
lease.AcceptProfile("active", now.AddDays(1), now.AddSeconds(10), 11_000);
|
|
checks["fresh_authenticated_profile_can_renew_subscription"] = lease.AccountIsValid(now.AddHours(1), 3_601_000);
|
|
lease.Reset(now.AddSeconds(5), now, 1000);
|
|
lease.AcceptProfile("active", now.AddDays(1), now, 1000);
|
|
checks["profile_cannot_extend_known_login_session_expiry"] = !lease.AccountIsValid(now.AddSeconds(5), 6000);
|
|
lease.Reset(null, now, 1000);
|
|
lease.AcceptProfile("suspended", null, now, 1000);
|
|
checks["explicit_inactive_status_is_not_retained"] = !lease.AccountIsValid(now, 1000);
|
|
lease.Reset(null, now, 1000);
|
|
lease.AcceptProfile("", null, now, 1000);
|
|
checks["legacy_fixture_without_status_or_deadline_is_not_expired"] = lease.AccountIsValid(now, 1000);
|
|
foreach (var failure in new Exception[] { new TimeoutException(), new HttpRequestException(), new ApiException(500, "fixture outage"), new ApiException(503, "fixture outage") })
|
|
checks["fresh_grant_failure_keeps_running_authorized_core_" + failure.GetType().Name + checks.Count]
|
|
= ConnectionRecoveryPolicy.KeepExisting(true, false, true, failure, true);
|
|
checks["expiry_prevents_control_plane_retention"] = !ConnectionRecoveryPolicy.KeepExisting(true, false, true, new TimeoutException(), false);
|
|
checks["revocation_still_ends_existing_session"] = !ConnectionRecoveryPolicy.KeepExisting(true, false, true, new ApiException(401, "revoked"), true)
|
|
&& !ConnectionRecoveryPolicy.KeepExisting(true, false, true, new ApiException(403, "revoked"), true);
|
|
checks["no_offline_new_login_or_connection_granted"] = !ConnectionRecoveryPolicy.KeepExisting(false, false, false, new TimeoutException(), true);
|
|
checks["already_replaced_core_is_not_falsely_retained"] = !ConnectionRecoveryPolicy.KeepExisting(true, true, true, new TimeoutException(), true);
|
|
return checks;
|
|
}
|
|
}
|