File tree 5 files changed +44
-0
lines changed
5 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
var url = require ( 'url' ) ;
4
+ var fs = require ( 'fs' ) ;
4
5
5
6
//Parse method copied from https://github.com/brianc/node-postgres
6
7
//Copyright (c) 2010-2014 Brian Carlson (brian.m.carlson@gmail.com)
@@ -48,6 +49,22 @@ function parse(str) {
48
49
config . ssl = true ;
49
50
}
50
51
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
+
51
68
return config ;
52
69
}
53
70
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(){
147
147
subject . ssl . should . equal ( true ) ;
148
148
} ) ;
149
149
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
+
150
174
it ( 'allow other params like max, ...' , function ( ) {
151
175
var subject = parse ( 'pg://myhost/db?max=18&min=4' ) ;
152
176
subject . max . should . equal ( '18' ) ;
You can’t perform that action at this time.
0 commit comments