import { productionConfigProblems } from './production-checks'; describe('productionConfigProblems', () => { const A = 'a'.repeat(40); const C = 'c'.repeat(40); const good = { NODE_ENV: 'production', JWT_SECRET: A, JWT_CUSTOMER_SECRET: C, CORS_ORIGINS: 'https://adm.example.ir, https://app.example.ir/', }; it('a complete production config passes', () => { expect(productionConfigProblems(good)).toEqual([]); }); it('checks nothing outside production', () => { expect(productionConfigProblems({ NODE_ENV: 'development' })).toEqual([]); }); it('refuses the fixed test login code (REL-01)', () => { expect(productionConfigProblems({ ...good, OTP_MASTER_CODE: '1234' })).toHaveLength(1); // explicit opt-in for a test server built from the production image expect( productionConfigProblems({ ...good, OTP_MASTER_CODE: '1234', TEST_SERVER_ALLOW_MASTER_CODE: 'yes' }), ).toEqual([]); }); it('requires a separate customer token key (REL-03)', () => { expect(productionConfigProblems({ ...good, JWT_CUSTOMER_SECRET: '' })).toHaveLength(1); expect(productionConfigProblems({ ...good, JWT_CUSTOMER_SECRET: A })).toHaveLength(1); expect(productionConfigProblems({ ...good, JWT_CUSTOMER_SECRET: 'short' })).toHaveLength(1); }); it('requires a strong admin key (SEC-04)', () => { expect(productionConfigProblems({ ...good, JWT_SECRET: undefined })).toHaveLength(1); expect(productionConfigProblems({ ...good, JWT_SECRET: 'dev-only-insecure-secret' })).toHaveLength(1); }); it('requires an explicit list of allowed origins (SEC-04)', () => { expect(productionConfigProblems({ ...good, CORS_ORIGINS: '' })).toHaveLength(1); expect(productionConfigProblems({ ...good, CORS_ORIGINS: '*' })).toHaveLength(1); expect(productionConfigProblems({ ...good, CORS_ORIGINS: 'adm.example.ir' })).toHaveLength(1); }); it('lists every problem at once', () => { expect(productionConfigProblems({ NODE_ENV: 'production', OTP_MASTER_CODE: '1234' })).toHaveLength(4); }); });