Skip to content

Commit

Permalink
Merge pull request #445 from DinoChiesa/po035-relax
Browse files Browse the repository at this point in the history
fix: PO035 allows both of Sync{IntervalInSeconds, MessageCount}
  • Loading branch information
ssvaidyanathan authored May 16, 2024
2 parents 2fd52e9 + 3095457 commit 30f839a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
30 changes: 16 additions & 14 deletions lib/package/plugins/PO035-quota-hygiene.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Quota name="Asynch-neither-child-element">
<DisplayName>Quota-1</DisplayName>
<Allow countRef="my-count"/>
<Interval>2</Interval>
<TimeUnit>minute</TimeUnit>
<Synchronous>true</Synchronous>
<Identifier>verifyapikey.Quota-1.app.name</Identifier>
<AsynchronousConfiguration>
</AsynchronousConfiguration>
</Quota>
4 changes: 2 additions & 2 deletions test/fixtures/resources/PO035/policies/fail/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = {
"element <MessageWeight> must not have a text value.",
"element <MessageWeight> must have a ref attribute."
],
"Asynch-too-many-elements.xml": [
"element <AsynchronousConfiguration> must have exactly one of {SyncIntervalInSeconds, SyncMessageCount} as a child."
"Asynch-neither-child-element.xml": [
"element <AsynchronousConfiguration> must have at least one of {SyncIntervalInSeconds, SyncMessageCount} as a child."
],
"Asynch-non-integer-SyncIntervalInSeconds-element.xml": [
"element <SyncIntervalInSeconds> must have a text value representing an integer."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Quota name="Asynch-too-many-elements">
<Quota name="Asynch-both-elements">
<DisplayName>Quota-1</DisplayName>
<Allow countRef="my-count"/>
<Interval>2</Interval>
Expand Down

0 comments on commit 30f839a

Please sign in to comment.