@@ -72,3 +72,57 @@ test('query with ssl with root cert', async () => {
7272
7373 DEFAULT_POOL_CONFIG . ssl = defaultSsl
7474} )
75+
76+ test ( 'query with invalid space empty encrypted connection string' , async ( ) => {
77+ const res = await app . inject ( {
78+ method : 'POST' ,
79+ path : '/query' ,
80+ headers : {
81+ 'x-connection-encrypted' : CryptoJS . AES . encrypt ( ` ` , CRYPTO_KEY ) . toString ( ) ,
82+ } ,
83+ payload : { query : 'select 1;' } ,
84+ } )
85+ expect ( res . statusCode ) . toBe ( 500 )
86+ expect ( res . json ( ) ) . toMatchInlineSnapshot ( `
87+ {
88+ "error": "failed to get upstream connection details",
89+ }
90+ ` )
91+ } )
92+
93+ test ( 'query with invalid empty encrypted connection string' , async ( ) => {
94+ const res = await app . inject ( {
95+ method : 'POST' ,
96+ path : '/query' ,
97+ headers : {
98+ 'x-connection-encrypted' : CryptoJS . AES . encrypt ( `` , CRYPTO_KEY ) . toString ( ) ,
99+ } ,
100+ payload : { query : 'select 1;' } ,
101+ } )
102+ expect ( res . statusCode ) . toBe ( 500 )
103+ expect ( res . json ( ) ) . toMatchInlineSnapshot ( `
104+ {
105+ "error": "failed to get upstream connection details",
106+ }
107+ ` )
108+ } )
109+
110+ test ( 'query with missing host connection string encrypted connection string' , async ( ) => {
111+ const res = await app . inject ( {
112+ method : 'POST' ,
113+ path : '/query' ,
114+ headers : {
115+ 'x-connection-encrypted' : CryptoJS . AES . encrypt (
116+ `postgres://name:password@:5432/postgres?sslmode=prefer` ,
117+ CRYPTO_KEY
118+ ) . toString ( ) ,
119+ } ,
120+ payload : { query : 'select 1;' } ,
121+ } )
122+ expect ( res . statusCode ) . toBe ( 500 )
123+ expect ( res . json ( ) ) . toMatchInlineSnapshot ( `
124+ {
125+ "error": "failed to process upstream connection details",
126+ }
127+ ` )
128+ } )
0 commit comments