fix: correct license validity and expiration logic in tests and implementation

This commit is contained in:
Dmitry Ng
2026-03-29 16:35:39 +03:00
parent e8b7ea3f9b
commit 8d6ac65160
3 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ func (l *LicenseInfo) IsValid() bool {
}
func (l *LicenseInfo) IsExpired() bool {
return l.Type == LicenseExpireable && l.ExpiredAt.After(alignDays(time.Now().UTC()))
return l.Type == LicenseExpireable && l.ExpiredAt.Before(alignDays(time.Now().UTC()))
}
type licenseData struct {
+6 -6
View File
@@ -391,8 +391,8 @@ func TestLicenseInfoMethods(t *testing.T) {
ExpiredAt: yesterday, // past date
CreatedAt: now.AddDate(0, 0, -10),
},
expectedValid: true, // not expired per client logic
expectedExpired: false, // .After(now) is false for yesterday
expectedValid: false, // expired license is not valid
expectedExpired: true, // .Before(now) is true for yesterday
},
{
name: "expireable_expires_tomorrow",
@@ -402,8 +402,8 @@ func TestLicenseInfoMethods(t *testing.T) {
ExpiredAt: tomorrow,
CreatedAt: yesterday,
},
expectedValid: false, // !IsExpired() will be false since tomorrow.After(now) = true
expectedExpired: true, // tomorrow.After(now) = true
expectedValid: true, // not expired yet, still valid
expectedExpired: false, // tomorrow.Before(now) = false
},
{
name: "invalid_perpetual_with_expiry",
@@ -425,7 +425,7 @@ func TestLicenseInfoMethods(t *testing.T) {
CreatedAt: tomorrow, // future creation date
},
expectedValid: false, // fails future CreatedAt check
expectedExpired: true, // future ExpiredAt.After(now) = true
expectedExpired: false, // ExpiredAt.Before(now) = false
},
{
name: "invalid_zero_created_at",
@@ -436,7 +436,7 @@ func TestLicenseInfoMethods(t *testing.T) {
CreatedAt: time.Time{}, // zero time
},
expectedValid: false, // fails zero CreatedAt check
expectedExpired: true, // tomorrow.After(now) = true
expectedExpired: false, // tomorrow.Before(now) = false
},
}
+2 -2
View File
@@ -61,7 +61,7 @@
],
"expired_at": "2035-01-01T00:00:00Z",
"created_at": "2025-09-16T00:00:00Z",
"valid": false
"valid": true
},
{
"name": "invalid_expired",
@@ -78,7 +78,7 @@
],
"expired_at": "2025-06-16T00:00:00Z",
"created_at": "2025-06-15T00:00:00Z",
"valid": true
"valid": false
},
{
"name": "invalid_future_created_at",