GenerateLicense returns a signed JWT using the test key.
(t *testing.T, options LicenseOptions)
| 263 | |
| 264 | // GenerateLicense returns a signed JWT using the test key. |
| 265 | func 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 | |
| 312 | func GenerateLicenseRaw(t *testing.T, claims jwt.Claims) string { |
| 313 | t.Helper() |