Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Staging to Main #723

Merged
merged 25 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6dee72c
Show correct counts
zacharykeeping Oct 18, 2023
7d5ed9f
Update text
zacharykeeping Oct 18, 2023
172513d
Show commas
zacharykeeping Oct 18, 2023
072bfe7
Sanitize strings before writing tab-delimited CSV
zacharykeeping Oct 19, 2023
fc0e772
Display Load Test errors
tombui99 Oct 19, 2023
2438d9a
Merge pull request #710 from SSWConsulting/bad-urls
tombui99 Oct 19, 2023
e37f335
Merge pull request #711 from SSWConsulting/sanitise-csv
tombui99 Oct 19, 2023
93ceb24
Merge pull request #712 from SSWConsulting/display-load-test-error
zacharykeeping Oct 19, 2023
52dd890
Update packages
zacharykeeping Oct 19, 2023
f50fc24
Upload all rules by default
zacharykeeping Oct 19, 2023
b4b0658
Merge pull request #714 from SSWConsulting/package-update-3
tombui99 Oct 19, 2023
6fb65df
Add error handling
zacharykeeping Oct 19, 2023
786c639
Merge pull request #717 from SSWConsulting/comparescans-error-handling
tombui99 Oct 20, 2023
54fef5d
Merge pull request #716 from SSWConsulting/upload-htmlhint-config
tombui99 Oct 20, 2023
3670812
Always show unscannable links
zacharykeeping Oct 20, 2023
a87758f
Use api in function
zacharykeeping Oct 20, 2023
64d8918
Get unscannable links from API
zacharykeeping Oct 20, 2023
6753da7
Remove const
zacharykeeping Oct 20, 2023
05368d7
Hide title if there is no alert email on the list
tombui99 Oct 20, 2023
6e79c39
Merge pull request #720 from SSWConsulting/fix-send-email-alert-modal
zacharykeeping Oct 20, 2023
622d8ea
Merge pull request #719 from SSWConsulting/unscannable-links-fixes
tombui99 Oct 20, 2023
899ae3e
Fixed false positive in spelling mistake custom rule
Oct 23, 2023
f0d74eb
Fix false positives
zacharykeeping Oct 23, 2023
9e31df4
Merge pull request #721 from SSWConsulting/fix-false-positive-spellin…
zacharykeeping Oct 23, 2023
d3eba41
Merge pull request #722 from SSWConsulting/phone-numbers-fix
tombui99 Oct 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions api/functions/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,3 @@ exports.BLOB = {
htmlhint: 'htmlhint',
codeAuditor: 'codeauditor',
};

exports.unscannableLinks = [
{url: "https://learn.microsoft.com/en-us/"},
{url: "https://support.google.com/"},
{url: "https://twitter.com/"},
{url: "https://marketplace.visualstudio.com/"},
{url: "https://www.nuget.org/"},
{url: "https://make.powerautomate.com"},
{url: "https://www.microsoft.com/"},
{url: "http://www.microsoft.com/"},
{url: "https://answers.microsoft.com/"},
{url: "https://admin.microsoft.com/"},
{url: "https://ngrx.io"},
{url: "https://twitter.com"},
{url: "https://marketplace"},
{url: "https://www.nuget.org/"},
{url: "http://nuget.org"},
{url: "https://t.co"},
{url: "https://support.google.com"},
{url: "https://playwright.dev"},
{url: "https://www.theurlist.com/xamarinstreamers"},
{url: "https://dev.botframework.com"},
{url: "https://www.ssw.com.au/rules/rules-to-better-research-and-development/"},
{url: "https://www.ato.gov.au/Business/Research-and-development-tax-incentive/"},
{url: "https://learn.microsoft.com/en-us/assessments/?mode=home/"}
]
8 changes: 4 additions & 4 deletions api/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const admin = require('firebase-admin');
const R = require('ramda');
const fetch = require('node-fetch');
const Queue = require('better-queue');
const { unscannableLinks } = require('./consts');
require('dotenv').config();

