Skip to content

Commit

Permalink
[8.8] [ResponseOps] Throwing a mustache error when validating action …
Browse files Browse the repository at this point in the history
…message for warnings (#158668) (#158776)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[ResponseOps] Throwing a mustache error when validating action
message for warnings
(#158668)](#158668)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Alexi
Doak","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-05-31T20:26:24Z","message":"[ResponseOps]
Throwing a mustache error when validating action message for warnings
(#158668)\n\nResolves
https://github.com/elastic/kibana/issues/158666\r\n\r\n##
Summary\r\n\r\nAdds a try/catch around `mustache.parse` to catch and
ignore any errors\r\nwhen validating the action message for
warnings.\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\r\n### To
verify\r\n\r\n- Create a rule and add a slack connector, and open dev
tools console\r\n- In the action message type `{{` - verify that an
error is not thrown\r\nand that you can add the second open curly
brace","sha":"15b31c62ba8d4a115c359d9bb723147866bbd34c","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:ResponseOps","v8.9.0","v8.8.1"],"number":158668,"url":"https://github.com/elastic/kibana/pull/158668","mergeCommit":{"message":"[ResponseOps]
Throwing a mustache error when validating action message for warnings
(#158668)\n\nResolves
https://github.com/elastic/kibana/issues/158666\r\n\r\n##
Summary\r\n\r\nAdds a try/catch around `mustache.parse` to catch and
ignore any errors\r\nwhen validating the action message for
warnings.\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\r\n### To
verify\r\n\r\n- Create a rule and add a slack connector, and open dev
tools console\r\n- In the action message type `{{` - verify that an
error is not thrown\r\nand that you can add the second open curly
brace","sha":"15b31c62ba8d4a115c359d9bb723147866bbd34c"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/158668","number":158668,"mergeCommit":{"message":"[ResponseOps]
Throwing a mustache error when validating action message for warnings
(#158668)\n\nResolves
https://github.com/elastic/kibana/issues/158666\r\n\r\n##
Summary\r\n\r\nAdds a try/catch around `mustache.parse` to catch and
ignore any errors\r\nwhen validating the action message for
warnings.\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\r\n### To
verify\r\n\r\n- Create a rule and add a slack connector, and open dev
tools console\r\n- In the action message type `{{` - verify that an
error is not thrown\r\nand that you can add the second open curly
brace","sha":"15b31c62ba8d4a115c359d9bb723147866bbd34c"}},{"branch":"8.8","label":"v8.8.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Alexi Doak <[email protected]>
  • Loading branch information
kibanamachine and doakalexi authored May 31, 2023
1 parent 564ff93 commit 06ee73f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ describe('validateParamsForWarnings', () => {
test('does not returns warnings when publicUrl is not set and the value is not a string', () => {
expect(validateParamsForWarnings(10, undefined, actionVariables)).toBeFalsy();
});

test('does not throw an error when passing in invalid mustache', () => {
expect(() => validateParamsForWarnings('{{', undefined, actionVariables)).not.toThrowError();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ export function validateParamsForWarnings(
return acc;
}, new Array<string>());

const variables = new Set(
(Mustache.parse(value) as Array<[string, string]>)
.filter(([type]) => type === 'name')
.map(([, v]) => v)
);
const hasUrlFields = some(publicUrlFields, (publicUrlField) => variables.has(publicUrlField));
if (hasUrlFields) {
return publicUrlWarning;
try {
const variables = new Set(
(Mustache.parse(value) as Array<[string, string]>)
.filter(([type]) => type === 'name')
.map(([, v]) => v)
);
const hasUrlFields = some(publicUrlFields, (publicUrlField) => variables.has(publicUrlField));
if (hasUrlFields) {
return publicUrlWarning;
}
} catch (e) {
/*
* do nothing, we don't care if the mustache is invalid
*/
}
}
return null;
Expand Down

0 comments on commit 06ee73f

Please sign in to comment.