MCPcopy Index your code
hub / github.com/coder/coder / GenerateLicense

Function GenerateLicense

enterprise/coderd/coderdenttest/coderdenttest.go:265–310  ·  view source on GitHub ↗

GenerateLicense returns a signed JWT using the test key.

(t *testing.T, options LicenseOptions)

Source from the content-addressed store, hash-verified

263
264// GenerateLicense returns a signed JWT using the test key.
265func GenerateLicense(t *testing.T, options LicenseOptions) string {
266 t.Helper()
267 if options.ExpiresAt.IsZero() {
268 options.ExpiresAt = time.Now().Add(time.Hour)
269 }
270 if options.GraceAt.IsZero() {
271 options.GraceAt = time.Now().Add(time.Hour)
272 }
273 if options.NotBefore.IsZero() {
274 options.NotBefore = time.Now().Add(-time.Minute)
275 }
276
277 issuedAt := options.IssuedAt
278 if issuedAt.IsZero() {
279 issuedAt = time.Now().Add(-time.Minute)
280 }
281
282 if !options.AllowEmpty && options.AccountType == "" {
283 options.AccountType = license.AccountTypeSalesforce
284 }
285 if !options.AllowEmpty && options.AccountID == "" {
286 options.AccountID = "test-account-id"
287 }
288
289 c := &license.Claims{
290 RegisteredClaims: jwt.RegisteredClaims{
291 ID: uuid.NewString(),
292 Issuer: "test@testing.test",
293 ExpiresAt: jwt.NewNumericDate(options.ExpiresAt),
294 NotBefore: jwt.NewNumericDate(options.NotBefore),
295 IssuedAt: jwt.NewNumericDate(issuedAt),
296 },
297 LicenseExpires: jwt.NewNumericDate(options.GraceAt),
298 AccountType: options.AccountType,
299 AccountID: options.AccountID,
300 DeploymentIDs: options.DeploymentIDs,
301 Trial: options.Trial,
302 Version: license.CurrentVersion,
303 AllFeatures: options.AllFeatures,
304 FeatureSet: options.FeatureSet,
305 Features: options.Features,
306 Addons: options.Addons,
307 PublishUsageData: options.PublishUsageData,
308 }
309 return GenerateLicenseRaw(t, c)
310}
311
312func GenerateLicenseRaw(t *testing.T, claims jwt.Claims) string {
313 t.Helper()

Callers 14

TestEntitlementsFunction · 0.92
TestPostLicenseFunction · 0.92
TestEntitlementsFunction · 0.92
TestUsageLimitFeaturesFunction · 0.92
TestAIGovernanceAddonFunction · 0.92
configureDeploymentFunction · 0.92
configureMockDeploymentFunction · 0.92
TestTrialerFunction · 0.92

Calls 4

GenerateLicenseRawFunction · 0.85
HelperMethod · 0.65
AddMethod · 0.65
IsZeroMethod · 0.45

Tested by 12

TestEntitlementsFunction · 0.74
TestPostLicenseFunction · 0.74
TestEntitlementsFunction · 0.74
TestUsageLimitFeaturesFunction · 0.74
TestAIGovernanceAddonFunction · 0.74
configureDeploymentFunction · 0.74
configureMockDeploymentFunction · 0.74
TestTrialerFunction · 0.74