diff --git a/packages/safe-chain/src/registryProxy/certUtils.js b/packages/safe-chain/src/registryProxy/certUtils.js index da969fc..c9fe99a 100644 --- a/packages/safe-chain/src/registryProxy/certUtils.js +++ b/packages/safe-chain/src/registryProxy/certUtils.js @@ -168,7 +168,16 @@ function loadCa() { } const { privateKey, certificate } = generateCa(); - fs.mkdirSync(certFolder, { recursive: true }); + + // Ensure directory exists before writing files + try { + 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 const keyFd = fs.openSync(keyPath, 'w'); diff --git a/packages/safe-chain/src/registryProxy/registryProxy.mitm.spec.js b/packages/safe-chain/src/registryProxy/registryProxy.mitm.spec.js index 82abe0c..6855449 100644 --- a/packages/safe-chain/src/registryProxy/registryProxy.mitm.spec.js +++ b/packages/safe-chain/src/registryProxy/registryProxy.mitm.spec.js @@ -9,23 +9,11 @@ import { import { getCaCertPath } from "./certUtils.js"; import { setEcoSystem, ECOSYSTEM_JS, ECOSYSTEM_PY } from "../config/settings.js"; import fs from "fs"; -import path from "path"; -import os from "os"; describe("registryProxy.mitm", () => { let proxy, proxyHost, proxyPort; 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(); await proxy.startServer(); const envVars = mergeSafeChainProxyEnvironmentVariables([]);