Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.6 KB
Raw Blame
import { CleartextKeyStore } from './cleartext-keystore'

describe('CleartextKeyStore', () => {
    let keyStore: CleartextKeyStore

    beforeEach(() => {
        keyStore = new CleartextKeyStore()
    })

    describe('start', () => {
        it('should complete without error', async () => {
            await expect(keyStore.start()).resolves.toBeUndefined()
        })
    })

    describe('generateKey', () => {
        it('should return empty keys with sessionState cleartext', async () => {
            const result = await keyStore.generateKey('session-123', 1, 30)

            expect(result.plaintextKey).toEqual(Buffer.alloc(0))
            expect(result.encryptedKey).toEqual(Buffer.alloc(0))
            expect(result.sessionState).toBe('cleartext')
        })
    })

    describe('getKey', () => {
        it('should return empty keys with sessionState cleartext', async () => {
            const result = await keyStore.getKey('session-123', 1)

            expect(result.plaintextKey).toEqual(Buffer.alloc(0))
            expect(result.encryptedKey).toEqual(Buffer.alloc(0))
            expect(result.sessionState).toBe('cleartext')
        })
    })

    describe('deleteKey', () => {
        it('should return success with deletedAt timestamp', async () => {
            const result = await keyStore.deleteKey('session-123', 1, '[email protected]')
            expect(result).toEqual({ status: 'deleted', deletedAt: expect.any(Number), deletedBy: '[email protected]' })
        })
    })

    describe('stop', () => {
        it('should complete without error', () => {
            expect(() => keyStore.stop()).not.toThrow()
        })
    })
})