Skip to content

Commit

Permalink
Merge pull request #803 from SSWConsulting/ignore-fix
Browse files Browse the repository at this point in the history
Update ignored URL handling
  • Loading branch information
tombui99 committed Nov 29, 2023
2 parents 8cba888 + 0181a14 commit 643db21
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion api/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ app.post('/scanresult/:api/:buildId', async (req, res) => {
...lhrSummary,
...atrSummary,
totalScanned,
whiteListed,
totalWhitelisted: whiteListed.length,
scanDuration,
url,
cloc,
Expand Down
12 changes: 5 additions & 7 deletions docker/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,23 +436,21 @@ exports.processBrokenLinks = (
whitelistedUrls
.filter(
(ig) =>
ig.ignoreOn === ignoreOn &&
(ig.ignoreOn === "all" || ig.ignoreOn === ignoreOn) &&
(+ig.ignoreDuration === -1 ||
diffInDaysToNow(new Date(ig.effectiveFrom)) <
+ig.ignoreDuration)
)
.map((ig) => ig.urlToIgnore)
.filter((ignorePattern) => minimatch(url, ignorePattern)).length > 0
.filter((ignorePattern) =>
minimatch(url.src, ignorePattern) || minimatch(url.dst, ignorePattern)
).length > 0
);
};

// return the URL only
const all = badUrls
.filter(
(url) =>
isInIgnoredList(url.dst, "all", whitelistedUrls) ||
isInIgnoredList(url.dst, startUrl, whitelistedUrls)
)
.filter((url) => isInIgnoredList(url, startUrl))
.map((x) => x.dst);
return [...new Set(all)];
};
Expand Down
5 changes: 3 additions & 2 deletions ui/src/components/linkauditorcomponents/DetailsByDest.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const dispatch = createEventDispatcher();
export let builds = [];
export let scanUrl;
const ignore = url => dispatch("ignore", url);
let destinations;
Expand All @@ -25,7 +26,7 @@
destinationsKeys = Object.keys(destinations);
ignoredChecks = builds.reduce((acc, val) => {
acc[val.dst] = isInIgnored(val.dst, $ignoredUrls$);
acc[val.dst] = isInIgnored(val, scanUrl, $ignoredUrls$);
return acc;
}, {});
}
Expand All @@ -47,7 +48,7 @@
const deleteIgnore = async (url) => {
deleteUrl = url;
loadingChecks[url] = true;
const rules = getMatchingIgnoredRules(url, $ignoredUrls$);
const rules = getMatchingIgnoredRules(url, scanUrl, $ignoredUrls$);
try {
for await (const rule of rules) {
await deleteIgnoreUrl(rule, $userSession$);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
const dispatch = createEventDispatcher();
const ignore = url => dispatch("ignore", url);
export let scanUrl;
let reasons;
let reasonsKeys = [];
let hiddenRows = {};
Expand All @@ -25,7 +27,7 @@
reasonsKeys = Object.keys(reasons);
ignoredChecks = builds.reduce((acc, val) => {
acc[val.dst] = isInIgnored(val.dst, $ignoredUrls$);
acc[val.dst] = isInIgnored(val, scanUrl, $ignoredUrls$);
return acc;
}, {});
}
Expand All @@ -46,7 +48,7 @@
const deleteIgnore = async (url) => {
deleteUrl = url;
loadingChecks[url] = true;
const rules = getMatchingIgnoredRules(url, $ignoredUrls$);
const rules = getMatchingIgnoredRules(url, scanUrl, $ignoredUrls$);
try {
for await (const rule of rules) {
await deleteIgnoreUrl(rule, $userSession$);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
const dispatch = createEventDispatcher();
const ignore = url => dispatch("ignore", url);
export let scanUrl;
let sources;
let sourcesKeys = [];
let ignoredChecks = {};
Expand All @@ -23,7 +25,7 @@
sources = groupBy(props(["src"]))(builds);
sourcesKeys = Object.keys(sources);
ignoredChecks = builds.reduce((acc, val) => {
acc[val.dst] = isInIgnored(val.dst, $ignoredUrls$);
acc[val.dst] = isInIgnored(val, scanUrl, $ignoredUrls$);
return acc;
}, {});
}
Expand All @@ -45,7 +47,7 @@
const deleteIgnore = async (url) => {
deleteUrl = url;
loadingChecks[url] = true;
const rules = getMatchingIgnoredRules(url, $ignoredUrls$);
const rules = getMatchingIgnoredRules(url, scanUrl, $ignoredUrls$);
try {
for await (const rule of rules) {
await deleteIgnoreUrl(rule, $userSession$);
Expand Down
7 changes: 4 additions & 3 deletions ui/src/components/linkauditorcomponents/DetailsTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
export let builds = [];
export let currentRoute;
export let unscannableLinks;
export let scanUrl;
let foundUnscannableLinks = [];
foundUnscannableLinks = builds.filter(build => unscannableLinks.some(link => build.dst.includes(link)));
Expand Down Expand Up @@ -167,10 +168,10 @@

{#if builds.length}
{#if displayMode === 0}
<DetailsBySource {builds} on:ignore />
<DetailsBySource {builds} {scanUrl} on:ignore />
{:else if displayMode === 1}
<DetailsByDest {builds} on:ignore />
<DetailsByDest {builds} {scanUrl} on:ignore />
{:else}
<DetailsByReason {builds} on:ignore />
<DetailsByReason {builds} {scanUrl} on:ignore />
{/if}
{/if}
2 changes: 1 addition & 1 deletion ui/src/components/misccomponents/UpdateIgnoreUrl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
class="hidden"
id="radio2"
bind:group={ignoreOn}
value={url}
value={scanUrl}
disabled={editing}
/>
<label for="radio2" class:disabled={editing} class="flex items-center">
Expand Down
3 changes: 2 additions & 1 deletion ui/src/containers/LinkReport.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
on:ignore={url => showIgnore(data.buildDetails.summary.url, url, $userSession$)}
builds={data.buildDetails ? data.buildDetails.brokenLinks : []}
{currentRoute}
unscannableLinks={[]}
unscannableLinks={[]}
scanUrl={data.buildDetails.summary.url}
/>
</BuildDetailsSlot>
{:catch error}
Expand Down
8 changes: 4 additions & 4 deletions ui/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ export const getLoadThresholdResult = (value) => ({
errors: value.errors,
});

export const isInIgnored = (url, list) => {
return getMatchingIgnoredRules(url, list).length > 0;
export const isInIgnored = (url, scanUrl, list) => {
return getMatchingIgnoredRules(url, scanUrl, list).length > 0;
};

export const getMatchingIgnoredRules = (url, list) => {
export const getMatchingIgnoredRules = (url, scanUrl, list) => {
const date = new Date();
return list.filter((item) => {
const pattern = item.urlToIgnore;
if (globMatchUrl(pattern, url)) {
if ((item.ignoreOn === "all" || item.ignoreOn === scanUrl) && (globMatchUrl(pattern, url.src) || globMatchUrl(pattern, url.dst))) {
const effectiveFrom = new Date(item.effectiveFrom);
const timeElapsed = (date - effectiveFrom) / 86400000;
return (item.ignoreDuration > 0 && timeElapsed < item.ignoreDuration) || item.ignoreDuration === -1;
Expand Down

0 comments on commit 643db21

Please sign in to comment.