diff --git a/lib/package/plugins/PO034-am-hygiene.js b/lib/package/plugins/PO034-am-hygiene.js
index 4e683e6..f5a9876 100644
--- a/lib/package/plugins/PO034-am-hygiene.js
+++ b/lib/package/plugins/PO034-am-hygiene.js
@@ -19,7 +19,8 @@ const ruleId = require("../myUtil.js").getRuleId(),
xpath = require("xpath"),
util = require("util");
-const TEXT_NODE = 3; // this value is not exported by xmldom module!
+const TEXT_NODE = 3, // these values are not exported by xmldom module!
+ CDATA_SECTION_NODE = 4;
const plugin = {
ruleId,
@@ -86,6 +87,7 @@ const allowedChildren = {
IgnoreUnresolvedVariables: [],
Properties: [],
DisplayName: [],
+ Description: [],
IgnoreUnresolvedProperties: [],
"FormParams/FormParam": [],
"Headers/Header": [],
@@ -318,7 +320,11 @@ const onPolicy = function (policy, cb) {
innerChild.columnNumber
);
} else {
- if (innerChild.firstChild.nodeType != TEXT_NODE) {
+ if (
+ ![TEXT_NODE, CDATA_SECTION_NODE].includes(
+ child.firstChild.nodeType
+ )
+ ) {
foundIssue = true;
_addIssue(
policy,
@@ -343,8 +349,31 @@ const onPolicy = function (policy, cb) {
});
}
} else {
- // this is a node like Set/{Verb, Version, Path, Payload}
- // check that it has exactly one text value
+ // child is a node like {Verb, Version, Path, Payload}
+ // Check that it has exactly one text value.
+ // Unless it's a Payload which can take XML!
+
+ if (child.hasAttributes()) {
+ for (let i = 0; i < child.attributes.length; i++) {
+ const attr = child.attributes[i];
+ if (
+ child.tagName != "Payload" ||
+ ![
+ "contentType",
+ "variablePrefix",
+ "variableSuffix"
+ ].includes(attr.name)
+ ) {
+ foundIssue = true;
+ _addIssue(
+ policy,
+ `incorrect attribute (${attr.name}) on element <${child.tagName}>.`,
+ child.lineNumber,
+ child.columnNumber
+ );
+ }
+ }
+ }
if (!child.hasChildNodes()) {
foundIssue = true;
@@ -355,21 +384,31 @@ const onPolicy = function (policy, cb) {
child.columnNumber
);
} else if (child.childNodes.length > 1) {
- foundIssue = true;
- _addIssue(
- policy,
- `extraneous data in element <${child.tagName}>.`,
- child.lineNumber,
- child.columnNumber
- );
- } else if (child.firstChild.nodeType != TEXT_NODE) {
- foundIssue = true;
- _addIssue(
- policy,
- `confounded structure of element <${child.tagName}>.`,
- child.lineNumber,
- child.columnNumber
- );
+ if (child.tagName != "Payload") {
+ // payload can have XML
+ foundIssue = true;
+ _addIssue(
+ policy,
+ `extraneous data in element <${child.tagName}>.`,
+ child.lineNumber,
+ child.columnNumber
+ );
+ }
+ } else if (
+ ![TEXT_NODE, CDATA_SECTION_NODE].includes(
+ child.firstChild.nodeType
+ )
+ ) {
+ if (child.tagName != "Payload") {
+ // Set/Payload can have CDATA
+ foundIssue = true;
+ _addIssue(
+ policy,
+ `confounded structure of element <${child.tagName}>.`,
+ child.lineNumber,
+ child.columnNumber
+ );
+ }
} else if (!child.firstChild.nodeValue) {
foundIssue = true;
_addIssue(
@@ -464,7 +503,7 @@ const onPolicy = function (policy, cb) {
foundIssue = true;
_addIssue(
policy,
- `there should be no text or child elements under element <${innerChild.tagName}>.`,
+ `there should be no text or child elements under element <${child.tagName}>/<${innerChild.tagName}>.`,
innerChild.lineNumber,
innerChild.columnNumber
);
@@ -478,7 +517,7 @@ const onPolicy = function (policy, cb) {
foundIssue = true;
_addIssue(
policy,
- `there should be no text or child elements under element <${child.tagName}>.`,
+ `there should be no text or child elements under element <${tag}>/<${child.tagName}>.`,
child.lineNumber,
child.columnNumber
);
diff --git a/test/fixtures/resources/PO034/pass/AM-Payload-with-CDATA.xml b/test/fixtures/resources/PO034/pass/AM-Payload-with-CDATA.xml
new file mode 100644
index 0000000..cf97312
--- /dev/null
+++ b/test/fixtures/resources/PO034/pass/AM-Payload-with-CDATA.xml
@@ -0,0 +1,29 @@
+
+ This policy sets a payload
+
+
+
+ 200
+ OK
+
+
+ false
+
+
+
+ flowResponse.ready
+ true
+
+
+
diff --git a/test/fixtures/resources/PO034/pass/AssignMessage-GoogleAuth302-Response.xml b/test/fixtures/resources/PO034/pass/AssignMessage-GoogleAuth302-Response.xml
new file mode 100644
index 0000000..2b00af4
--- /dev/null
+++ b/test/fixtures/resources/PO034/pass/AssignMessage-GoogleAuth302-Response.xml
@@ -0,0 +1,28 @@
+
+ AssignMessage-GoogleAuth302
+
+ false
+
+
+
+
+
+ 302
+ Found
+
+
diff --git a/test/fixtures/resources/PO034/pass/Set-Payload-to-XML.xml b/test/fixtures/resources/PO034/pass/Set-Payload-to-XML.xml
new file mode 100644
index 0000000..a88ce40
--- /dev/null
+++ b/test/fixtures/resources/PO034/pass/Set-Payload-to-XML.xml
@@ -0,0 +1,17 @@
+
+ false
+
+
+
+
+ something
+ 9283987494
+
+
+ something-else
+ 12345
+
+
+
+
+
diff --git a/test/specs/PO034-am-hygiene-test.js b/test/specs/PO034-am-hygiene-test.js
index 08c44ba..8c26b38 100644
--- a/test/specs/PO034-am-hygiene-test.js
+++ b/test/specs/PO034-am-hygiene-test.js
@@ -46,8 +46,9 @@ describe(`${testID} - policy passes hygiene evaluation`, function () {
assert.notEqual(policyType, undefined, `${policyType} should be defined`);
plugin.onPolicy(policy, (e, foundIssues) => {
assert.equal(e, undefined, "should be undefined");
- assert.equal(foundIssues, false, "should be no issues");
const messages = policy.getReport().messages;
+ debug(util.format(messages));
+ assert.equal(foundIssues, false, "should be no issues");
assert.ok(messages, "messages should exist");
assert.equal(messages.length, 0, "unexpected number of messages");
});