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 static validation to middleware #106

Merged
merged 1 commit into from
May 20, 2024
Merged

Conversation

katherinelc321
Copy link
Collaborator

@katherinelc321 katherinelc321 commented May 7, 2024

What this PR does

Before this PR:
Not enough static validation on the frontend
After this PR:
Added validation for subscription ID, resource name, resource group name
Jira: ARO-5736
Link to demo recording:

Special notes for your reviewer

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

  • PR: The PR description is expressive enough and will help future contributors
  • Code: Write code that humans can understand and Keep it simple
  • Refactor: You have left the code cleaner than you found it (Boy Scout Rule)
  • Upgrade: Impact of this change on upgrade flows was considered and addressed if required
  • Deployment: The deployment process was considered and addressed if required
  • Testing: New code requires new unit tests.
  • Documentation: Is the documentation updated? Either in the doc located in focus area, in the README or in the code itself.
  • Customers: Is this change affecting customers? Is the release plan considered?

Copy link
Collaborator

@mbarnes mbarnes left a comment

Choose a reason for hiding this comment

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

Looks good overall, just some minor requests to reduce code duplication and unnecessary imports.

frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
internal/api/utils.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved

if resourceName != "" {
if !rxResourceGroupName.MatchString(resourceName) {
arm.WriteError(w, http.StatusBadRequest, arm.CloudErrorCodeResourceNotFound, "", "The Resource '%s/%s/%s' under resource group '%s' was not found.", resourceProviderNamespace, resourceType, resourceName, resourceGroupName)
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't actually check if the resourceName exists within a resourceGroup. If we are trying to validate the resourceName, we should have an error message tailored to the check. Do the resourceGroup and resourceName have the same requirements?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Each resource has their own requirements. The resource group one is a good upper limit. I can also narrow it down to this from the api spec:
"name": "hcpOpenShiftClusterName",
"in": "path",
"description": "Name of HCP cluster",
"required": true,
"type": "string",
"minLength": 3,
"maxLength": 24,
"pattern": "^[a-zA-Z0-9-]{3,24}$"
}

frontend/middleware_validatestatic.go Show resolved Hide resolved
Copy link

Please rebase pull request.

Copy link

Please rebase pull request.

Copy link
Member

@petrkotas petrkotas left a comment

Choose a reason for hiding this comment

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

Hi @katherinelc321 thank you for doing the extra validation. I agree it is important to do it right from the start. Overall the PR is on a good path with some minor tweaks needed. Would you please look at the comments ?

frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@mbarnes mbarnes left a comment

Choose a reason for hiding this comment

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

Some more changes are needed, see comments below.

tl;dr The path segment constants you're adding are not being used in the route patterns, so those path values will not be set. I make a case for why they may not be necessary anyway.

frontend/const.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
internal/api/utils.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
frontend/middleware_validatestatic.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@mbarnes mbarnes left a comment

Choose a reason for hiding this comment

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

LGTM now, thanks!

Copy link
Contributor

@s-amann s-amann left a comment

Choose a reason for hiding this comment

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

Thank you for making those changes, lgtm!

@s-amann s-amann merged commit a87ee6d into Azure:main May 20, 2024
5 checks passed
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.

4 participants