mirror of
https://github.com/vxcontrol/cloud.git
synced 2026-07-19 11:51:48 -04:00
fix: correct license validity and expiration logic in tests and implementation
This commit is contained in:
+1
-1
@@ -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
@@ -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
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user