Fix tests

This commit is contained in:
Reinier Criel 2025-12-08 15:23:44 -08:00 committed by Sander Declerck
parent 7b5a700655
commit 4210d00ac4
No known key found for this signature in database
2 changed files with 12 additions and 8 deletions

View file

@ -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,12 +172,8 @@ 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 content;
} catch {

View file

@ -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}`
);
});