const {
Expand Down Expand Up @@ -231,6 +230,7 @@ app.post('/scanresult/:api/:buildId', async (req, res) => {
const buildId = req.params.buildId;
const runId = newGuid();
const buildDate = new Date();
const unscannableLinks = await getUnscannableLinks();

const uid = await getUserIdFromApiKey(apikey);
if (!uid) {
Expand Down Expand Up @@ -262,11 +262,11 @@ app.post('/scanresult/:api/:buildId', async (req, res) => {
url,
cloc,
totalBrokenLinks: badUrls.length,
uniqueBrokenLinks: R.uniqBy(R.prop('dst'), badUrls.filter((x) => !unscannableLinks.some(link => x.dst.includes(link.url)))).length,
pagesWithBrokenLink: R.uniqBy(R.prop('src'), badUrls.filter((x) => !unscannableLinks.some(link => x.dst.includes(link.url)))).length,
uniqueBrokenLinks: R.uniqBy(R.prop('dst'), badUrls.filter((x) => !unscannableLinks.some(link => x.dst.includes(link)))).length,
pagesWithBrokenLink: R.uniqBy(R.prop('src'), badUrls.filter((x) => !unscannableLinks.some(link => x.dst.includes(link)))).length,
totalUnique404: R.uniqBy(
R.prop('dst'),
badUrls.filter((x) => x.statuscode === '404' && !unscannableLinks.some(link => x.dst.includes(link.url)))
badUrls.filter((x) => x.statuscode === '404' && !unscannableLinks.some(link => x.dst.includes(link)))
).length,
htmlWarnings: htmlWarnings ? htmlWarnings : 0,
htmlErrors: htmlErrors ? htmlErrors : 0,
Expand Down
30 changes: 17 additions & 13 deletions api/functions/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const getExistingBrokenLinkCount = async (runId) => {

const existingCount = result.reduce((count, item) => {
if (item.runId === runId) {
if (!previousFailures.has(item.dst) && !unscannableLinks.find((i) => item.dst.startsWith(i))) {
const hasPrevious = result.find((i) => i.dst === item.dst && i.buildDate < item.buildDate);
if (!previousFailures.has(item.dst) && !unscannableLinks.some((i) => item.dst.includes(i))) {
const hasPrevious = result.some((i) => i.dst === item.dst && i.buildDate < item.buildDate);
previousFailures.set(item.dst, hasPrevious);

if (hasPrevious) {
Expand Down Expand Up @@ -279,7 +279,7 @@ exports.getAllScanSummaryFromUrl = (url, api) =>
for await (const item of iterator) {
if (item[0]) {
const existing = await getExistingBrokenLinkCount(item[0].runId);
item[0].totalUnique404Existing = existing;
item[0].totalUniqueBrokenLinksExisting = existing;
}

resolve(item);
Expand Down Expand Up @@ -314,17 +314,21 @@ exports.compareScans = (api, url) =>
for await (const item of entity) {
result.push(item);
}

const latestResult = result[0] || {};
const prevResult = result[1] || {};

let isErrorUp = {
isHtmlWarningsUp: result[0].htmlWarnings > result[1].htmlWarnings,
prevHtmlWarnings: result[1].htmlWarnings,
currHtmlWarnings: result[0].htmlWarnings,
isHtmlErrorsUp: result[0].htmlErrors > result[1].htmlErrors,
prevHtmlErrors: result[1].htmlErrors,
currHtmlErrors: result[0].htmlErrors,
isBrokenLinksUp: result[0].totalUnique404 > result[1].totalUnique404,
prevBrokenLinks: result[1].totalUnique404,
currBrokenLinks: result[0].totalUnique404,
latestRunId: result[0].runId
isHtmlWarningsUp: latestResult.htmlWarnings > prevResult.htmlWarnings,
prevHtmlWarnings: prevResult.htmlWarnings || 0,
currHtmlWarnings: latestResult.htmlWarnings || 0,
isHtmlErrorsUp: latestResult.htmlErrors > prevResult.htmlErrors,
prevHtmlErrors: prevResult.htmlErrors || 0,
currHtmlErrors: latestResult.htmlErrors || 0,
isBrokenLinksUp: latestResult.uniqueBrokenLinks > prevResult.uniqueBrokenLinks,
prevBrokenLinks: prevResult.uniqueBrokenLinks || 0,
currBrokenLinks: latestResult.uniqueBrokenLinks || 0,
latestRunId: latestResult.runId
}
resolve(isErrorUp)
});
45 changes: 25 additions & 20 deletions docker/customHtmlRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ exports.addCustomHtmlRule = () => {
scrumTerms.forEach((i) => {
var contentIndex = pageContent.indexOf(i);
var col = event.lastEvent.col;

if (contentIndex >= 0) {
reporter.warn(
"Incorrect Scrum term: '" + i + "'.",
event.line,
col,
self,
event.raw
);

// Make sure the character has space and is not part of a long single string
if (pageContent.indexOf(' ') >= 0) {
if (contentIndex >= 0) {
reporter.warn(
"Incorrect Scrum term: '" + i + "'.",
event.line,
col,
self,
event.raw
);
}
}
});
}
Expand Down Expand Up @@ -445,17 +448,19 @@ exports.addCustomHtmlRule = () => {
let pageContent = event.lastEvent.raw;
if (pageContent) {
spellings.forEach((i) => {
var contentIndex = pageContent.indexOf(i);
var contentIndex = pageContent.indexOf(i) >= 0;
var col = event.lastEvent.col;

if (contentIndex >= 0) {
reporter.warn(
"Incorrect spellings: '" + i + "'.",
event.line,
col,
self,
event.raw
);
// Make sure the character has space and is not part of a long single string
if (pageContent.indexOf(' ') >= 0) {
if (contentIndex) {
reporter.warn(
"Incorrect spellings: '" + i + "'.",
event.line,
col,
self,
event.raw
);
}
}
});
}
Expand All @@ -473,7 +478,7 @@ exports.addCustomHtmlRule = () => {
init: function (parser, reporter) {
const self = this;
parser.addListener("all", (event) => {
if (event.raw && event.lastEvent && findPhoneNumbersInText(event.raw, "US").length) {
if (event.raw && event.lastEvent && findPhoneNumbersInText(event.raw, "AU").length) {
const pageContent = event.lastEvent.raw;
if (pageContent && event.lastEvent.tagName) {
const tagName = event.lastEvent.tagName.toLowerCase();
Expand Down
9 changes: 5 additions & 4 deletions docker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const {
runLighthouseReport,
runArtilleryLoadTest
} = require("./utils");
const { htmlHintConfig } = require("./api");

const LIGHTHOUSEFOLDER = "./lhr.json";
const ARTILLERYFOLDER = "./artilleryOut.json";
Expand Down Expand Up @@ -315,7 +316,7 @@ const processAndUpload = async (
});
} catch (error) {
console.error(
`Error: Unabled to push data to dashboard service => ${error.message}`
`Error: Unable to push data to dashboard service => ${error.message}`
);
}
}
Expand All @@ -334,13 +335,13 @@ const processAndUpload = async (
// Upload selected HTMLHint Rules to the scan
if (args.htmlhint && args.token && runId) {
const result = await getHTMLHintRules(args.token, args.url);
const selectedRules = result?.selectedRules ?? Object.keys(htmlHintConfig).join(",");

if (result && result.selectedRules?.split(",").length > 0) {
const selectedRules = result.selectedRules;
if (selectedRules?.length > 0) {
const res = await addHTMLHintRulesForScan(args.token, args.url, runId, selectedRules)

if (res) {
console.log('Upload selected HTMLHint Rules successfully')
console.log('Uploaded selected HTMLHint Rules successfully');
} else {
throw new Error("Failed to add custom html rules for each scan");
}
Expand Down
38 changes: 14 additions & 24 deletions docker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"boxen": "^4.2.0",
"chalk": "^3.0.0",
"csv-parser": "^2.3.5",
"csv-parser": "^3.0.0",
"csv-writer": "^1.6.0",
"date-fns": "^2.30.0",
"eslint-plugin-promise": "^4.3.1",
Expand All @@ -20,10 +20,10 @@
"html5parser": "^1.2.1",
"htmlhint": "^0.11.0",
"js-beautify": "^1.14.9",
"libphonenumber-js": "^1.10.47",
"libphonenumber-js": "^1.10.48",
"minimatch": "^3.1.2",
"mocha": "^9.2.2",
"node-fetch": "^2.6.12",
"node-fetch": "^2.7.0",
"nodemailer": "^6.9.3",
"puppeteer": "^3.3.0",
"ramda": "^0.27.2",
Expand Down
13 changes: 12 additions & 1 deletion docker/sswlinkauditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,23 @@ func writeResultFile(allUrls map[string]LinkStatus) {

f.WriteString("Source" + "\t" + "Destination" + "\t" + "Status" + "\t" + "StatusCode" + "\t" + "Anchor" + "\n")
for _, v := range allUrls {
f.WriteString(v.srcUrl + "\t" + v.url + "\t" + v.status + "\t" + strconv.Itoa(v.statusCode) + "\t" + strings.ReplaceAll(v.anchor,"\"","") + "\n")
f.WriteString(sanitizeString(v.srcUrl) + "\t" + sanitizeString(v.url) + "\t" + sanitizeString(v.status) + "\t" + strconv.Itoa(v.statusCode) + "\t" + sanitizeString(v.anchor) + "\n")
}

f.Close()
}

func sanitizeString(s string) string {
replacer := strings.NewReplacer(
"\"", "",
"\t", " ",
"\r\n", "",
"\n", "",
);

return replacer.Replace(s);
}

func isLinkUnscannable(a string, unscannableLinks []string) bool {
for _, b := range unscannableLinks {
if strings.HasPrefix(strings.ToLower(a), strings.ToLower(b)) {
Expand Down
6 changes: 6 additions & 0 deletions docker/test/common-spelling-mistakes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ describe(`Rules: ${ruleId}`, () => {
expect(messages.length).to.be(9);
});

it("long string contains the character should not result in an error", () => {
const code = `<div>wgARCAAKABQDASIAAhEBAxEB/8QAGAAAAwEBAAAAAAAAAAAAAAAAAAIDBAX/xAAUAQE</div>`;
const messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(0);
});

["meta", "link", "script", "svg"].forEach((tag) => {
it(`incorrect terms in a <${tag}> tag should not result in an error`, () => {
const code = `<${tag}>a.k.a A.K.A AKA e-mail EMail can not web site user name task bar</${tag}>`;
Expand Down
6 changes: 6 additions & 0 deletions docker/test/grammar-scrum-terms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ describe(`Rules: ${ruldId}`, () => {
expect(messages.length).to.be(11);
});

it("long string contains the character should not result in an error", () => {
const code = `<div>blahblahsprintblahblah</div>`;
const messages = HTMLHint.verify(code, ruleOptions);
expect(messages.length).to.be(0);
});

it("Incorrect Scrum terms in <a> tag should not result in an error", () => {
const code =
"<a href='sprint'>scrum, sprint, product owner</a>";
Expand Down
Loading