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.2 KB
Raw Blame
import * as envUtils from '~/common/utils/env-utils'

import { CleartextKeyStore } from './cleartext-keystore'
import { DynamoDBKeyStore } from './dynamodb-keystore'
import { getKeyStore } from './index'

jest.mock('~/common/utils/env-utils', () => ({
    ...jest.requireActual('~/common/utils/env-utils'),
    isCloud: jest.fn(),
}))

describe('getKeyStore', () => {
    it('should return DynamoDBKeyStore when running on cloud', () => {
        ;(envUtils.isCloud as jest.Mock).mockReturnValue(true)

        const keyStore = getKeyStore('us-east-1')

        expect(keyStore).toBeInstanceOf(DynamoDBKeyStore)
    })

    it('should return CleartextKeyStore when not running on cloud', () => {
        ;(envUtils.isCloud as jest.Mock).mockReturnValue(false)

        const keyStore = getKeyStore('us-east-1')

        expect(keyStore).toBeInstanceOf(CleartextKeyStore)
    })

    it('should accept custom kmsEndpoint and dynamoDBEndpoint', () => {
        ;(envUtils.isCloud as jest.Mock).mockReturnValue(true)

        const keyStore = getKeyStore('us-east-1', {
            kmsEndpoint: 'http://kms.test',
            dynamoDBEndpoint: 'http://dynamodb.test',
        })

        expect(keyStore).toBeInstanceOf(DynamoDBKeyStore)
    })
})