Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

agarciamontoro
Copy link
Member

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

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.
@agarciamontoro agarciamontoro added the 2: Dev Review Requires review by a core committer label Oct 15, 2024
Comment on lines 112 to 117
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 {
Copy link
Member

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.

Copy link
Member Author

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 :)

@agnivade
Copy link
Member

cc @streamer45 as FYI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2: Dev Review Requires review by a core committer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants