Fix tests

This commit is contained in:
Reinier Criel 2025-12-08 15:23:44 -08:00
parent d9fe775d11
commit c51956b2db
2 changed files with 12 additions and 8 deletions

View file

@ -15,8 +15,7 @@ import { ui } from "../environment/userInteraction.js";
*/ */
function isParsable(pem) { function isParsable(pem) {
if (!pem || typeof pem !== "string") return false; if (!pem || typeof pem !== "string") return false;
// Normalize Windows CRLF to LF to ensure consistent parsing pem = normalizeLineEndings(pem);
pem = pem.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
const begin = "-----BEGIN CERTIFICATE-----"; const begin = "-----BEGIN CERTIFICATE-----";
const end = "-----END CERTIFICATE-----"; const end = "-----END CERTIFICATE-----";
const blocks = []; const blocks = [];
@ -118,6 +117,15 @@ function normalizePathF(p) {
return p.replace(/\\/g, "/"); 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 * Read and validate user certificate file
* @param {string} certPath - Path to certificate file * @param {string} certPath - Path to certificate file
@ -164,11 +172,7 @@ function readUserCertificateFile(certPath) {
// 5) Validate PEM format // 5) Validate PEM format
if (!isParsable(content)) { if (!isParsable(content)) {
// Fallback: accept if it at least contains PEM delimiters return null;
// (covers edge cases with unusual formatting that X509Certificate might reject)
if (!content.includes("-----BEGIN CERTIFICATE-----") || !content.includes("-----END CERTIFICATE-----")) {
return null;
}
} }
return content; return content;

View file

@ -340,7 +340,7 @@ describe("E2E: NODE_EXTRA_CA_CERTS merging", () => {
); );
assert.ok( 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}` `bun i failed with valid NODE_EXTRA_CA_CERTS. Output was:\n${result.output}`
); );
}); });