From 4210d00ac410a58d61ea006342df01702cc499e9 Mon Sep 17 00:00:00 2001 From: Reinier Criel Date: Mon, 8 Dec 2025 15:23:44 -0800 Subject: [PATCH] Fix tests --- .../safe-chain/src/registryProxy/certBundle.js | 18 +++++++++++------- test/e2e/certbundle.e2e.spec.js | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/safe-chain/src/registryProxy/certBundle.js b/packages/safe-chain/src/registryProxy/certBundle.js index ab0ac63..78e0f70 100644 --- a/packages/safe-chain/src/registryProxy/certBundle.js +++ b/packages/safe-chain/src/registryProxy/certBundle.js @@ -15,8 +15,7 @@ import { ui } from "../environment/userInteraction.js"; */ function isParsable(pem) { if (!pem || typeof pem !== "string") return false; - // Normalize Windows CRLF to LF to ensure consistent parsing - pem = pem.replace(/\r\n/g, "\n").replace(/\r/g, "\n"); + pem = normalizeLineEndings(pem); const begin = "-----BEGIN CERTIFICATE-----"; const end = "-----END CERTIFICATE-----"; const blocks = []; @@ -118,6 +117,15 @@ function normalizePathF(p) { return p.replace(/\\/g, "/"); } +/** + * Normalize line endings to LF + * @param {string} text - Text with mixed line endings + * @returns {string} + */ +function normalizeLineEndings(text) { + return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n"); +} + /** * Read and validate user certificate file * @param {string} certPath - Path to certificate file @@ -164,11 +172,7 @@ function readUserCertificateFile(certPath) { // 5) Validate PEM format if (!isParsable(content)) { - // Fallback: accept if it at least contains PEM delimiters - // (covers edge cases with unusual formatting that X509Certificate might reject) - if (!content.includes("-----BEGIN CERTIFICATE-----") || !content.includes("-----END CERTIFICATE-----")) { - return null; - } + return null; } return content; diff --git a/test/e2e/certbundle.e2e.spec.js b/test/e2e/certbundle.e2e.spec.js index a60dc3b..055b29d 100644 --- a/test/e2e/certbundle.e2e.spec.js +++ b/test/e2e/certbundle.e2e.spec.js @@ -340,7 +340,7 @@ describe("E2E: NODE_EXTRA_CA_CERTS merging", () => { ); assert.ok( - result.output.includes("no malware found."), + result.output.includes("installed") || result.output.includes("packages installed"), `bun i failed with valid NODE_EXTRA_CA_CERTS. Output was:\n${result.output}` ); });