Skip to content

Commit b5bfdc9

Browse files
bmcutlerMasterOdin
andauthored
Add validation of security tag (#5)
Co-authored-by: Matthew Peveler <[email protected]>
1 parent df25179 commit b5bfdc9

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

dist/index.js

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/validate.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const sysadminTag = "[SYSADMIN ACTION]";
2+
const securityTag = "[SECURITY]";
23
const allowedTypes = [
34
"Bugfix",
45
"Feature",
@@ -30,21 +31,30 @@ const allowedModules = [
3031
export function checkTitle(fullTitle: string): true {
3132
let title = fullTitle;
3233
let hasSysadminTag = false;
34+
let hasSecurityTag = false;
3335

3436
if (title.startsWith(sysadminTag)) {
3537
hasSysadminTag = true;
3638
title = title.substring(sysadminTag.length);
3739
if (title.startsWith(" ")) {
38-
throw new Error(
39-
`There should not be a space between ${sysadminTag} and [<TYPE>:<MODULE>].`
40-
);
40+
throw new Error(`There should not be a space following ${sysadminTag}.`);
41+
}
42+
}
43+
44+
if (title.startsWith(securityTag)) {
45+
hasSecurityTag = true;
46+
title = title.substring(securityTag.length);
47+
if (title.startsWith(" ")) {
48+
throw new Error(`There should not be a space following ${securityTag}.`);
4149
}
4250
}
4351

4452
if (!/^\[[a-zA-Z0-9\\/]+(?::[a-zA-Z0-9\\/]+)?\] /.test(title)) {
4553
throw new Error(
4654
`Invalid title format, must start with ${
4755
hasSysadminTag ? sysadminTag : ""
56+
}${
57+
hasSecurityTag ? securityTag : ""
4858
}[<TYPE>:<MODULE>] and have space before description.`
4959
);
5060
}

test/validate.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ describe("validate", () => {
1212
"[Bugfix:SubminiPolls] xxxx",
1313
"[Feature:HelpQueue] xxxx",
1414
"[SYSADMIN ACTION][Refactor:Autograding] xxxx",
15+
"[SECURITY][Bugfix:Submission] Some security hole",
16+
"[SYSADMIN ACTION][SECURITY][Bugfix:Submission] xxxx",
1517
"[DevDependency] xxxx",
1618
"[Dependency] xxxx",
1719
"[Bugfix:Submission] 0123456789012345678901234567890123456789",
@@ -34,6 +36,30 @@ describe("validate", () => {
3436
"[SYSADMINACTION][Refactor:Autograding] xxxx",
3537
"Invalid title format, must start with [<TYPE>:<MODULE>] and have space before description.",
3638
],
39+
[
40+
"[SYSADMIN ACTION] [Refactor:Submission] test",
41+
"There should not be a space following [SYSADMIN ACTION].",
42+
],
43+
[
44+
"[SYSADMIN ACTION][Refactor:Autograding]foo",
45+
"Invalid title format, must start with [SYSADMIN ACTION][<TYPE>:<MODULE>] and have space before description.",
46+
],
47+
[
48+
"[SECURITY] [Refactor:Submission] test",
49+
"There should not be a space following [SECURITY].",
50+
],
51+
[
52+
"[SECURITY][Refactor:Autograding]foo",
53+
"Invalid title format, must start with [SECURITY][<TYPE>:<MODULE>] and have space before description.",
54+
],
55+
[
56+
"[SYSADMIN ACTION][SECURITY][Refactor:Autograding]foo",
57+
"Invalid title format, must start with [SYSADMIN ACTION][SECURITY][<TYPE>:<MODULE>] and have space before description.",
58+
],
59+
[
60+
"[SECURITY][SYSADMIN ACTION][Refactor:Autograding] foo",
61+
"Invalid title format, must start with [SECURITY][<TYPE>:<MODULE>] and have space before description.",
62+
],
3763
].forEach(([value, expectedException]) => {
3864
it(`checkTitle should throw: ${value}`, () => {
3965
expect(() => checkTitle(value)).to.throw(expectedException);

0 commit comments

Comments
 (0)