Skip to content

Commit cdb03a0

Browse files
test: handle FIPS-on-by-default in cipher/hash cache test
Capture initialFips state and explicitly disable FIPS before recording the baseline algorithm lists, so the test works correctly on systems where FIPS is enabled by default. Restore the original state on exit. Signed-off-by: srikanth-karthi <[email protected]>
1 parent 7ffbd6d commit cdb03a0

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

test/parallel/test-crypto-ciphers-hashes-fips-cache.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ if (!testFipsCrypto())
1818
const assert = require('assert');
1919
const { getCiphers, getHashes, setFips, getFips } = require('crypto');
2020

21-
// Record the full lists available when FIPS is off.
21+
const initialFips = getFips();
22+
23+
// Ensure FIPS is off so we can capture the full algorithm lists as a baseline,
24+
// regardless of whether the system has FIPS on by default.
25+
if (initialFips)
26+
setFips(false);
27+
2228
const ciphersWithoutFips = getCiphers();
2329
const hashesWithoutFips = getHashes();
2430

@@ -60,7 +66,7 @@ for (const hash of hashesWithFips) {
6066
);
6167
}
6268

63-
// Restore; the cache must be evicted again so the full lists come back.
69+
// Turn FIPS back off; the cache must be evicted so the full lists come back.
6470
setFips(false);
6571
assert.strictEqual(getFips(), 0);
6672

@@ -74,3 +80,7 @@ assert.deepStrictEqual(
7480
hashesWithoutFips,
7581
'getHashes() should match pre-FIPS list after setFips(false)'
7682
);
83+
84+
// Restore the original FIPS state.
85+
if (initialFips)
86+
setFips(true);

0 commit comments

Comments
 (0)