File tree 2 files changed +5
-4
lines changed
2 files changed +5
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { logger } from '@internal/monitoring'
2
+ import { ConnectionOptions } from 'tls'
2
3
3
4
export function getSslSettings ( {
4
5
connectionString,
5
6
databaseSSLRootCert,
6
7
} : {
7
8
connectionString : string
8
9
databaseSSLRootCert : string | undefined
9
- } ) : { ca : string } | undefined {
10
+ } ) : ConnectionOptions | undefined {
10
11
if ( ! databaseSSLRootCert ) return undefined
11
12
12
13
try {
@@ -15,7 +16,7 @@ export function getSslSettings({
15
16
// in case the hostname is an IP address
16
17
const url = new URL ( connectionString )
17
18
if ( url . hostname && isIpAddress ( url . hostname ) ) {
18
- return undefined
19
+ return { ca : databaseSSLRootCert , rejectUnauthorized : false }
19
20
}
20
21
} catch ( err ) {
21
22
// ignore to ensure this never breaks the connection in case of an invalid URL
Original file line number Diff line number Diff line change @@ -23,13 +23,13 @@ describe('database utils', () => {
23
23
) . toBeUndefined ( )
24
24
} )
25
25
26
- test ( 'should return no SSL settings if hostname is an IP address' , ( ) => {
26
+ test ( 'should return SSL settings if hostname is an IP address' , ( ) => {
27
27
expect (
28
28
getSslSettings ( {
29
29
connectionString :
'postgres://foo:[email protected] :5432/postgres' ,
30
30
databaseSSLRootCert : '<cert>' ,
31
31
} )
32
- ) . toBeUndefined ( )
32
+ ) . toStrictEqual ( { ca : '<cert>' , rejectUnauthorized : false } )
33
33
} )
34
34
35
35
test ( 'should return SSL settings if hostname is not an IP address' , ( ) => {
You can’t perform that action at this time.
0 commit comments