Skip to content

Commit 4eac2ac

Browse files
authored
fix: stop reporting future licenses as errors (#14492)
1 parent 5bd5801 commit 4eac2ac

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

enterprise/coderd/coderdenttest/coderdenttest.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ func (opts *LicenseOptions) Valid(now time.Time) *LicenseOptions {
199199
return opts
200200
}
201201

202+
func (opts *LicenseOptions) FutureTerm(now time.Time) *LicenseOptions {
203+
opts.NotBefore = now.Add(time.Hour * 24)
204+
opts.ExpiresAt = now.Add(time.Hour * 24 * 60)
205+
opts.GraceAt = now.Add(time.Hour * 24 * 53)
206+
return opts
207+
}
208+
202209
func (opts *LicenseOptions) UserLimit(limit int64) *LicenseOptions {
203210
return opts.Feature(codersdk.FeatureUserLimit, limit)
204211
}

enterprise/coderd/license/license.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ func LicensesEntitlements(
100100
// 'Entitlements' group as a whole.
101101
for _, license := range licenses {
102102
claims, err := ParseClaims(license.JWT, keys)
103+
var vErr *jwt.ValidationError
104+
if xerrors.As(err, &vErr) && vErr.Is(jwt.ErrTokenNotValidYet) {
105+
// The license isn't valid yet. We don't consider any entitlements contained in it, but
106+
// it's also not an error. Just skip it silently. This can happen if an administrator
107+
// uploads a license for a new term that hasn't started yet.
108+
continue
109+
}
103110
if err != nil {
104111
entitlements.Errors = append(entitlements.Errors,
105112
fmt.Sprintf("Invalid license (%s) parsing claims: %s", license.UUID.String(), err.Error()))

enterprise/coderd/license/license_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,25 @@ func TestLicenseEntitlements(t *testing.T) {
826826
assert.True(t, entitlements.Features[codersdk.FeatureCustomRoles].Enabled, "custom-roles enabled for premium")
827827
},
828828
},
829+
{
830+
Name: "CurrentAndFuture",
831+
Licenses: []*coderdenttest.LicenseOptions{
832+
enterpriseLicense().UserLimit(100),
833+
premiumLicense().UserLimit(200).FutureTerm(time.Now()),
834+
},
835+
Enablements: defaultEnablements,
836+
AssertEntitlements: func(t *testing.T, entitlements codersdk.Entitlements) {
837+
assertEnterpriseFeatures(t, entitlements)
838+
assertNoErrors(t, entitlements)
839+
assertNoWarnings(t, entitlements)
840+
userFeature := entitlements.Features[codersdk.FeatureUserLimit]
841+
assert.Equalf(t, int64(100), *userFeature.Limit, "user limit")
842+
assert.Equal(t, codersdk.EntitlementNotEntitled,
843+
entitlements.Features[codersdk.FeatureMultipleOrganizations].Entitlement)
844+
assert.Equal(t, codersdk.EntitlementNotEntitled,
845+
entitlements.Features[codersdk.FeatureCustomRoles].Entitlement)
846+
},
847+
},
829848
}
830849

831850
for _, tc := range testCases {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy