1+ import 'should' ;
12import { config , isEnclavedConfig , TlsMode } from '../config' ;
23
34describe ( 'Configuration' , ( ) => {
@@ -6,23 +7,26 @@ describe('Configuration', () => {
67 const mockTlsCert = '-----BEGIN CERTIFICATE-----\nMOCK_CERT\n-----END CERTIFICATE-----' ;
78
89 beforeEach ( ( ) => {
9- jest . resetModules ( ) ;
1010 process . env = { ...originalEnv } ;
1111 // Clear TLS-related environment variables
1212 delete process . env . TLS_MODE ;
1313 } ) ;
1414
15- afterAll ( ( ) => {
15+ after ( ( ) => {
1616 process . env = originalEnv ;
1717 } ) ;
1818
1919 it ( 'should throw error when APP_MODE is not set' , ( ) => {
20- expect ( ( ) => config ( ) ) . toThrow ( 'APP_MODE environment variable is required' ) ;
20+ ( ( ) => config ( ) ) . should . throw (
21+ 'APP_MODE environment variable is required. Set APP_MODE to either "enclaved" or "master-express"' ,
22+ ) ;
2123 } ) ;
2224
2325 it ( 'should throw error when APP_MODE is invalid' , ( ) => {
2426 process . env . APP_MODE = 'invalid' ;
25- expect ( ( ) => config ( ) ) . toThrow ( 'Invalid APP_MODE: invalid' ) ;
27+ ( ( ) => config ( ) ) . should . throw (
28+ 'Invalid APP_MODE: invalid. Must be either "enclaved" or "master-express"' ,
29+ ) ;
2630 } ) ;
2731
2832 describe ( 'Enclaved Mode' , ( ) => {
@@ -36,64 +40,66 @@ describe('Configuration', () => {
3640
3741 it ( 'should use default configuration when no environment variables are set' , ( ) => {
3842 const cfg = config ( ) ;
39- expect ( isEnclavedConfig ( cfg ) ) . toBe ( true ) ;
43+ isEnclavedConfig ( cfg ) . should . be . true ( ) ;
4044 if ( isEnclavedConfig ( cfg ) ) {
41- expect ( cfg . port ) . toBe ( 3080 ) ;
42- expect ( cfg . bind ) . toBe ( 'localhost' ) ;
43- expect ( cfg . tlsMode ) . toBe ( TlsMode . MTLS ) ;
44- expect ( cfg . timeout ) . toBe ( 305 * 1000 ) ;
45- expect ( cfg . kmsUrl ) . toBe ( 'http://localhost:3000' ) ;
46- expect ( cfg . tlsKey ) . toBe ( mockTlsKey ) ;
47- expect ( cfg . tlsCert ) . toBe ( mockTlsCert ) ;
45+ cfg . port . should . equal ( 3080 ) ;
46+ cfg . bind . should . equal ( 'localhost' ) ;
47+ cfg . tlsMode . should . equal ( TlsMode . MTLS ) ;
48+ cfg . timeout . should . equal ( 305 * 1000 ) ;
49+ cfg . kmsUrl . should . equal ( 'http://localhost:3000' ) ;
50+ cfg . tlsKey ! . should . equal ( mockTlsKey ) ;
51+ cfg . tlsCert ! . should . equal ( mockTlsCert ) ;
4852 }
4953 } ) ;
5054
5155 it ( 'should read port from environment variable' , ( ) => {
5256 process . env . ENCLAVED_EXPRESS_PORT = '4000' ;
5357 const cfg = config ( ) ;
54- expect ( isEnclavedConfig ( cfg ) ) . toBe ( true ) ;
58+ isEnclavedConfig ( cfg ) . should . be . true ( ) ;
5559 if ( isEnclavedConfig ( cfg ) ) {
56- expect ( cfg . port ) . toBe ( 4000 ) ;
57- expect ( cfg . kmsUrl ) . toBe ( 'http://localhost:3000' ) ;
58- expect ( cfg . tlsKey ) . toBe ( mockTlsKey ) ;
59- expect ( cfg . tlsCert ) . toBe ( mockTlsCert ) ;
60+ cfg . port . should . equal ( 4000 ) ;
61+ cfg . kmsUrl . should . equal ( 'http://localhost:3000' ) ;
62+ cfg . tlsKey ! . should . equal ( mockTlsKey ) ;
63+ cfg . tlsCert ! . should . equal ( mockTlsCert ) ;
6064 }
6165 } ) ;
6266
6367 it ( 'should read TLS mode from environment variables' , ( ) => {
6468 // Test with TLS disabled
6569 process . env . TLS_MODE = 'disabled' ;
6670 let cfg = config ( ) ;
67- expect ( isEnclavedConfig ( cfg ) ) . toBe ( true ) ;
71+ isEnclavedConfig ( cfg ) . should . be . true ( ) ;
6872 if ( isEnclavedConfig ( cfg ) ) {
69- expect ( cfg . tlsMode ) . toBe ( TlsMode . DISABLED ) ;
70- expect ( cfg . kmsUrl ) . toBe ( 'http://localhost:3000' ) ;
73+ cfg . tlsMode . should . equal ( TlsMode . DISABLED ) ;
74+ cfg . kmsUrl . should . equal ( 'http://localhost:3000' ) ;
7175 }
7276
7377 // Test with mTLS explicitly enabled
7478 process . env . TLS_MODE = 'mtls' ;
7579 cfg = config ( ) ;
76- expect ( isEnclavedConfig ( cfg ) ) . toBe ( true ) ;
80+ isEnclavedConfig ( cfg ) . should . be . true ( ) ;
7781 if ( isEnclavedConfig ( cfg ) ) {
78- expect ( cfg . tlsMode ) . toBe ( TlsMode . MTLS ) ;
79- expect ( cfg . kmsUrl ) . toBe ( 'http://localhost:3000' ) ;
80- expect ( cfg . tlsKey ) . toBe ( mockTlsKey ) ;
81- expect ( cfg . tlsCert ) . toBe ( mockTlsCert ) ;
82+ cfg . tlsMode . should . equal ( TlsMode . MTLS ) ;
83+ cfg . kmsUrl . should . equal ( 'http://localhost:3000' ) ;
84+ cfg . tlsKey ! . should . equal ( mockTlsKey ) ;
85+ cfg . tlsCert ! . should . equal ( mockTlsCert ) ;
8286 }
8387
8488 // Test with invalid TLS mode
8589 process . env . TLS_MODE = 'invalid' ;
86- expect ( ( ) => config ( ) ) . toThrow ( 'Invalid TLS_MODE: invalid' ) ;
90+ ( ( ) => config ( ) ) . should . throw (
91+ 'Invalid TLS_MODE: invalid. Must be either "disabled" or "mtls"' ,
92+ ) ;
8793
8894 // Test with no TLS mode (should default to MTLS)
8995 delete process . env . TLS_MODE ;
9096 cfg = config ( ) ;
91- expect ( isEnclavedConfig ( cfg ) ) . toBe ( true ) ;
97+ isEnclavedConfig ( cfg ) . should . be . true ( ) ;
9298 if ( isEnclavedConfig ( cfg ) ) {
93- expect ( cfg . tlsMode ) . toBe ( TlsMode . MTLS ) ;
94- expect ( cfg . kmsUrl ) . toBe ( 'http://localhost:3000' ) ;
95- expect ( cfg . tlsKey ) . toBe ( mockTlsKey ) ;
96- expect ( cfg . tlsCert ) . toBe ( mockTlsCert ) ;
99+ cfg . tlsMode . should . equal ( TlsMode . MTLS ) ;
100+ cfg . kmsUrl . should . equal ( 'http://localhost:3000' ) ;
101+ cfg . tlsKey ! . should . equal ( mockTlsKey ) ;
102+ cfg . tlsCert ! . should . equal ( mockTlsCert ) ;
97103 }
98104 } ) ;
99105
@@ -103,13 +109,13 @@ describe('Configuration', () => {
103109 process . env . MTLS_ALLOWED_CLIENT_FINGERPRINTS = 'ABC123,DEF456' ;
104110
105111 const cfg = config ( ) ;
106- expect ( isEnclavedConfig ( cfg ) ) . toBe ( true ) ;
112+ isEnclavedConfig ( cfg ) . should . be . true ( ) ;
107113 if ( isEnclavedConfig ( cfg ) ) {
108- expect ( cfg . mtlsRequestCert ) . toBe ( true ) ;
109- expect ( cfg . mtlsAllowedClientFingerprints ) . toEqual ( [ 'ABC123' , 'DEF456' ] ) ;
110- expect ( cfg . kmsUrl ) . toBe ( 'http://localhost:3000' ) ;
111- expect ( cfg . tlsKey ) . toBe ( mockTlsKey ) ;
112- expect ( cfg . tlsCert ) . toBe ( mockTlsCert ) ;
114+ cfg . mtlsRequestCert ! . should . be . true ( ) ;
115+ cfg . mtlsAllowedClientFingerprints ! . should . deepEqual ( [ 'ABC123' , 'DEF456' ] ) ;
116+ cfg . kmsUrl . should . equal ( 'http://localhost:3000' ) ;
117+ cfg . tlsKey ! . should . equal ( mockTlsKey ) ;
118+ cfg . tlsCert ! . should . equal ( mockTlsCert ) ;
113119 }
114120 } ) ;
115121 } ) ;
0 commit comments