|
1 | 1 | import * as process from 'node:process';
|
| 2 | +import * as tls from 'node:tls'; |
2 | 3 |
|
3 | 4 | import { expect } from 'chai';
|
4 | 5 | import { promises as fs } from 'fs';
|
| 6 | +import * as sinon from 'sinon'; |
5 | 7 |
|
6 | 8 | import {
|
7 | 9 | LEGACY_HELLO_COMMAND,
|
@@ -61,6 +63,63 @@ describe('TLS Support', function () {
|
61 | 63 | });
|
62 | 64 |
|
63 | 65 | context('when tls filepaths have length > 0', () => {
|
| 66 | + context('when auto family options are not set', function () { |
| 67 | + let tlsSpy; |
| 68 | + |
| 69 | + afterEach(function () { |
| 70 | + sinon.restore(); |
| 71 | + }); |
| 72 | + |
| 73 | + beforeEach(function () { |
| 74 | + client = new MongoClient(CONNECTION_STRING, tlsSettings); |
| 75 | + tlsSpy = sinon.spy(tls, 'connect'); |
| 76 | + }); |
| 77 | + |
| 78 | + it('sets the default options', async function () { |
| 79 | + await client.connect(); |
| 80 | + expect(tlsSpy).to.have.been.calledWith({ |
| 81 | + autoSelectFamily: true, |
| 82 | + host: 'localhost', |
| 83 | + port: 27017, |
| 84 | + servername: 'localhost', |
| 85 | + ca: sinon.match.defined, |
| 86 | + cert: sinon.match.defined, |
| 87 | + key: sinon.match.defined |
| 88 | + }); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + context('when auto family options are set', function () { |
| 93 | + let tlsSpy; |
| 94 | + |
| 95 | + afterEach(function () { |
| 96 | + sinon.restore(); |
| 97 | + }); |
| 98 | + |
| 99 | + beforeEach(function () { |
| 100 | + client = new MongoClient(CONNECTION_STRING, { |
| 101 | + ...tlsSettings, |
| 102 | + autoSelectFamily: false, |
| 103 | + autoSelectFamilyAttemptTimeout: 100 |
| 104 | + }); |
| 105 | + tlsSpy = sinon.spy(tls, 'connect'); |
| 106 | + }); |
| 107 | + |
| 108 | + it('sets the provided options', async function () { |
| 109 | + await client.connect(); |
| 110 | + expect(tlsSpy).to.have.been.calledWith({ |
| 111 | + autoSelectFamily: false, |
| 112 | + autoSelectFamilyAttemptTimeout: 100, |
| 113 | + host: 'localhost', |
| 114 | + port: 27017, |
| 115 | + servername: 'localhost', |
| 116 | + ca: sinon.match.defined, |
| 117 | + cert: sinon.match.defined, |
| 118 | + key: sinon.match.defined |
| 119 | + }); |
| 120 | + }); |
| 121 | + }); |
| 122 | + |
64 | 123 | context('when connection will succeed', () => {
|
65 | 124 | beforeEach(async () => {
|
66 | 125 | client = new MongoClient(CONNECTION_STRING, tlsSettings);
|
|
0 commit comments