Files
aura-crm/production/backend/internal/license/status_test.go
T
root 56ffca767d feat: offline license/trial system
7-day full-access trial, then gated behind an Ed25519-signed license key
(internal/license) verified entirely offline — no phone-home dependency.
Middleware 402s non-exempt API routes once the trial lapses with no valid
key; frontend shows a countdown banner in the last 3 days and a blocking
overlay once actually gated, both pointing at the new Settings -> Лицензия
tab. tools/gen-license mints keys for the vendor side (never ships the
private key).
2026-08-21 18:44:54 +00:00

63 lines
1.6 KiB
Go

package license
import (
"testing"
"time"
)
func TestCheckNoKeyWithinTrialWindow(t *testing.T) {
s := Check("", time.Now().Add(-2*24*time.Hour))
if s.Licensed {
t.Error("Licensed = true with no key, want false")
}
if !s.TrialActive {
t.Error("TrialActive = false 2 days into a 7-day trial, want true")
}
if !s.Allowed() {
t.Error("Allowed() = false during active trial, want true")
}
}
func TestCheckNoKeyTrialExpired(t *testing.T) {
s := Check("", time.Now().Add(-8*24*time.Hour))
if s.TrialActive {
t.Error("TrialActive = true 8 days into a 7-day trial, want false")
}
if s.Allowed() {
t.Error("Allowed() = true after trial expiry with no license, want false")
}
}
func TestCheckInvalidKeyFallsBackToTrial(t *testing.T) {
s := Check("garbage-not-a-license-key", time.Now())
if s.Licensed {
t.Error("Licensed = true for an unparseable key, want false")
}
if !s.Allowed() {
t.Error("Allowed() = false with an invalid key but fresh trial, want true (trial covers it)")
}
}
func TestCheckTrialDaysLeftRoundsUp(t *testing.T) {
// 23 hours remaining should still read as 1 day left, not 0 — see
// status.go's own comment on why ceiling division matters here.
trialStart := time.Now().Add(-(TrialDuration - 23*time.Hour))
s := Check("", trialStart)
if s.TrialDaysLeft != 1 {
t.Errorf("TrialDaysLeft = %d with 23h remaining, want 1", s.TrialDaysLeft)
}
}
func TestCheckTrialDaysLeftExactDays(t *testing.T) {
trialStart := time.Now().Add(-(TrialDuration - 3*24*time.Hour))
s := Check("", trialStart)
if s.TrialDaysLeft != 3 {
t.Errorf("TrialDaysLeft = %d with exactly 3 days remaining, want 3", s.TrialDaysLeft)
}
}