Another try

This commit is contained in:
Reinier Criel 2025-11-27 13:25:53 -08:00
parent 0106767c35
commit 2810a87cd0
2 changed files with 10 additions and 13 deletions

View file

@ -168,7 +168,16 @@ function loadCa() {
} }
const { privateKey, certificate } = generateCa(); const { privateKey, certificate } = generateCa();
// Ensure directory exists before writing files
try {
fs.mkdirSync(certFolder, { recursive: true }); fs.mkdirSync(certFolder, { recursive: true });
} catch (error) {
// Directory might already exist or there's a permission issue
if (/** @type {any} */(error).code !== 'EEXIST') {
throw error;
}
}
// Write files and ensure they're flushed to disk // Write files and ensure they're flushed to disk
const keyFd = fs.openSync(keyPath, 'w'); const keyFd = fs.openSync(keyPath, 'w');

View file

@ -9,23 +9,11 @@ import {
import { getCaCertPath } from "./certUtils.js"; import { getCaCertPath } from "./certUtils.js";
import { setEcoSystem, ECOSYSTEM_JS, ECOSYSTEM_PY } from "../config/settings.js"; import { setEcoSystem, ECOSYSTEM_JS, ECOSYSTEM_PY } from "../config/settings.js";
import fs from "fs"; import fs from "fs";
import path from "path";
import os from "os";
describe("registryProxy.mitm", () => { describe("registryProxy.mitm", () => {
let proxy, proxyHost, proxyPort; let proxy, proxyHost, proxyPort;
before(async () => { before(async () => {
// Clean up any existing CA certificates to ensure fresh generation with new extensions
const certFolder = path.join(os.homedir(), ".safe-chain", "certs");
try {
if (fs.existsSync(certFolder)) {
fs.rmSync(certFolder, { recursive: true, force: true });
}
} catch (error) {
// Ignore errors during cleanup
}
proxy = createSafeChainProxy(); proxy = createSafeChainProxy();
await proxy.startServer(); await proxy.startServer();
const envVars = mergeSafeChainProxyEnvironmentVariables([]); const envVars = mergeSafeChainProxyEnvironmentVariables([]);