From 3095457e3be1bae23da19c8fd194bffb480d77b0 Mon Sep 17 00:00:00 2001 From: Dino Chiesa Date: Wed, 15 May 2024 18:12:23 -0700 Subject: [PATCH] fix: PO035 allows both of Sync{IntervalInSeconds, MessageCount} --- lib/package/plugins/PO035-quota-hygiene.js | 30 ++++++++++--------- .../fail/Asynch-neither-child-element.xml | 10 +++++++ .../resources/PO035/policies/fail/messages.js | 4 +-- .../Asynch-both-elements.xml} | 2 +- 4 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 test/fixtures/resources/PO035/policies/fail/Asynch-neither-child-element.xml rename test/fixtures/resources/PO035/policies/{fail/Asynch-too-many-elements.xml => pass/Asynch-both-elements.xml} (90%) diff --git a/lib/package/plugins/PO035-quota-hygiene.js b/lib/package/plugins/PO035-quota-hygiene.js index 49a9ff1..15960b7 100644 --- a/lib/package/plugins/PO035-quota-hygiene.js +++ b/lib/package/plugins/PO035-quota-hygiene.js @@ -290,7 +290,7 @@ const onPolicy = function (quotaPolicy, cb) { } } - // 7. For AsynchronousConfiguration, only one child + // 7. For AsynchronousConfiguration, check children const asyncElement = xpath.select1( `AsynchronousConfiguration`, policyRoot @@ -305,28 +305,30 @@ const onPolicy = function (quotaPolicy, cb) { .join(" or "); const children = xpath.select(`*[${condition}]`, asyncElement); - if (children.length != 1) { + if (children.length == 0) { addIssue( `element <${ asyncElement.tagName - }> must have exactly one of {${validChildElements.join( + }> must have at least one of {${validChildElements.join( ", " )}} as a child.`, asyncElement.lineNumber, asyncElement.columnNumber ); - } - const child = children[0]; - const textValue = xpath.select1("text()", child); - debug(`asynch textValue (${textValue})...`); + } else { + children.forEach((child) => { + const textValue = xpath.select1("text()", child); + debug(`asynch textValue (${textValue})...`); - const intValue = textValue && parseInt(textValue, 10); - if (!textValue || !intValue || intValue <= 0) { - addIssue( - `element <${child.tagName}> must have a text value representing an integer.`, - child.lineNumber, - child.columnNumber - ); + const intValue = textValue && parseInt(textValue, 10); + if (!textValue || !intValue || intValue <= 0) { + addIssue( + `element <${child.tagName}> must have a text value representing an integer.`, + child.lineNumber, + child.columnNumber + ); + } + }); } } diff --git a/test/fixtures/resources/PO035/policies/fail/Asynch-neither-child-element.xml b/test/fixtures/resources/PO035/policies/fail/Asynch-neither-child-element.xml new file mode 100644 index 0000000..df64870 --- /dev/null +++ b/test/fixtures/resources/PO035/policies/fail/Asynch-neither-child-element.xml @@ -0,0 +1,10 @@ + + Quota-1 + + 2 + minute + true + verifyapikey.Quota-1.app.name + + + diff --git a/test/fixtures/resources/PO035/policies/fail/messages.js b/test/fixtures/resources/PO035/policies/fail/messages.js index 9600583..0821a27 100644 --- a/test/fixtures/resources/PO035/policies/fail/messages.js +++ b/test/fixtures/resources/PO035/policies/fail/messages.js @@ -19,8 +19,8 @@ module.exports = { "element must not have a text value.", "element must have a ref attribute." ], - "Asynch-too-many-elements.xml": [ - "element must have exactly one of {SyncIntervalInSeconds, SyncMessageCount} as a child." + "Asynch-neither-child-element.xml": [ + "element must have at least one of {SyncIntervalInSeconds, SyncMessageCount} as a child." ], "Asynch-non-integer-SyncIntervalInSeconds-element.xml": [ "element must have a text value representing an integer." diff --git a/test/fixtures/resources/PO035/policies/fail/Asynch-too-many-elements.xml b/test/fixtures/resources/PO035/policies/pass/Asynch-both-elements.xml similarity index 90% rename from test/fixtures/resources/PO035/policies/fail/Asynch-too-many-elements.xml rename to test/fixtures/resources/PO035/policies/pass/Asynch-both-elements.xml index 1dedcb6..a97b4ef 100644 --- a/test/fixtures/resources/PO035/policies/fail/Asynch-too-many-elements.xml +++ b/test/fixtures/resources/PO035/policies/pass/Asynch-both-elements.xml @@ -1,4 +1,4 @@ - + Quota-1 2