Skip to content

Commit 03a2b8a

Browse files
authored
Merge pull request #7 from AmoreComputer/fix/grace-period-preserves-expiry
fix(licensing): keep real expiry on license during grace period
2 parents e9a658d + 4e7e527 commit 03a2b8a

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

‎Sources/AmoreLicensing/AmoreLicensing.swift‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,13 @@ public final class AmoreLicensing: Licensing {
227227
status = .invalid
228228
}
229229
}
230-
231-
/// The license a still-within-grace expired payload represents, with its
232-
/// expiry extended to the grace deadline, or `nil` once grace has elapsed.
230+
231+
/// The license a still-within-grace expired payload represents, or `nil` once
232+
/// the grace period has elapsed.
233233
private func graceLicense(for payload: LicensePayload) -> License? {
234234
let graceEnd = payload.exp.addingTimeInterval(configuration.gracePeriod.timeInterval)
235235
guard graceEnd >= .now else { return nil }
236-
var license = License(from: payload)
237-
license.expiresAt = graceEnd
238-
return license
236+
return License(from: payload)
239237
}
240238

241239
private func mapClientErrors<T>(

‎Tests/AmoreLicensingTests/AmoreClientTests.swift‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ import Testing
210210
Issue.record("Expected gracePeriod, got \(result)")
211211
return
212212
}
213-
let expectedEnd = expDate.addingTimeInterval(7 * 86_400)
214-
#expect(abs(license.expiresAt!.timeIntervalSince(expectedEnd)) < 1)
213+
#expect(abs(license.expiresAt!.timeIntervalSince(expDate)) < 1)
215214
}
216215

217216
@Test func validateExpiredTokenValidates() async throws {
@@ -358,8 +357,7 @@ import Testing
358357
Issue.record("Expected gracePeriod on first synchronous read, got \(client.status)")
359358
return
360359
}
361-
let expectedEnd = expDate.addingTimeInterval(7 * 86_400)
362-
#expect(abs(license.expiresAt!.timeIntervalSince(expectedEnd)) < 1)
360+
#expect(abs(license.expiresAt!.timeIntervalSince(expDate)) < 1)
363361
}
364362

365363
/// An expired token whose grace has already elapsed must stay `.unknown` at

0 commit comments

Comments
 (0)