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 #810

Merged
merged 9 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions api/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,5 +362,39 @@ app.post('/scanresult/:api/:buildId', async (req, res) => {
res.json(runId);
});

app.get('/testing/statichtmlpage', async (req, res) => {
try {
// You can customize the HTML template here if needed
const htmlTemplate = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Sites</title>
<link rel="stylesheet" href="/styles/main.css">
</head>
<body>
<h1>Testing Page!!!</h1>
<h1>Links to test scraping function:</h1>
<ul>
<li><a href="https://htmlhint.com">HTML Hint</a></li>
<li><a href="https://github.com">GitHub</a></li>
<li><a href="https://ssw.com.au/">SSW</a></li>
</ul>
<h1>Sample misspelling terms to test HTML scanning function: </h1>
<p>scrum, sprint, product owner, scrum master, product backlog, sprint review, sprint planning, sprint retrospective, sprint retro, specification review, spec review</p>
<p>a.k.a A.K.A AKA e-mail EMail can not web site user name task bar</p>
</body>
</html>
`;

res.send(htmlTemplate);
} catch (error) {
console.error(error);
res.status(500).send('Internal Server Error');
}
});

exports.api = functions.runWith({ timeoutSeconds: 540 }).region('asia-east2').https.onRequest(app);
exports.api2 = functions.runWith({ timeoutSeconds: 540 }).region('asia-northeast1').https.onRequest(app);
2 changes: 1 addition & 1 deletion docker/customHtmlRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const findPhoneNumbersInText = require('libphonenumber-js').findPhoneNumbersInTe
const { customHtmlHintRules } = require("./rules");

exports.addCustomHtmlRule = async (apiToken, url) => {
const customRuleOptions = await getCustomHtmlRuleOptions(apiToken, url);
const customRuleOptions = apiToken && url ? await getCustomHtmlRuleOptions(apiToken, url) : [];

HTMLHint.addRule({
id: "code-block-missing-language",
Expand Down
2 changes: 1 addition & 1 deletion docker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "mocha --recursive --require test/hooks.js"
},
"author": "",
"license": "ISC",
Expand Down
6 changes: 0 additions & 6 deletions docker/test/anchor-names-must-be-valid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = 'anchor-names-must-be-valid'

const ruleOptions = {}

const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it('Anchor name starts with letter and contains no space should not result in an error', () => {
const code = '<a name="ThisisAnchor">Anchor</a>'
Expand Down
6 changes: 0 additions & 6 deletions docker/test/code-block-missing-language.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = 'code-block-missing-language'

const ruleOptions = {}

const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it('Code block with data language specifier should not result in an error', () => {
const code = '<pre data-language="javascript">Some Code</pre>'
Expand Down
6 changes: 0 additions & 6 deletions docker/test/common-spelling-mistakes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruleId = "common-spelling-mistakes";

const ruleOptions = {};

const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruleId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruleId}`, () => {
it("terms used correctly should not result in an error", () => {
const code = "<p>aka email cannot website username taskbar</p>";
Expand Down
12 changes: 3 additions & 9 deletions docker/test/detect-absolute-references-correctly.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
const expect = require("expect.js");
const HTMLHint = require("htmlhint").default;

const ruldId = "detect-absolute-references-url-path-correctly";
const ruleId = "detect-absolute-references-url-path-correctly";

const ruleOptions = {};

const { addCustomHtmlRule } = require("../customHtmlRules");
ruleOptions[ruleId] = true;

ruleOptions[ruldId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
describe(`Rules: ${ruleId}`, () => {
it("Bad example should result in an error", () => {
const code = '<a href="https://ssw.com.au/rules/when-you-use-mentions-in-a-pbi/" />';
const messages = HTMLHint.verify(code, ruleOptions);
Expand Down
6 changes: 0 additions & 6 deletions docker/test/figure-must-use-the-right-code.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = "figure-must-use-the-right-code";

const ruleOptions = {};

const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruldId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it("Figures not wrapped in figcaption must result in an error", () => {
const code = "<p>Figure: Caption</p>";
Expand Down
6 changes: 0 additions & 6 deletions docker/test/font-tag-must-not-be-used.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = 'font-tag-must-not-be-used'

const ruleOptions = {}

const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it('Anything that is not font tag should not result in an error', () => {
const code = '<p color="red">Text</p>'
Expand Down
6 changes: 0 additions & 6 deletions docker/test/grammar-scrum-terms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = "grammar-scrum-terms";

const ruleOptions = {};

const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruldId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it("Scrum terms that are cased correctly should not result in an error", () => {
const code =
Expand Down
7 changes: 7 additions & 0 deletions docker/test/hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { addCustomHtmlRule } = require('../customHtmlRules');

exports.mochaHooks = {
async beforeAll() {
await addCustomHtmlRule(null, 'https://ssw.com.au/');
},
};
6 changes: 0 additions & 6 deletions docker/test/link-must-not-show-unc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = 'link-must-not-show-unc'

const ruleOptions = {}

const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it('Href that does not show UNC should not result in an error', () => {
const code = '<a href="/ssw">somelink</a>'
Expand Down
24 changes: 24 additions & 0 deletions docker/test/link-scanning/codeauditor-test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const expect = require('expect.js')
const HTMLHint = require("htmlhint").default;
const { runBrokenLinkCheck, readCsv } = require("../../utils")
const { htmlHintConfig, fetchHtml } = require("../../api");

let testUrls = "https://asia-east2-sswlinkauditor-c1131.cloudfunctions.net/api/testing/statichtmlpage";

describe(`Test CodeAuditor Run`, () => {
it('Test CodeAuditor run', async () => {
// Test Scanning links
const [result, error] = runBrokenLinkCheck(testUrls);
if (error) {
console.log(`Error scanning broken links: ${error}`);
}
const scanResults = await readCsv("./all_links.csv");

// Test Checking HTML Errors/Warnings
let html = await fetchHtml(testUrls);
const htmlHintResult = HTMLHint.verify(html, htmlHintConfig);

expect(scanResults.length).to.be(5);
expect(htmlHintResult.length).to.be(22);
}).timeout(10000)
})
6 changes: 0 additions & 6 deletions docker/test/meta-tags-must-not-redirect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = 'meta-tag-must-not-redirect'

const ruleOptions = {}

const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it('Meta tags that does not refresh should not result in an error', () => {
const code = '<meta name="description" />'
Expand Down
6 changes: 0 additions & 6 deletions docker/test/page-must-not-show-email-addresses.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = 'page-must-not-show-email-addresses'

const ruleOptions = {}

const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it('Page that does not show email addresses should not result in an error', () => {
const code = '<a href="...">email address</a>'
Expand Down
6 changes: 0 additions & 6 deletions docker/test/phone-numbers-without-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const ruleId = "phone-numbers-without-links";

const ruleOptions = {};

const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruleId] = true;

const phoneNumbers = [
Expand All @@ -27,10 +25,6 @@ const nonPhoneNumbers = [
"20231102.4"
];

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruleId}`, () => {

phoneNumbers.forEach((phone) => {
Expand Down
6 changes: 0 additions & 6 deletions docker/test/url-must-be-formatted-correctly.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = "url-must-be-formatted-correctly";

const ruleOptions = {};

const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruldId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it("URL with full stop at the end should result in an error", () => {
const code = '<a href="www.ssw.com.au/Thisisarule." />';
Expand Down
6 changes: 0 additions & 6 deletions docker/test/url-must-not-have-click-here.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = 'url-must-not-have-click-here'

const ruleOptions = {}

const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it('URL text without words click here should not result in an error', () => {
const code = '<a href="www.ssw.com.au/Thisisarule">Not Click Here</a>'
Expand Down
6 changes: 0 additions & 6 deletions docker/test/url-must-not-have-space.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = 'url-must-not-have-space'

const ruleOptions = {}

const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it('URL without space should not result in an error', () => {
const code = '<a href="www.ssw.com.au/Thisisarule" />'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ const ruldId = "use-unicode-hex-code-for-special-html-characters";

const ruleOptions = {};

const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruldId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
it("Non code tag with special char should result in an error", () => {
const code = '<span>aaa>bbb<ccc</span>';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"engines" : {
"npm" : ">=8.0.0 <9.0.0",
"node" : "16.x"
"node" : "18.x"
},
"repository": {
"type": "git",
Expand Down
Loading