-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch: made the source code of bashaway testing utils public
- Loading branch information
1 parent
4f0afc2
commit 84b27c3
Showing
7 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import exec from "@sliit-foss/actions-exec-wrapper"; | ||
|
||
const countLines = (str) => str.split(/\r\n|\r|\n/).length; | ||
|
||
export const dependencyCount = () => exec("npm ls --parseable").then((output) => countLines(output) - 2); | ||
|
||
export const globalDependencyCount = () => exec("npm ls -g --parseable").then((output) => countLines(output) - 2); | ||
|
||
export const prohibitedCommands = /(npm|pnpm|yarn|npx)\s+(i|install|add|exec|dlx)\s+\S+/g; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import exec from "@sliit-foss/actions-exec-wrapper"; | ||
import axios from "axios"; | ||
|
||
export const commitList = async (urlOrPath) => { | ||
if (urlOrPath?.includes("https://")) { | ||
await exec(`git clone ${urlOrPath} out`); | ||
process.chdir("out"); | ||
} else { | ||
process.chdir(urlOrPath); | ||
} | ||
const commits = await exec(`git log --pretty=format:"%h (%cd) %s|||%cn|||%ce|||%an|||%ae" --date=iso`); | ||
return commits | ||
?.split("\n") | ||
?.filter((c) => c) | ||
?.map((commit) => { | ||
const [, date, time, offset, ...info] = commit?.split(" "); | ||
const [message, commiterName, commiterEmail, authorName, authorEmail] = info?.join(" ")?.split("|||"); | ||
return { | ||
message, | ||
timestamp: new Date(`${date.replace("(", "")} ${time} ${offset.replace(")", "")}`).getTime(), | ||
commiterName, | ||
commiterEmail, | ||
authorName, | ||
authorEmail | ||
}; | ||
}); | ||
}; | ||
|
||
export const ghOrgRepos = async (org) => { | ||
return axios.get(`https://api.github.com/orgs/${org}/repos?per_page=1000`).then((res) => res.data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
import { compactString, functionCallFollowedByAnd, functionCalls } from "./patterns"; | ||
|
||
export * from "./commands"; | ||
export * from "./git"; | ||
export * from "./patterns"; | ||
export * from "./restrict"; | ||
export * from "./scan"; | ||
export * from "./_"; | ||
export * from "./secrets"; | ||
|
||
export const cleanLogs = (code) => | ||
compactString( | ||
code.replace( | ||
code.includes("console.log") | ||
? functionCallFollowedByAnd("console.log") | ||
: functionCalls(["print", "System.out.println", "Console.WriteLine"]), | ||
"" | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const functionCall = (fn) => new RegExp(`${fn}\\([^)]*\\);?`, "g"); | ||
|
||
export const functionCallFollowedByAnd = (fn) => new RegExp(`${fn}\\([^)]*\\);?(\\s*&&\\s*)?`, "g"); | ||
|
||
export const functionCalls = (fns) => new RegExp(`(${fns.join("|")})\\([^)]*\\);?`, "g"); | ||
|
||
export const compactString = (str) => | ||
str | ||
.replace(/\/\/.*\n/g, "") | ||
.replace(/\s/g, "") | ||
.trim(); | ||
|
||
export const isStrongPassword = (str) => str.match(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const restrictJavascript = (script) => { | ||
expect(script).not.toContain("node --eval"); | ||
expect(script).not.toContain("node -e"); | ||
expect(script).not.toContain("deno run"); | ||
expect(script).not.toContain("bun"); | ||
}; | ||
|
||
export const restrictPython = (script) => { | ||
expect(script).not.toContain("python"); | ||
expect(script).not.toContain("python3"); | ||
expect(script).not.toContain("pip install"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const generateSecrets = (content, service) => { | ||
const services = content | ||
.split("---") | ||
?.filter((service) => !service.split("\n")?.every((svc) => ["\r", "", " "].includes(svc))) | ||
.map((service) => { | ||
const lines = service.split("\n"); | ||
const keyStartIndex = lines.indexOf(lines.find((l) => l.includes("stringData:"))); | ||
const keys = lines.reduce((acc, line, index) => { | ||
if (index > keyStartIndex && !line.trim()?.startsWith("#") && line.includes(":") && line.split(":")?.[1]) { | ||
let key = line.split(":").splice(1).join(":").trim(); | ||
if (key.startsWith('"') && key.endsWith('"')) { | ||
key = key.substring(1, key.length - 1); | ||
} | ||
acc[line.split(":")[0]?.trim()] = key; | ||
} | ||
return acc; | ||
}, {}); | ||
return { | ||
name: lines | ||
.find((l) => l.includes("name:")) | ||
?.split(":")[1] | ||
.trim(), | ||
keys | ||
}; | ||
}); | ||
const serviceKeys = services.find((s) => s.name === `${service}-secret`)?.keys; | ||
return Object.keys(serviceKeys) | ||
.map((key) => `${key}=${serviceKeys[key]}`) | ||
?.join("\n"); | ||
}; |