mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Add tests
This commit is contained in:
parent
1f707c1e13
commit
fbb7e0f95f
10 changed files with 1934 additions and 22 deletions
|
|
@ -1,12 +1,20 @@
|
|||
import fetch from "make-fetch-happen";
|
||||
import { getEcoSystem } from "../config/settings.js";
|
||||
|
||||
const malwareDatabaseUrl =
|
||||
"https://malware-list.aikido.dev/malware_predictions.json";
|
||||
const malwareDatabaseUrls = {
|
||||
js: "https://malware-list.aikido.dev/malware_predictions.json",
|
||||
python: "https://malware-list.aikido.dev/malware_predictions_python.json",
|
||||
};
|
||||
|
||||
export async function fetchMalwareDatabase() {
|
||||
const ecosystem = getEcoSystem() || "js";
|
||||
if (ecosystem === "py") {
|
||||
console.log("**aikido.js** Using 'python' ecosystem for malware database fetch");
|
||||
}
|
||||
const malwareDatabaseUrl = malwareDatabaseUrls[ecosystem];
|
||||
const response = await fetch(malwareDatabaseUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error fetching malware database: ${response.statusText}`);
|
||||
throw new Error(`Error fetching ${ecosystem} malware database: ${response.statusText}`);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -16,17 +24,23 @@ export async function fetchMalwareDatabase() {
|
|||
version: response.headers.get("etag") || undefined,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new Error(`Error parsing malware database: ${error.message}`);
|
||||
throw new Error(`Error parsing ${ecosystem} malware database: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchMalwareDatabaseVersion() {
|
||||
const ecosystem = getEcoSystem() || "js";
|
||||
if (ecosystem === "py") {
|
||||
console.log("**aikido.js** Using 'python' ecosystem for malware database fetch");
|
||||
}
|
||||
|
||||
const malwareDatabaseUrl = malwareDatabaseUrls[ecosystem];
|
||||
const response = await fetch(malwareDatabaseUrl, {
|
||||
method: "HEAD",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Error fetching malware database version: ${response.statusText}`
|
||||
`Error fetching ${ecosystem} malware database version: ${response.statusText}`
|
||||
);
|
||||
}
|
||||
return response.headers.get("etag") || undefined;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue