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

Add validation to org subdomain during signup, and add a list of reserved subdomains. #3066

Merged
merged 4 commits into from
Aug 31, 2022

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Aug 30, 2022

Summary

This PR adds validation to the org subdomain, including min/max length, character restrictions, and a list of reserved words that we should not allow to be subdomains.

Best viewed by individual commit, more details in commit messages.

@@ -12,6 +12,33 @@ type SignupOrg struct {
Subdomain string `json:"subDomain"`
}

var reservedSubDomains = []string{
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ssoroka also had a list of reserved subdomains. Perhaps you should work together on this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to add or edit this list! I should have mentioned that in the PR description.

Please do suggest changes to this list and I can update it.

@dnephin dnephin force-pushed the dnephin/orgs-reserve-sub-domains branch from b06786f to 6f60a09 Compare August 30, 2022 20:46
Comment on lines +24 to +30
validate.StringRule{
Name: "token",
Value: r.Token,
MinLength: 10,
MaxLength: 10,
CharacterRanges: validate.AlphaNumeric,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

way less elegant :P

validate.Required("name", r.Name),
validate.Required("subDomain", r.Subdomain),
validate.ReservedStrings("subDomain", r.Subdomain, reservedSubDomains),
validate.StringRule{
Copy link
Contributor

Choose a reason for hiding this comment

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

not necessarily a blocker, but it's missing the can't-start-with-dash case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added first character validation to the StringRule and added it here as well

So that the openAPI doc is generated correctly. The validation rules continue to work the
same way.
Functions with more than 3 arguments are hard to use, especially when some of the args
have the same type. From the caller it's not easy to see what the values represent.

Using a string makes the code more obvious because we can see the value 10 is for
length. The field names help document what the values mean.

Also remove a TODO, the password critiera are validated in the access package.
Add a new validation rule for restricting strings, and use it to validate the org subdomain.

Also add min/max length and character restrictions.
@dnephin dnephin force-pushed the dnephin/orgs-reserve-sub-domains branch from 92d1740 to b63ed2c Compare August 31, 2022 16:04
@dnephin dnephin merged commit 78b7572 into main Aug 31, 2022
@dnephin dnephin deleted the dnephin/orgs-reserve-sub-domains branch August 31, 2022 16:12
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.

None yet

3 participants