Repository navigation
CLI: coder licenses list - #3686
Conversation
Signed-off-by: Spike Curtis <spike@coder.com>
Signed-off-by: Spike Curtis <spike@coder.com>
| cb, err := base64.URLEncoding.DecodeString(parts[1]) | ||
| cb, err := base64.RawURLEncoding.DecodeString(parts[1]) |
There was a problem hiding this comment.
For those who had to look this up, there are four kinds of base64 encoding [1] [2]:
base64.URLEncoding: filename and URL-safe encoding, with paddingbase64.RawURLEncoding: filename and URL-safe encoding, without paddingbase64.StdEncoding: not safe for use in filenames and URLs, with paddingbase64.RawStdEncoding: not safe for use in filenames and URLs, without padding
[1] https://pkg.go.dev/encoding/base64#pkg-variables
[2] https://www.rfc-editor.org/rfc/rfc4648.html#section-4
| // We need a license in the DB, so that when we call GET api/v2/licenses there is one in the | ||
| // list to check authz on. | ||
| claims := &Claims{ | ||
| RegisteredClaims: jwt.RegisteredClaims{ | ||
| Issuer: "test@coder.test", | ||
| IssuedAt: jwt.NewNumericDate(time.Now()), | ||
| NotBefore: jwt.NewNumericDate(time.Now()), | ||
| ExpiresAt: jwt.NewNumericDate(time.Now().Add(2 * time.Hour)), | ||
| }, | ||
| LicenseExpires: jwt.NewNumericDate(time.Now().Add(time.Hour)), | ||
| AccountType: AccountTypeSalesforce, | ||
| AccountID: "testing", | ||
| Version: CurrentVersion, | ||
| Features: Features{ | ||
| UserLimit: 0, | ||
| AuditLog: 1, | ||
| }, | ||
| } | ||
| lic, err := makeLicense(claims, privKey, keyID) | ||
| require.NoError(t, err) | ||
| _, err = a.Client.AddLicense(ctx, codersdk.AddLicenseRequest{ | ||
| License: lic, | ||
| }) | ||
| require.NoError(t, err) |
There was a problem hiding this comment.
(nit, observation, non-blocking): This seems like something that we could shoe-horn into a coderdtest convenience function, as it might be useful elsewhere.
There was a problem hiding this comment.
yeah, it's gonna be needed for basically any test of enterprise-licensed features on the API...
I take this back. I have a better idea for enterprise features. But, it's needed for testing the parts of the API that deal with actual licenses.
johnstcn
left a comment
There was a problem hiding this comment.
I learned something new from reading this PR!
Fixes #3280
Also fixes a bug in the API where we used the wrong base64 encoding variant for JWTs.
Also, also adds proper support for testing that the API checks authz before returning licenses