From 4e7e527de47bf98b9192f59c9414089f21749499 Mon Sep 17 00:00:00 2001 From: Lucas Fischer Date: Fri, 19 Jun 2026 09:53:10 +0800 Subject: [PATCH] fix(licensing): keep real expiry on license during grace period --- Sources/AmoreLicensing/AmoreLicensing.swift | 10 ++++------ Tests/AmoreLicensingTests/AmoreClientTests.swift | 6 ++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Sources/AmoreLicensing/AmoreLicensing.swift b/Sources/AmoreLicensing/AmoreLicensing.swift index 9cb1f12..a6442b0 100644 --- a/Sources/AmoreLicensing/AmoreLicensing.swift +++ b/Sources/AmoreLicensing/AmoreLicensing.swift @@ -227,15 +227,13 @@ public final class AmoreLicensing: Licensing { status = .invalid } } - - /// The license a still-within-grace expired payload represents, with its - /// expiry extended to the grace deadline, or `nil` once grace has elapsed. + + /// The license a still-within-grace expired payload represents, or `nil` once + /// the grace period has elapsed. private func graceLicense(for payload: LicensePayload) -> License? { let graceEnd = payload.exp.addingTimeInterval(configuration.gracePeriod.timeInterval) guard graceEnd >= .now else { return nil } - var license = License(from: payload) - license.expiresAt = graceEnd - return license + return License(from: payload) } private func mapClientErrors( diff --git a/Tests/AmoreLicensingTests/AmoreClientTests.swift b/Tests/AmoreLicensingTests/AmoreClientTests.swift index 22dc839..9fdf793 100644 --- a/Tests/AmoreLicensingTests/AmoreClientTests.swift +++ b/Tests/AmoreLicensingTests/AmoreClientTests.swift @@ -210,8 +210,7 @@ import Testing Issue.record("Expected gracePeriod, got \(result)") return } - let expectedEnd = expDate.addingTimeInterval(7 * 86_400) - #expect(abs(license.expiresAt!.timeIntervalSince(expectedEnd)) < 1) + #expect(abs(license.expiresAt!.timeIntervalSince(expDate)) < 1) } @Test func validateExpiredTokenValidates() async throws { @@ -358,8 +357,7 @@ import Testing Issue.record("Expected gracePeriod on first synchronous read, got \(client.status)") return } - let expectedEnd = expDate.addingTimeInterval(7 * 86_400) - #expect(abs(license.expiresAt!.timeIntervalSince(expectedEnd)) < 1) + #expect(abs(license.expiresAt!.timeIntervalSince(expDate)) < 1) } /// An expired token whose grace has already elapsed must stay `.unknown` at