Skip to content

Commit

Permalink
test: use non-existant dir path to trigger failed key write
Browse files Browse the repository at this point in the history
Using permissions did not work, so let's try using non-existant directory.
  • Loading branch information
ahwayakchih committed Feb 16, 2025
1 parent a5416a3 commit b71ac7a
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions test/lib/keypair.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,9 @@ test('keypair', t => {
t.strictEqual(keypairFailedOnRead, null, 'Should return `null` if key file exists but could not be read');
fs.unlinkSync(failPath);

mask = process.umask(0o000);
const failDirPath = 'forbidden-write-dir';
const readOnly = 0o444;
fs.mkdir(failDirPath, {mode: readOnly}, err => {
process.umask(mask);
t.strictEqual(err, null, 'Should be able to create directory for testing');
const failKeyPath = `${failDirPath}/test`;
const keypairFailedOnWriteDir = keypair(failKeyPath);
t.strictEqual(keypairFailedOnWriteDir, null, 'Should return `null` if key file could not be written');
fs.rmdir(failDirPath, () => {
// We ignore possible error when trying to remove test directory
t.end();
});
});
const failDirPath = 'non-existant-write-dir';
const failKeyPath = `${failDirPath}/test`;
const keypairFailedOnWriteDir = keypair(failKeyPath);
t.strictEqual(keypairFailedOnWriteDir, null, 'Should return `null` if key file could not be written');
t.end();
});

0 comments on commit b71ac7a

Please sign in to comment.