system-secured-storage
Version:
A Node.js project that allows users to store encrypted key-value data locally on their system. This project serves as an alternate storage solution to SQLite but with enhanced security features, leveraging AES encryption to ensure the confidentiality and
50 lines • 2.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
const globals_1 = require("@jest/globals");
const system_secured_storage_service_1 = require("../services/system-secured-storage.service");
(0, globals_1.describe)('Syncronous system secured storage', () => {
let systemSecuredStorage;
const TESTING_DATA = 'Testing text !@#$%^&*()_+';
const fileName = 'data.encrypted';
(0, globals_1.beforeAll)(() => {
systemSecuredStorage = new system_secured_storage_service_1.SystemSecuredStorage({
directory: __dirname,
encryptionKey: 'de746182415c1a57acaa6e53b6eeb66be0c4d13cb6206d6a1dabf29422fe5581',
ivKey: 'a5cf58ee1df1343334a5ec799c237256',
});
});
(0, globals_1.it)('Should store the encrypted data in a file locally.', () => {
systemSecuredStorage.storeData('key', TESTING_DATA);
const isFileStorageExists = (0, node_fs_1.existsSync)((0, node_path_1.resolve)(__dirname, fileName));
(0, globals_1.expect)(isFileStorageExists).toBeDefined();
});
(0, globals_1.it)(`Should retrieve data in key 'key' from the encrypted storage.`, () => {
const data = systemSecuredStorage.retrieveData('key');
(0, globals_1.expect)(data).toBeDefined();
(0, globals_1.expect)(data).toEqual(TESTING_DATA);
});
(0, globals_1.it)(`Retrieving data in a non-existing key 'abc' should be undefined.`, () => {
const data = systemSecuredStorage.retrieveData('abc');
(0, globals_1.expect)(data).toBeUndefined();
});
(0, globals_1.it)('Should retrieve all the data from the storage.', () => {
const storageData = systemSecuredStorage.retrieveAll();
(0, globals_1.expect)(storageData).toBeDefined();
(0, globals_1.expect)(typeof storageData).toBe('object');
(0, globals_1.expect)(Object.keys(storageData)).toContain('key');
});
(0, globals_1.it)(`Should delete data stored in 'key'.`, () => {
systemSecuredStorage.deleteData('key');
const data = systemSecuredStorage.retrieveData('key');
(0, globals_1.expect)(data).toBeUndefined();
});
(0, globals_1.it)('Should reset the storage by clearing it.', () => {
systemSecuredStorage.storeData('key', TESTING_DATA);
systemSecuredStorage.reset();
const storageData = systemSecuredStorage.retrieveAll();
(0, globals_1.expect)(storageData).toBeUndefined();
});
});
//# sourceMappingURL=system-secured-storage.service.test.js.map