-
Notifications
You must be signed in to change notification settings - Fork 42
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
MM-60036: License validation #832
base: master
Are you sure you want to change the base?
Conversation
This is to make testing easier. We can read the file outside of the function, no big deal.
A common error when providing a license is to use a different service environment (dev, test or production) to the one the license was generated for. This error is not surfaced by the call to ValidateLicense, so we explicitly test a different environment to the one currently in use to check whether license would be valid there. If that's the case, then we return a much more helpful error to the user.
Double-check that the error returned in case of a mismatch in the service environment is the one we expect.
deployment/terraform/create.go
Outdated
licenseData, err := os.ReadFile(t.config.MattermostLicenseFile) | ||
if err != nil { | ||
return fmt.Errorf("failed to read license file: %w", err) | ||
} | ||
|
||
if err := validateLicense(licenseData); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading from the file still seems like the right way for me. We can tweak the tests to move the license contents to a test asset file and read from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really see any more value in one or the other alternative, to be honest. I usually use "easier for testing" as a proxy for slightly better code, but it doesn't really matter where to get the license data from, a string or an asset file.
So I'll revert and use an asset file, then :)
cc @streamer45 as FYI |
Summary
A common error when providing a license is to use a different service environment (dev, test or production) to the one the license was generated for. This error is not surfaced by the call to
validator.ValidateLicense
, so we explicitly test a different environment to the one currently in use to check whether the license would be valid there. If that's the case, then we return a much more helpful error to the user.Note that the license in the test is not valid for production, only for test (and for 1 user just in case).
Ticket Link
https://mattermost.atlassian.net/browse/MM-60036