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

Parse datacenter from request #12370

Merged

Conversation

thisisnotashwin
Copy link
Contributor

@thisisnotashwin thisisnotashwin commented Feb 16, 2022

Parse the value of the datacenter from the create/delete requests for AuthMethods and BindingRules so that they can be created in and deleted from the datacenters specified in the request.

@thisisnotashwin thisisnotashwin added the type/bug Feature does not function as expected label Feb 16, 2022
@thisisnotashwin thisisnotashwin requested review from ishustava and a team February 16, 2022 21:38
@thisisnotashwin thisisnotashwin force-pushed the ashwin/parse-dc-for-authmethod-and-binding-create branch from e363809 to 79b009b Compare February 16, 2022 21:40
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 16, 2022 21:40 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 16, 2022 21:40 Inactive
- Parse the value of the datacenter from the create/delete requests for
  AuthMethods and BindingRules so that they can be created in and
deleted from the datacenters specified in the request.
@thisisnotashwin thisisnotashwin force-pushed the ashwin/parse-dc-for-authmethod-and-binding-create branch from 79b009b to c05e37c Compare February 17, 2022 14:42
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 17, 2022 14:42 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 17, 2022 14:42 Inactive
@@ -1341,7 +1361,7 @@ func TestACL_LoginProcedure_HTTP(t *testing.T) {
BindName: "web",
}

req, _ := http.NewRequest("PUT", "/v1/acl/binding-rule?token=root", jsonBody(ruleInput))
Copy link
Contributor

Choose a reason for hiding this comment

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

hm, are those breaking changes?

as in, if I'm a practitioner on 1.10.x or 1.11.x and don't URL encode the datacenter, will my existing code still work?

It doesn't seem like it right?

Copy link
Member

Choose a reason for hiding this comment

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

parseDC should also default the datacenter to the current one:

// parseDC is used to parse the ?dc query param
func (s *HTTPHandlers) parseDC(req *http.Request, dc *string) {
	if other := req.URL.Query().Get("dc"); other != "" {
		*dc = other
	} else if *dc == "" {
		*dc = s.agent.config.Datacenter
	}
}

I don't think these test assertions should need &dc=dc1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not a breaking change! If no datacenter is provided, it will continue to behave as it previously did. In case someone was passing a query param that referenced a datacenter that was incorrect, that will fail, but that would be desired behavior.

This actually ensures consistent behavior between the read/list requests and the write and delete requests!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the tests @rboyer

.changelog/12370.txt Outdated Show resolved Hide resolved
Co-authored-by: Iryna Shustava <ishustava@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 17, 2022 17:42 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 17, 2022 17:42 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 17, 2022 17:45 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 17, 2022 17:45 Inactive
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for making this change!

A couple non-blocking suggestion for the tests. I think it applies to both of the new cases, but I only commented on one.


req, _ := http.NewRequest("PUT", "/v1/acl/auth-method?token=root&dc=invalid", jsonBody(methodInput))
resp := httptest.NewRecorder()
_, err := a.srv.ACLAuthMethodCRUD(resp, req)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker, just an FYI that we've started to change our tests to do this: #11396

Right now the url path on line 1237 is ignored (the query params are used though), and the test doesn't exercise any of the wrappers around endpoints.

Instead of calling ACLAuthMethodCRUD we are moving to call a.srv.h.ServeHTTP, which makes the test closer to a real API call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙏 thanks for the heads up! I don't mind making this change across the file.

@@ -1222,6 +1222,26 @@ func TestACL_LoginProcedure_HTTP(t *testing.T) {
methodMap[method.Name] = method
})

t.Run("Create in invalid datacenter", func(t *testing.T) {
Copy link
Contributor

@dnephin dnephin Feb 17, 2022

Choose a reason for hiding this comment

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

Not a blocker, but I believe the purpose of this test is to show we accept a dc query parameter, right? Since we don't have a backend interface we can fake, and we don't want to have to setup a whole second server in a different DC the test happens to fail with invalid DC. But I believe the underlying thing we are testing is that parseDC is called and sets the DC value correct. The current name suggests it is more about testing validation of the dc query parameter, but I think that might be more incidental than the primary purpose of the case.

I would suggest changing the name to something like this:

Suggested change
t.Run("Create in invalid datacenter", func(t *testing.T) {
t.Run("Create in remote datacenter", func(t *testing.T) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good catch. I was testing incidental behavior purely for the reasons you have described. Ill rename these tests to reflect that behavior they do test.

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 might have spoken too soon! the refactor seems large, and ill punt on it for now. Thanks so much for the heads up!

@thisisnotashwin thisisnotashwin force-pushed the ashwin/parse-dc-for-authmethod-and-binding-create branch from c1fe002 to dd40882 Compare February 17, 2022 21:07
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging February 17, 2022 21:07 Inactive
@vercel vercel bot temporarily deployed to Preview – consul February 17, 2022 21:07 Inactive
@thisisnotashwin thisisnotashwin merged commit 6e6cd92 into main Feb 17, 2022
@thisisnotashwin thisisnotashwin deleted the ashwin/parse-dc-for-authmethod-and-binding-create branch February 17, 2022 21:41
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/588266.

@hc-github-team-consul-core
Copy link
Collaborator

🍒✅ Cherry pick of commit 6e6cd92 onto release/1.11.x succeeded!

hc-github-team-consul-core pushed a commit that referenced this pull request Feb 17, 2022
* Parse datacenter from request
- Parse the value of the datacenter from the create/delete requests for AuthMethods and BindingRules so that they can be created in and deleted from the datacenters specified in the request.
@hc-github-team-consul-core
Copy link
Collaborator

🍒✅ Cherry pick of commit 6e6cd92 onto release/1.10.x succeeded!

hc-github-team-consul-core pushed a commit that referenced this pull request Feb 17, 2022
* Parse datacenter from request
- Parse the value of the datacenter from the create/delete requests for AuthMethods and BindingRules so that they can be created in and deleted from the datacenters specified in the request.
@hc-github-team-consul-core
Copy link
Collaborator

🍒✅ Cherry pick of commit 6e6cd92 onto release/1.9.x succeeded!

hc-github-team-consul-core pushed a commit that referenced this pull request Feb 17, 2022
* Parse datacenter from request
- Parse the value of the datacenter from the create/delete requests for AuthMethods and BindingRules so that they can be created in and deleted from the datacenters specified in the request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Feature does not function as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants