|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 | 3 | var chai = require('chai')
|
| 4 | +var expect = chai.expect |
4 | 5 | chai.should()
|
5 | 6 |
|
6 | 7 | var parse = require('../').parse
|
@@ -287,6 +288,114 @@ describe('parse', function () {
|
287 | 288 | })
|
288 | 289 | })
|
289 | 290 |
|
| 291 | + it('configuration parameter sslmode=disable with uselibpqcompat query param', function () { |
| 292 | + var connectionString = 'pg:///?sslmode=disable&uselibpqcompat=true' |
| 293 | + var subject = parse(connectionString) |
| 294 | + subject.ssl.should.eql(false) |
| 295 | + }) |
| 296 | + |
| 297 | + it('configuration parameter sslmode=prefer with uselibpqcompat query param', function () { |
| 298 | + var connectionString = 'pg:///?sslmode=prefer&uselibpqcompat=true' |
| 299 | + var subject = parse(connectionString) |
| 300 | + subject.ssl.should.eql({ |
| 301 | + rejectUnauthorized: false, |
| 302 | + }) |
| 303 | + }) |
| 304 | + |
| 305 | + it('configuration parameter sslmode=require with uselibpqcompat query param', function () { |
| 306 | + var connectionString = 'pg:///?sslmode=require&uselibpqcompat=true' |
| 307 | + var subject = parse(connectionString) |
| 308 | + subject.ssl.should.eql({ |
| 309 | + rejectUnauthorized: false, |
| 310 | + }) |
| 311 | + }) |
| 312 | + |
| 313 | + it('configuration parameter sslmode=verify-ca with uselibpqcompat query param', function () { |
| 314 | + var connectionString = 'pg:///?sslmode=verify-ca&uselibpqcompat=true' |
| 315 | + expect(function () { |
| 316 | + parse(connectionString) |
| 317 | + }).to.throw() |
| 318 | + }) |
| 319 | + |
| 320 | + it('configuration parameter sslmode=verify-ca and sslrootcert with uselibpqcompat query param', function () { |
| 321 | + var connectionString = 'pg:///?sslmode=verify-ca&uselibpqcompat=true&sslrootcert=' + __dirname + '/example.ca' |
| 322 | + var subject = parse(connectionString) |
| 323 | + subject.ssl.should.have.property('checkServerIdentity').that.is.a('function') |
| 324 | + expect(subject.ssl.checkServerIdentity()).be.undefined |
| 325 | + }) |
| 326 | + |
| 327 | + it('configuration parameter sslmode=verify-full with uselibpqcompat query param', function () { |
| 328 | + var connectionString = 'pg:///?sslmode=verify-full&uselibpqcompat=true' |
| 329 | + var subject = parse(connectionString) |
| 330 | + subject.ssl.should.eql({}) |
| 331 | + }) |
| 332 | + |
| 333 | + it('configuration parameter ssl=true and sslmode=require still work with sslrootcert=/path/to/ca with uselibpqcompat query param', function () { |
| 334 | + var connectionString = |
| 335 | + 'pg:///?ssl=true&sslrootcert=' + __dirname + '/example.ca&sslmode=require&uselibpqcompat=true' |
| 336 | + var subject = parse(connectionString) |
| 337 | + subject.ssl.should.have.property('ca', 'example ca\n') |
| 338 | + subject.ssl.should.have.property('checkServerIdentity').that.is.a('function') |
| 339 | + expect(subject.ssl.checkServerIdentity()).be.undefined |
| 340 | + }) |
| 341 | + |
| 342 | + it('configuration parameter sslmode=disable with useLibpqCompat option', function () { |
| 343 | + var connectionString = 'pg:///?sslmode=disable' |
| 344 | + var subject = parse(connectionString, { useLibpqCompat: true }) |
| 345 | + subject.ssl.should.eql(false) |
| 346 | + }) |
| 347 | + |
| 348 | + it('configuration parameter sslmode=prefer with useLibpqCompat option', function () { |
| 349 | + var connectionString = 'pg:///?sslmode=prefer' |
| 350 | + var subject = parse(connectionString, { useLibpqCompat: true }) |
| 351 | + subject.ssl.should.eql({ |
| 352 | + rejectUnauthorized: false, |
| 353 | + }) |
| 354 | + }) |
| 355 | + |
| 356 | + it('configuration parameter sslmode=require with useLibpqCompat option', function () { |
| 357 | + var connectionString = 'pg:///?sslmode=require' |
| 358 | + var subject = parse(connectionString, { useLibpqCompat: true }) |
| 359 | + subject.ssl.should.eql({ |
| 360 | + rejectUnauthorized: false, |
| 361 | + }) |
| 362 | + }) |
| 363 | + |
| 364 | + it('configuration parameter sslmode=verify-ca with useLibpqCompat option', function () { |
| 365 | + var connectionString = 'pg:///?sslmode=verify-ca' |
| 366 | + expect(function () { |
| 367 | + parse(connectionString, { useLibpqCompat: true }) |
| 368 | + }).to.throw() |
| 369 | + }) |
| 370 | + |
| 371 | + it('configuration parameter sslmode=verify-ca and sslrootcert with useLibpqCompat option', function () { |
| 372 | + var connectionString = 'pg:///?sslmode=verify-ca&sslrootcert=' + __dirname + '/example.ca' |
| 373 | + var subject = parse(connectionString, { useLibpqCompat: true }) |
| 374 | + subject.ssl.should.have.property('checkServerIdentity').that.is.a('function') |
| 375 | + expect(subject.ssl.checkServerIdentity()).be.undefined |
| 376 | + }) |
| 377 | + |
| 378 | + it('configuration parameter sslmode=verify-full with useLibpqCompat option', function () { |
| 379 | + var connectionString = 'pg:///?sslmode=verify-full' |
| 380 | + var subject = parse(connectionString, { useLibpqCompat: true }) |
| 381 | + subject.ssl.should.eql({}) |
| 382 | + }) |
| 383 | + |
| 384 | + it('configuration parameter ssl=true and sslmode=require still work with sslrootcert=/path/to/ca with useLibpqCompat option', function () { |
| 385 | + var connectionString = 'pg:///?ssl=true&sslrootcert=' + __dirname + '/example.ca&sslmode=require' |
| 386 | + var subject = parse(connectionString, { useLibpqCompat: true }) |
| 387 | + subject.ssl.should.have.property('ca', 'example ca\n') |
| 388 | + subject.ssl.should.have.property('checkServerIdentity').that.is.a('function') |
| 389 | + expect(subject.ssl.checkServerIdentity()).be.undefined |
| 390 | + }) |
| 391 | + |
| 392 | + it('does not allow sslcompat query parameter and useLibpqCompat option at the same time', function () { |
| 393 | + var connectionString = 'pg:///?uselibpqcompat=true' |
| 394 | + expect(function () { |
| 395 | + parse(connectionString, { useLibpqCompat: true }) |
| 396 | + }).to.throw() |
| 397 | + }) |
| 398 | + |
290 | 399 | it('allow other params like max, ...', function () {
|
291 | 400 | var subject = parse('pg://myhost/db?max=18&min=4')
|
292 | 401 | subject.max.should.equal('18')
|
|
0 commit comments