Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,74 @@
|
||||
// Generated, do not edit. sha256:d1b5492d54f83698bbcb8bdc3d04e455dbca8d3823702e08f9379c11b89bc2c0
|
||||
import { describe, it, beforeEach, afterEach } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtemp, rm, readFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
|
||||
import { writeActiveName } from '../../server/portfolios.mjs';
|
||||
import { secretsFile } from '../../server/keys.mjs';
|
||||
import { handleSecret, _resetHandleSecret } from '../../server/ai/handle-secret.mjs';
|
||||
|
||||
let DIR;
|
||||
let vorige;
|
||||
|
||||
beforeEach(async () => {
|
||||
vorige = process.env.ASSETAPP_DATA_DIR;
|
||||
DIR = await mkdtemp(join(tmpdir(), 'assetapp-handle-'));
|
||||
process.env.ASSETAPP_DATA_DIR = DIR;
|
||||
_resetHandleSecret();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
_resetHandleSecret();
|
||||
if (vorige === undefined) delete process.env.ASSETAPP_DATA_DIR;
|
||||
else process.env.ASSETAPP_DATA_DIR = vorige;
|
||||
await rm(DIR, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe('handleSecret: één geheim per portefeuille', () => {
|
||||
it('geeft twee portefeuilles een VERSCHILLEND geheim, ook binnen hetzelfde proces', async () => {
|
||||
writeActiveName('Echt');
|
||||
const echt = await handleSecret();
|
||||
|
||||
writeActiveName('Demo');
|
||||
const demo = await handleSecret();
|
||||
|
||||
assert.notEqual(demo, echt, 'anders krijgt dezelfde rij-id in beide portefeuilles dezelfde handle');
|
||||
assert.match(echt, /^[0-9a-f]{64}$/);
|
||||
assert.match(demo, /^[0-9a-f]{64}$/);
|
||||
});
|
||||
|
||||
it('geeft binnen één portefeuille elke keer hetzelfde geheim terug', async () => {
|
||||
writeActiveName('Echt');
|
||||
const eerste = await handleSecret();
|
||||
assert.equal(await handleSecret(), eerste);
|
||||
|
||||
_resetHandleSecret();
|
||||
assert.equal(await handleSecret(), eerste);
|
||||
});
|
||||
|
||||
it('komt na heen-en-weer wisselen weer bij het eigen geheim uit', async () => {
|
||||
writeActiveName('Echt');
|
||||
const echt = await handleSecret();
|
||||
writeActiveName('Demo');
|
||||
await handleSecret();
|
||||
writeActiveName('Echt');
|
||||
|
||||
assert.equal(await handleSecret(), echt);
|
||||
});
|
||||
|
||||
it('schrijft het geheim in het geheimenbestand van díe portefeuille en nergens anders', async () => {
|
||||
writeActiveName('Echt');
|
||||
const echt = await handleSecret();
|
||||
const echtPad = secretsFile();
|
||||
|
||||
writeActiveName('Demo');
|
||||
await handleSecret();
|
||||
|
||||
const inEcht = JSON.parse(await readFile(echtPad, 'utf-8'));
|
||||
const inDemo = JSON.parse(await readFile(secretsFile(), 'utf-8'));
|
||||
assert.equal(inEcht.ai_handle_secret, echt);
|
||||
assert.notEqual(inDemo.ai_handle_secret, echt);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user