mirror of
https://github.com/status-im/consul.git
synced 2025-02-23 02:48:19 +00:00
ui: ACL Policies. Catch all server errors (#5836)
Always show any server errors under Rules, not just invalid HCL
This commit is contained in:
parent
5f7494137a
commit
75e221d256
@ -4,6 +4,7 @@ import { inject as service } from '@ember/service';
|
|||||||
import updateArrayObject from 'consul-ui/utils/update-array-object';
|
import updateArrayObject from 'consul-ui/utils/update-array-object';
|
||||||
|
|
||||||
const ERROR_PARSE_RULES = 'Failed to parse ACL rules';
|
const ERROR_PARSE_RULES = 'Failed to parse ACL rules';
|
||||||
|
const ERROR_INVALID_POLICY = 'Invalid service policy';
|
||||||
const ERROR_NAME_EXISTS = 'Invalid Policy: A Policy with Name';
|
const ERROR_NAME_EXISTS = 'Invalid Policy: A Policy with Name';
|
||||||
|
|
||||||
export default ChildSelectorComponent.extend({
|
export default ChildSelectorComponent.extend({
|
||||||
@ -38,10 +39,11 @@ export default ChildSelectorComponent.extend({
|
|||||||
const err = e.error;
|
const err = e.error;
|
||||||
if (typeof err.errors !== 'undefined') {
|
if (typeof err.errors !== 'undefined') {
|
||||||
const error = err.errors[0];
|
const error = err.errors[0];
|
||||||
let prop;
|
let prop = 'Rules';
|
||||||
let message = error.detail;
|
let message = error.detail;
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case message.indexOf(ERROR_PARSE_RULES) === 0:
|
case message.indexOf(ERROR_PARSE_RULES) === 0:
|
||||||
|
case message.indexOf(ERROR_INVALID_POLICY) === 0:
|
||||||
prop = 'Rules';
|
prop = 'Rules';
|
||||||
message = error.detail;
|
message = error.detail;
|
||||||
break;
|
break;
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<strong>{{item.error.Name.validation}}</strong>
|
<strong>{{item.error.Name.validation}}</strong>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</label>
|
</label>
|
||||||
<label class="type-text">
|
<label class="type-text" data-test-rules>
|
||||||
<span>Rules <a href="{{env 'CONSUL_DOCUMENTATION_URL'}}/guides/acl.html#rule-specification" rel="help noopener noreferrer" target="_blank">(HCL Format)</a></span>
|
<span>Rules <a href="{{env 'CONSUL_DOCUMENTATION_URL'}}/guides/acl.html#rule-specification" rel="help noopener noreferrer" target="_blank">(HCL Format)</a></span>
|
||||||
{{#if (eq item.template '') }}
|
{{#if (eq item.template '') }}
|
||||||
{{code-editor syntax='hcl' class=(if item.error.Rules 'error') name=(concat name '[Rules]') value=item.Rules onkeyup=(action 'change' (concat name '[Rules]'))}}
|
{{code-editor syntax='hcl' class=(if item.error.Rules 'error') name=(concat name '[Rules]') value=item.Rules onkeyup=(action 'change' (concat name '[Rules]'))}}
|
||||||
|
@ -67,6 +67,33 @@ Feature: dc / acls / policies / as many / add new: Add new policy
|
|||||||
| token |
|
| token |
|
||||||
| role |
|
| role |
|
||||||
-------------
|
-------------
|
||||||
|
Scenario: Adding a new policy as a child of [Model] and getting an error
|
||||||
|
Given the url "/v1/acl/policy" responds with from yaml
|
||||||
|
---
|
||||||
|
status: 500
|
||||||
|
body: |
|
||||||
|
Invalid service policy: acl.ServicePolicy{Name:"service", Policy:"", Sentinel:acl.Sentinel{Code:"", EnforcementLevel:""}, Intentions:""}
|
||||||
|
---
|
||||||
|
Then I fill in the policies.form with yaml
|
||||||
|
---
|
||||||
|
Name: New-Policy
|
||||||
|
Description: New Policy Description
|
||||||
|
Rules: key {}
|
||||||
|
---
|
||||||
|
And I click submit on the policies.form
|
||||||
|
Then the last PUT request was made to "/v1/acl/policy?dc=datacenter" with the body from yaml
|
||||||
|
---
|
||||||
|
Name: New-Policy
|
||||||
|
Description: New Policy Description
|
||||||
|
Rules: key {}
|
||||||
|
---
|
||||||
|
And I see error on the policies.form.rules like 'Invalid service policy: acl.ServicePolicy{Name:"service", Policy:"", Sentinel:acl.Sentinel{Code:"", EnforcementLevel:""}, Intentions:""}'
|
||||||
|
Where:
|
||||||
|
-------------
|
||||||
|
| Model |
|
||||||
|
| token |
|
||||||
|
| role |
|
||||||
|
-------------
|
||||||
@ignore:
|
@ignore:
|
||||||
Scenario: Click the cancel form
|
Scenario: Click the cancel form
|
||||||
Then ok
|
Then ok
|
||||||
|
@ -48,7 +48,7 @@ const cancelable = createCancelable(clickable, is);
|
|||||||
|
|
||||||
const tokenList = tokenListFactory(clickable, attribute, collection, deletable);
|
const tokenList = tokenListFactory(clickable, attribute, collection, deletable);
|
||||||
|
|
||||||
const policyForm = policyFormFactory(submitable, cancelable, radiogroup);
|
const policyForm = policyFormFactory(submitable, cancelable, radiogroup, text);
|
||||||
const policySelector = policySelectorFactory(clickable, deletable, collection, alias, policyForm);
|
const policySelector = policySelectorFactory(clickable, deletable, collection, alias, policyForm);
|
||||||
|
|
||||||
const roleForm = roleFormFactory(submitable, cancelable, policySelector);
|
const roleForm = roleFormFactory(submitable, cancelable, policySelector);
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
export default (submitable, cancelable, radiogroup) => () => {
|
export default (submitable, cancelable, radiogroup, text) => (
|
||||||
|
scope = '[data-test-policy-form]'
|
||||||
|
) => {
|
||||||
return {
|
return {
|
||||||
// this should probably be settable
|
// this should probably be settable
|
||||||
resetScope: true,
|
resetScope: true,
|
||||||
scope: '[data-test-policy-form]',
|
scope: scope,
|
||||||
prefix: 'policy',
|
prefix: 'policy',
|
||||||
...submitable(),
|
...submitable(),
|
||||||
...cancelable(),
|
...cancelable(),
|
||||||
...radiogroup('template', ['', 'service-identity'], 'policy'),
|
...radiogroup('template', ['', 'service-identity'], 'policy'),
|
||||||
|
rules: {
|
||||||
|
error: text('[data-test-rules] strong'),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,7 @@ export default (clickable, deletable, collection, alias, policyForm) => (
|
|||||||
return {
|
return {
|
||||||
scope: scope,
|
scope: scope,
|
||||||
create: clickable(createSelector),
|
create: clickable(createSelector),
|
||||||
form: policyForm(),
|
form: policyForm('#new-policy-toggle + div'),
|
||||||
policies: alias('selectedOptions'),
|
policies: alias('selectedOptions'),
|
||||||
selectedOptions: collection(
|
selectedOptions: collection(
|
||||||
'[data-test-policies] [data-test-tabular-row]',
|
'[data-test-policies] [data-test-tabular-row]',
|
||||||
|
@ -96,18 +96,28 @@ export default function(scenario, assert, find, currentPage) {
|
|||||||
.then(['I see $property'], function(property) {
|
.then(['I see $property'], function(property) {
|
||||||
assert.ok(currentPage()[property], `Expected to see ${property}`);
|
assert.ok(currentPage()[property], `Expected to see ${property}`);
|
||||||
})
|
})
|
||||||
.then(['I see $property on the $component like "$value"'], function(
|
.then(
|
||||||
property,
|
[
|
||||||
component,
|
'I see $property on the $component like "$value"',
|
||||||
value
|
"I see $property on the $component like '$value'",
|
||||||
) {
|
],
|
||||||
const target = currentPage()[component][property];
|
function(property, component, value) {
|
||||||
assert.equal(
|
let target;
|
||||||
target,
|
try {
|
||||||
value,
|
if (typeof component === 'string') {
|
||||||
`Expected to see ${property} on ${component} as ${value}, was ${target}`
|
property = `${component}.${property}`;
|
||||||
);
|
}
|
||||||
})
|
target = find(property);
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
assert.equal(
|
||||||
|
target,
|
||||||
|
value,
|
||||||
|
`Expected to see ${property} on ${component} as ${value}, was ${target}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
)
|
||||||
.then(['I see $property like "$value"'], function(property, value) {
|
.then(['I see $property like "$value"'], function(property, value) {
|
||||||
const target = currentPage()[property];
|
const target = currentPage()[property];
|
||||||
assert.equal(target, value, `Expected to see ${property} as ${value}, was ${target}`);
|
assert.equal(target, value, `Expected to see ${property} as ${value}, was ${target}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user