-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
ui: Default allow notices test #11240
Conversation
@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']))} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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']))} |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scenario: WildcardIntetions and FilteredByACLs are set to true | |
Scenario: WildcardIntentions and FilteredByACLs are set to true |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
@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. |
b5a1097
to
3cb57a7
Compare
Small PR to have a test for Default Allow notices.