Skip to content

CLI: coder licenses list #3686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2022
Merged

Conversation

spikecurtis
Copy link
Contributor

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

Signed-off-by: Spike Curtis <spike@coder.com>
Signed-off-by: Spike Curtis <spike@coder.com>
@spikecurtis spikecurtis requested a review from a team August 24, 2022 20:51
Comment on lines -256 to +257
cb, err := base64.URLEncoding.DecodeString(parts[1])
cb, err := base64.RawURLEncoding.DecodeString(parts[1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 padding
  • base64.RawURLEncoding: filename and URL-safe encoding, without padding
  • base64.StdEncoding: not safe for use in filenames and URLs, with padding
  • base64.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

Comment on lines +38 to +61
// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit, observation, non-blocking): This seems like something that we could shoe-horn into a coderdtest convenience function, as it might be useful elsewhere.

Copy link
Contributor Author

@spikecurtis spikecurtis Aug 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learned something new from reading this PR!

@spikecurtis spikecurtis merged commit 4de1fc8 into main Aug 25, 2022
@spikecurtis spikecurtis deleted the spike/3280_coder_licenses_list_cli branch August 25, 2022 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GET license claims API
2 participants