2 SESSION_DIGEST_VERSION,
3 SESSION_INTEGRITY_KEYS_V1,
5 getSessionDigestVersion,
6 getSessionIntegrityKeys,
8 import { LockMode } from './lock/types';
10 const MOCK_SESSION = {
13 lockMode: LockMode.PASSWORD,
15 offlineVerifier: 'abc',
24 describe('Session integrity', () => {
25 describe('`getSessionIntegrityKeys`', () => {
26 it('should return correct keys for version 1', () => {
27 expect(getSessionIntegrityKeys(1)).toEqual(SESSION_INTEGRITY_KEYS_V1);
30 it('should return an empty array for unknown versions', () => {
31 expect(getSessionIntegrityKeys(-1)).toEqual([]);
32 expect(getSessionIntegrityKeys(999)).toEqual([]);
36 describe('`getSessionDigestVersion`', () => {
37 it('should extract the correct version from a valid digest', () => {
38 expect(getSessionDigestVersion('2.7f83b1657ff1fc53b92dc')).toBe(2);
39 expect(getSessionDigestVersion('24.18148a1d65dfc2d4b1k9d')).toBe(24);
40 expect(getSessionDigestVersion('004.a3d677284addd200126d9')).toBe(4);
43 it('should return `SESSION_DIGEST_VERSION` for invalid digests', () => {
44 expect(getSessionDigestVersion('7f83b1657ff1fc53b92dc')).toBe(SESSION_DIGEST_VERSION);
45 expect(getSessionDigestVersion('notanumber.18148a1d65dfc2d4b1k9d')).toBe(SESSION_DIGEST_VERSION);
49 describe('`digestSession`', () => {
50 it('should generate a correct digest', async () => {
51 const digest = '1.rpaFGlfkJtY27MfCzrnooGceeEfun+khBXvWr4U0hWM=';
52 const result = await digestSession(MOCK_SESSION, 1);
53 expect(result).toEqual(digest);
56 it('should generate different digests for different sessions', async () => {
57 const sessionA = MOCK_SESSION;
58 const digestA = await digestSession(sessionA, 1);
60 const sessionB = { ...MOCK_SESSION, LocalID: 42 };
61 const digestB = await digestSession(sessionB, 1);
63 expect(digestA).not.toBe(digestB);