File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use strict' ;
22
33var url = require ( 'url' ) ;
4+ var fs = require ( 'fs' ) ;
45
56//Parse method copied from https://github.com/brianc/node-postgres
67//Copyright (c) 2010-2014 Brian Carlson (brian.m.carlson@gmail.com)
@@ -48,6 +49,22 @@ function parse(str) {
4849 config . ssl = true ;
4950 }
5051
52+ if ( config . sslcert || config . sslkey || config . sslrootcert ) {
53+ config . ssl = { } ;
54+ }
55+
56+ if ( config . sslcert ) {
57+ config . ssl . cert = fs . readFileSync ( config . sslcert ) . toString ( ) ;
58+ }
59+
60+ if ( config . sslkey ) {
61+ config . ssl . key = fs . readFileSync ( config . sslkey ) . toString ( ) ;
62+ }
63+
64+ if ( config . sslrootcert ) {
65+ config . ssl . ca = fs . readFileSync ( config . sslrootcert ) . toString ( ) ;
66+ }
67+
5168 return config ;
5269}
5370
Original file line number Diff line number Diff line change 1+ example ca
Original file line number Diff line number Diff line change 1+ example cert
Original file line number Diff line number Diff line change 1+ example key
Original file line number Diff line number Diff line change @@ -147,6 +147,30 @@ describe('parse', function(){
147147 subject . ssl . should . equal ( true ) ;
148148 } ) ;
149149
150+ it ( 'configuration parameter sslcert=/path/to/cert' , function ( ) {
151+ var connectionString = 'pg:///?sslcert=' + __dirname + '/example.cert' ;
152+ var subject = parse ( connectionString ) ;
153+ subject . ssl . should . eql ( {
154+ cert : 'example cert\n'
155+ } ) ;
156+ } ) ;
157+
158+ it ( 'configuration parameter sslkey=/path/to/key' , function ( ) {
159+ var connectionString = 'pg:///?sslkey=' + __dirname + '/example.key' ;
160+ var subject = parse ( connectionString ) ;
161+ subject . ssl . should . eql ( {
162+ key : 'example key\n'
163+ } ) ;
164+ } ) ;
165+
166+ it ( 'configuration parameter sslrootcert=/path/to/ca' , function ( ) {
167+ var connectionString = 'pg:///?sslrootcert=' + __dirname + '/example.ca' ;
168+ var subject = parse ( connectionString ) ;
169+ subject . ssl . should . eql ( {
170+ ca : 'example ca\n'
171+ } ) ;
172+ } ) ;
173+
150174 it ( 'allow other params like max, ...' , function ( ) {
151175 var subject = parse ( 'pg://myhost/db?max=18&min=4' ) ;
152176 subject . max . should . equal ( '18' ) ;
You can’t perform that action at this time.
0 commit comments