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

ui: Default allow notices test #11240

Merged

Conversation

kaxcode
Copy link
Contributor

@kaxcode kaxcode commented Oct 6, 2021

Small PR to have a test for Default Allow notices.

@kaxcode kaxcode added theme/ui Anything related to the UI pr/no-changelog PR does not need a corresponding .changelog entry labels Oct 6, 2021
@kaxcode kaxcode requested a review from johncowen October 6, 2021 21:13
@kaxcode
Copy link
Contributor Author

kaxcode commented Oct 6, 2021

@johncowen I made this into a separate PR because the convo was getting too long for PR #11216

@@ -4,4 +4,4 @@
"*":
headers:
response:
X-Consul-Default-Acl-Policy: ${fake.helpers.randomize(['allow', 'deny'])}
x-consul-default-acl-policy: ${env('CONSUL_ACL_POLICY', fake.helpers.randomize(['allow', 'deny']))}
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 think the serializer is lowercasing this or something. In the end it's what made dev and the tests worked.

Copy link
Contributor

Choose a reason for hiding this comment

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

The mocks should mock the real backend exactly (as much as we possibly can). So this should be reverted, and then we should look into why the tests fail (if thats what happens).

Off the top of my head I know that within the code we lowercase all header keynames to cope with the behaviour of different browsers (apparently some browsers/XHRs impl. lowercase the headers, although a lot of time has passed since this was done so maybe thats no longer the case 🤷 )

If something here is breaking when its not lowercased, then I would assume it would also break when using a real Consul backend.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change does not break the UI when it's running against Consul binary. As I stated in #11216 I've spent more than enough time getting this test to work. I will not be reverting this change or doing any further research on why the header needs to be lowercased.

If you don't want this mock-api change to go through, I'll close the PR and this test can be added at a later time. Please let me know. @johncowen

Intention:
Allowed: false
---
And the default ACL policy is "allow"
Copy link
Contributor Author

@kaxcode kaxcode Oct 6, 2021

Choose a reason for hiding this comment

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

The set solution for changing cookies works but the action has to be done before visiting page.

Copy link
Contributor

@johncowen johncowen Oct 7, 2021

Choose a reason for hiding this comment

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

Yup, thats expected you need to set up your tests case before testing.

Arrange. Act. Assert.

This whole thing (setting up the default ACL policy) was about Arranging and so needs to happen before Acting (visiting the page) and Asserting.

Related: The catalog/datacenters HTTP API call where we grab the header is pretty much the first HTTP call the app makes, so you absolutely need to Arrange the mock before you visit anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@johncowen there's no need for you to explain how to set up tests. One, I didn't ask you. Two, I clearly see the mistake I made. I'm the one who pointed out what I did wrong. Please don't assume I don't know things just because I made a mistake.

@@ -38,6 +38,9 @@ export default function(scenario, create, set, win = window, doc = document) {
.given(['ACLs are disabled'], function() {
doc.cookie = `CONSUL_ACLS_ENABLE=0`;
})
.given(['the default ACL policy is "$policy"'], function(policy) {
set('CONSUL_ACL_POLICY', policy);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned, this solution works but it has to be in a specific place. Glad you tried it out because I got to take another look.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, glad it works. See my comment above re: Arrange. Act. Assert.

Copy link
Contributor

@johncowen johncowen left a comment

Choose a reason for hiding this comment

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

I think this is all super good. The only thing we definitely need to get to the bottom of is why the header in the mocks here needs to be lowercased. We need to make sure things work when its normal header cased (whatever that one is called snake/camel/capital/sentence/kebab/blah - basically not lower).

@@ -4,4 +4,4 @@
"*":
headers:
response:
X-Consul-Default-Acl-Policy: ${fake.helpers.randomize(['allow', 'deny'])}
x-consul-default-acl-policy: ${env('CONSUL_ACL_POLICY', fake.helpers.randomize(['allow', 'deny']))}
Copy link
Contributor

Choose a reason for hiding this comment

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

The mocks should mock the real backend exactly (as much as we possibly can). So this should be reverted, and then we should look into why the tests fail (if thats what happens).

Off the top of my head I know that within the code we lowercase all header keynames to cope with the behaviour of different browsers (apparently some browsers/XHRs impl. lowercase the headers, although a lot of time has passed since this was done so maybe thats no longer the case 🤷 )

If something here is breaking when its not lowercased, then I would assume it would also break when using a real Consul backend.

Intention:
Allowed: false
---
And the default ACL policy is "allow"
Copy link
Contributor

@johncowen johncowen Oct 7, 2021

Choose a reason for hiding this comment

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

Yup, thats expected you need to set up your tests case before testing.

Arrange. Act. Assert.

This whole thing (setting up the default ACL policy) was about Arranging and so needs to happen before Acting (visiting the page) and Asserting.

Related: The catalog/datacenters HTTP API call where we grab the header is pretty much the first HTTP call the app makes, so you absolutely need to Arrange the mock before you visit anything.

service: web
---
Then the url should be /datacenter/services/web/topology
And I see the tabs.topologyTab.defaultAllowNotice object
Scenario: WildcardIntetions and FilteredByACLs are set to true
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Scenario: WildcardIntetions and FilteredByACLs are set to true
Scenario: WildcardIntentions and FilteredByACLs are set to true

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, no biggie this, but this is no longer the scenario right? These things were never set to true in Consul itself, only in our mocks? So might want to change this sentence. As I said no biggie, its almost just a comment more than anything, but its sometimes useful for folks understanding what we are testing here.

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'll make this change in #11216

@@ -38,6 +38,9 @@ export default function(scenario, create, set, win = window, doc = document) {
.given(['ACLs are disabled'], function() {
doc.cookie = `CONSUL_ACLS_ENABLE=0`;
})
.given(['the default ACL policy is "$policy"'], function(policy) {
set('CONSUL_ACL_POLICY', policy);
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, glad it works. See my comment above re: Arrange. Act. Assert.

@kaxcode
Copy link
Contributor Author

kaxcode commented Oct 7, 2021

@johncowen At this time, I'm not making any further changes or research to make this test pass. If you don't feel it can be merged because of the mock-data then I will close it.

Please let me know. I would like to unblock #11216.

@kaxcode kaxcode merged this pull request into ui/bugfix/topology-notices Oct 11, 2021
@kaxcode kaxcode deleted the ui/chore/default-allow-notices-test branch October 11, 2021 14:02
kaxcode added a commit that referenced this pull request Oct 11, 2021
kaxcode added a commit that referenced this pull request Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/no-changelog PR does not need a corresponding .changelog entry theme/ui Anything related to the UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants