mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
chore: Force license uuids to not be null (#6012)
* chore: Force license uuids to not be null * All unit tests generate uuids for licenses * Update migration files to new numbers * Put migration in transaction
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@ -128,6 +129,7 @@ func GenerateLicense(t *testing.T, options LicenseOptions) string {
|
||||
|
||||
c := &license.Claims{
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ID: uuid.NewString(),
|
||||
Issuer: "test@testing.test",
|
||||
ExpiresAt: jwt.NewNumericDate(options.ExpiresAt),
|
||||
NotBefore: jwt.NewNumericDate(time.Now().Add(-time.Minute)),
|
||||
|
@ -98,14 +98,19 @@ func (api *API) postLicense(rw http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
id, err := uuid.Parse(claims.ID)
|
||||
if err != nil {
|
||||
// If no uuid is in the license, we generate a random uuid.
|
||||
// This is not ideal, and this should be fixed to require a uuid
|
||||
// for all licenses. We require this patch to support older licenses.
|
||||
// TODO: In the future (April 2023?) we should remove this and reissue
|
||||
// old licenses with a uuid.
|
||||
id = uuid.New()
|
||||
}
|
||||
dl, err := api.Database.InsertLicense(ctx, database.InsertLicenseParams{
|
||||
UploadedAt: database.Now(),
|
||||
JWT: addLicense.License,
|
||||
Exp: expTime,
|
||||
Uuid: uuid.NullUUID{
|
||||
UUID: id,
|
||||
Valid: err == nil,
|
||||
},
|
||||
UUID: id,
|
||||
})
|
||||
if err != nil {
|
||||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
|
||||
@ -229,7 +234,7 @@ func (api *API) deleteLicense(rw http.ResponseWriter, r *http.Request) {
|
||||
func convertLicense(dl database.License, c jwt.MapClaims) codersdk.License {
|
||||
return codersdk.License{
|
||||
ID: dl.ID,
|
||||
UUID: dl.Uuid.UUID,
|
||||
UUID: dl.UUID,
|
||||
UploadedAt: dl.UploadedAt,
|
||||
Claims: c,
|
||||
}
|
||||
|
Reference in New Issue
Block a user