Twitch-VOD-Manager/src/main/infra/secure-storage.test.ts
xRangerDE d1eacf31f2 feat(auth): SecureStorage interface + Memory + Electron impls (7 tests)
Electron impl wraps safeStorage (Win Credential Manager). MemoryImpl uses
base64 (no real crypto) — clearly marks isEncryptionAvailable()=false for
test/headless envs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 22:12:23 +02:00

46 lines
1.7 KiB
TypeScript

import { test, expect, describe } from 'vitest';
import { MemorySecureStorage, createElectronSecureStorage, type SecureStorage } from './secure-storage';
describe('MemorySecureStorage', () => {
test('isEncryptionAvailable returns false (kennzeichnet Memory-Mode)', () => {
const s: SecureStorage = new MemorySecureStorage();
expect(s.isEncryptionAvailable()).toBe(false);
});
test('roundtrip ascii', () => {
const s = new MemorySecureStorage();
const cipher = s.encrypt('hello');
expect(cipher).not.toBe('hello'); // base64-Kodierung greift
expect(s.decrypt(cipher)).toBe('hello');
});
test('roundtrip multi-byte', () => {
const s = new MemorySecureStorage();
expect(s.decrypt(s.encrypt('aeoeue-test'))).toBe('aeoeue-test');
});
test('roundtrip empty string', () => {
const s = new MemorySecureStorage();
expect(s.decrypt(s.encrypt(''))).toBe('');
});
test('long token (simuliert OAuth access_token Groesse)', () => {
const s = new MemorySecureStorage();
const token = 'a'.repeat(256);
expect(s.decrypt(s.encrypt(token))).toBe(token);
});
});
describe('createElectronSecureStorage', () => {
test('is exported as function', () => {
expect(typeof createElectronSecureStorage).toBe('function');
});
test('throws useful error if called outside Electron (vitest env)', () => {
// In vitest (Node-only) ist electron entweder nicht installiert oder hat keine
// app-context-Funktionen. Genaues Error-Wording ist nicht stable, aber Aufruf
// muss throwen statt undefined zurueckgeben.
expect(() => createElectronSecureStorage()).toThrow();
});
});