mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
fix: stop reporting future licenses as errors (#14492)
This commit is contained in:
@ -199,6 +199,13 @@ func (opts *LicenseOptions) Valid(now time.Time) *LicenseOptions {
|
|||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (opts *LicenseOptions) FutureTerm(now time.Time) *LicenseOptions {
|
||||||
|
opts.NotBefore = now.Add(time.Hour * 24)
|
||||||
|
opts.ExpiresAt = now.Add(time.Hour * 24 * 60)
|
||||||
|
opts.GraceAt = now.Add(time.Hour * 24 * 53)
|
||||||
|
return opts
|
||||||
|
}
|
||||||
|
|
||||||
func (opts *LicenseOptions) UserLimit(limit int64) *LicenseOptions {
|
func (opts *LicenseOptions) UserLimit(limit int64) *LicenseOptions {
|
||||||
return opts.Feature(codersdk.FeatureUserLimit, limit)
|
return opts.Feature(codersdk.FeatureUserLimit, limit)
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,13 @@ func LicensesEntitlements(
|
|||||||
// 'Entitlements' group as a whole.
|
// 'Entitlements' group as a whole.
|
||||||
for _, license := range licenses {
|
for _, license := range licenses {
|
||||||
claims, err := ParseClaims(license.JWT, keys)
|
claims, err := ParseClaims(license.JWT, keys)
|
||||||
|
var vErr *jwt.ValidationError
|
||||||
|
if xerrors.As(err, &vErr) && vErr.Is(jwt.ErrTokenNotValidYet) {
|
||||||
|
// The license isn't valid yet. We don't consider any entitlements contained in it, but
|
||||||
|
// it's also not an error. Just skip it silently. This can happen if an administrator
|
||||||
|
// uploads a license for a new term that hasn't started yet.
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
entitlements.Errors = append(entitlements.Errors,
|
entitlements.Errors = append(entitlements.Errors,
|
||||||
fmt.Sprintf("Invalid license (%s) parsing claims: %s", license.UUID.String(), err.Error()))
|
fmt.Sprintf("Invalid license (%s) parsing claims: %s", license.UUID.String(), err.Error()))
|
||||||
|
@ -826,6 +826,25 @@ func TestLicenseEntitlements(t *testing.T) {
|
|||||||
assert.True(t, entitlements.Features[codersdk.FeatureCustomRoles].Enabled, "custom-roles enabled for premium")
|
assert.True(t, entitlements.Features[codersdk.FeatureCustomRoles].Enabled, "custom-roles enabled for premium")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "CurrentAndFuture",
|
||||||
|
Licenses: []*coderdenttest.LicenseOptions{
|
||||||
|
enterpriseLicense().UserLimit(100),
|
||||||
|
premiumLicense().UserLimit(200).FutureTerm(time.Now()),
|
||||||
|
},
|
||||||
|
Enablements: defaultEnablements,
|
||||||
|
AssertEntitlements: func(t *testing.T, entitlements codersdk.Entitlements) {
|
||||||
|
assertEnterpriseFeatures(t, entitlements)
|
||||||
|
assertNoErrors(t, entitlements)
|
||||||
|
assertNoWarnings(t, entitlements)
|
||||||
|
userFeature := entitlements.Features[codersdk.FeatureUserLimit]
|
||||||
|
assert.Equalf(t, int64(100), *userFeature.Limit, "user limit")
|
||||||
|
assert.Equal(t, codersdk.EntitlementNotEntitled,
|
||||||
|
entitlements.Features[codersdk.FeatureMultipleOrganizations].Entitlement)
|
||||||
|
assert.Equal(t, codersdk.EntitlementNotEntitled,
|
||||||
|
entitlements.Features[codersdk.FeatureCustomRoles].Entitlement)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
Reference in New Issue
Block a user