-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable back the tests that were not running.
- Loading branch information
Showing
7 changed files
with
290 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const keyring = require("../src/node"); | ||
const assert = require("node:assert"); | ||
|
||
// Encrypted File Store tests | ||
assert(keyring.FileStore.set, "keyring.FileStore.set is undefined"); | ||
assert(keyring.FileStore.get, "keyring.FileStore.get is undefined"); | ||
assert(keyring.FileStore.list, "keyring.FileStore.list is undefined"); | ||
assert(keyring.FileStore.remove, "keyring.FileStore.remove is undefined"); | ||
|
||
const fileName = "test.key"; | ||
const data = "hello from file keystore"; | ||
const password = "password123"; | ||
|
||
function testSetFileStore(context) { | ||
return () => { | ||
const result = keyring.FileStore.set( | ||
context.tmpDir, | ||
fileName, | ||
data, | ||
password | ||
); | ||
console.log("keyring.FileStore.set returns:", result); | ||
assert.strictEqual(result, "success", "Unexpected value returned"); | ||
}; | ||
} | ||
|
||
function testGetFileStore(context) { | ||
return () => { | ||
const dataResult = keyring.FileStore.get( | ||
context.tmpDir, | ||
fileName, | ||
password | ||
); | ||
console.log("keyring.FileStore.get returns:", dataResult); | ||
assert.strictEqual(dataResult, data, "Unexpected value returned"); | ||
}; | ||
} | ||
|
||
function testListFileStore(context) { | ||
return () => { | ||
const result = keyring.FileStore.list(context.tmpDir); | ||
console.log("keyring.FileStore.list returns:", result); | ||
assert( | ||
Array.isArray(result) && result.includes(fileName), | ||
"Unexpected value returned" | ||
); | ||
}; | ||
} | ||
|
||
function testRemoveFileStore(context) { | ||
return () => { | ||
const result = keyring.FileStore.remove(context.tmpDir, fileName); | ||
console.log("keyring.FileStore.remove returns:", result); | ||
|
||
const list = keyring.FileStore.list(context.tmpDir); | ||
assert( | ||
Array.isArray(list) && !list.includes(fileName), | ||
"Unexpected value returned" | ||
); | ||
}; | ||
} | ||
|
||
function run(context) { | ||
assert.doesNotThrow( | ||
testSetFileStore(context), | ||
undefined, | ||
"testSetFileStore threw an expection" | ||
); | ||
assert.doesNotThrow( | ||
testGetFileStore(context), | ||
undefined, | ||
"testGetFileStore threw an expection" | ||
); | ||
assert.doesNotThrow( | ||
testListFileStore(context), | ||
undefined, | ||
"testListFileStore threw an expection" | ||
); | ||
assert.doesNotThrow( | ||
testRemoveFileStore(context), | ||
undefined, | ||
"testRemoveFileStore threw an expection" | ||
); | ||
} | ||
|
||
module.exports = { | ||
run, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const fs = require("node:fs"); | ||
const os = require("node:os"); | ||
const path = require("node:path"); | ||
|
||
const context = { | ||
tmpDir: fs.mkdtempSync(path.join(os.tmpdir(), "archway-keyring-test-")), | ||
}; | ||
|
||
["file", "os", "unencrypted"].forEach((test) => { | ||
console.log(`\n=> Testing ${test}`); | ||
require(`./${test}`).run(context); | ||
}); | ||
|
||
try { | ||
fs.rmSync(context.tmpDir, { recursive: true }); | ||
} catch (e) { | ||
console.error( | ||
`An error has occurred while cleaning up the temp folder at ${tmpDir}` | ||
); | ||
} | ||
|
||
console.log("\nAll tests passed!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const keyring = require("../src/node"); | ||
const assert = require("assert"); | ||
|
||
// OS Store tests | ||
assert(keyring.OsStore.set, "keyring.OsStore.set is undefined"); | ||
assert(keyring.OsStore.get, "keyring.OsStore.get is undefined"); | ||
assert(keyring.OsStore.list, "keyring.OsStore.list is undefined"); | ||
assert(keyring.OsStore.remove, "keyring.OsStore.remove is undefined"); | ||
|
||
const serviceName = "archway-keyring-test"; | ||
const keyName = "test"; | ||
const data = "hello from os keyring"; | ||
|
||
function testSetOsStore(_context) { | ||
return () => { | ||
const result = keyring.OsStore.set(serviceName, keyName, data); | ||
console.log("keyring.OsStore.set returns:", result); | ||
assert.strictEqual(result, "success", "Unexpected value returned"); | ||
}; | ||
} | ||
|
||
function testGetOsStore(_context) { | ||
return () => { | ||
const result = keyring.OsStore.get(serviceName, keyName); | ||
console.log("keyring.OsStore.get returns:", result); | ||
assert.strictEqual(result, data, "Unexpected value returned"); | ||
}; | ||
} | ||
|
||
function testListOsStore(_context) { | ||
return () => { | ||
const result = keyring.OsStore.list(serviceName); | ||
console.log("keyring.OsStore.list returns:", result); | ||
assert( | ||
Array.isArray(result) && result.includes(keyName), | ||
"Unexpected value returned" | ||
); | ||
}; | ||
} | ||
|
||
function testRemoveOsStore(_context) { | ||
return () => { | ||
const result = keyring.OsStore.remove(serviceName, keyName); | ||
console.log("keyring.OsStore.remove returns:", result); | ||
|
||
const list = keyring.OsStore.list(serviceName); | ||
assert( | ||
Array.isArray(list) && !list.includes(keyName), | ||
"Unexpected value returned" | ||
); | ||
}; | ||
} | ||
|
||
function run(context) { | ||
assert.doesNotThrow( | ||
testSetOsStore(context), | ||
undefined, | ||
"testSetOsStore threw an expection" | ||
); | ||
assert.doesNotThrow( | ||
testGetOsStore(context), | ||
undefined, | ||
"testGetOsStore threw an expection" | ||
); | ||
assert.doesNotThrow( | ||
testListOsStore(context), | ||
undefined, | ||
"testListOsStore threw an expection" | ||
); | ||
assert.doesNotThrow( | ||
testRemoveOsStore(context), | ||
undefined, | ||
"testRemoveOsStore threw an expection" | ||
); | ||
} | ||
|
||
module.exports = { | ||
run, | ||
}; |
Oops, something went wrong.