|
1 | 1 | import { expect } from 'chai';
|
2 | 2 | import { promises as fs } from 'fs';
|
3 | 3 |
|
4 |
| -import { LEGACY_HELLO_COMMAND, MongoClient, type MongoClientOptions } from '../mongodb'; |
| 4 | +import { |
| 5 | + LEGACY_HELLO_COMMAND, |
| 6 | + MongoClient, |
| 7 | + type MongoClientOptions, |
| 8 | + MongoServerSelectionError |
| 9 | +} from '../mongodb'; |
5 | 10 |
|
6 | 11 | const REQUIRED_ENV = ['MONGODB_URI', 'SSL_KEY_FILE', 'SSL_CA_FILE'];
|
7 | 12 |
|
@@ -51,11 +56,13 @@ describe('TLS Support', function () {
|
51 | 56 | expect(client.options).property('tlsCertificateKeyFile', TLS_CERT_KEY_FILE);
|
52 | 57 | expect(client.options).not.have.property('ca');
|
53 | 58 | expect(client.options).not.have.property('key');
|
| 59 | + expect(client.options).not.have.property('cert'); |
54 | 60 |
|
55 | 61 | await client.connect();
|
56 | 62 |
|
57 | 63 | expect(client.options).property('ca').to.exist;
|
58 | 64 | expect(client.options).property('key').to.exist;
|
| 65 | + expect(client.options).property('cert').to.exist; |
59 | 66 | });
|
60 | 67 |
|
61 | 68 | context('when client has been opened and closed more than once', function () {
|
@@ -106,6 +113,44 @@ describe('TLS Support', function () {
|
106 | 113 | });
|
107 | 114 | });
|
108 | 115 | });
|
| 116 | + |
| 117 | + context('when tlsCertificateKeyFile is provided, but tlsCAFile is missing', () => { |
| 118 | + let client: MongoClient; |
| 119 | + beforeEach(() => { |
| 120 | + client = new MongoClient(CONNECTION_STRING, { |
| 121 | + tls: true, |
| 122 | + tlsCertificateKeyFile: TLS_CERT_KEY_FILE, |
| 123 | + serverSelectionTimeoutMS: 5000, |
| 124 | + connectTimeoutMS: 5000 |
| 125 | + }); |
| 126 | + }); |
| 127 | + afterEach(async () => { |
| 128 | + if (client) await client.close(); |
| 129 | + }); |
| 130 | + |
| 131 | + it('throws a MongoServerSelectionError', async () => { |
| 132 | + const err = await client.connect().catch(e => e); |
| 133 | + expect(err).to.be.instanceOf(MongoServerSelectionError); |
| 134 | + }); |
| 135 | + }); |
| 136 | + |
| 137 | + context('when tlsCAFile is provided, but tlsCertificateKeyFile is missing', () => { |
| 138 | + let client: MongoClient; |
| 139 | + beforeEach(() => { |
| 140 | + client = new MongoClient(CONNECTION_STRING, { |
| 141 | + tls: true, |
| 142 | + tlsCAFile: TLS_CA_FILE |
| 143 | + }); |
| 144 | + }); |
| 145 | + afterEach(async () => { |
| 146 | + if (client) await client.close(); |
| 147 | + }); |
| 148 | + |
| 149 | + it('connects without error', async () => { |
| 150 | + const clientOrError = await client.connect().catch(e => e); |
| 151 | + expect(clientOrError).to.be.instanceOf(MongoClient); |
| 152 | + }); |
| 153 | + }); |
109 | 154 | });
|
110 | 155 |
|
111 | 156 | function makeConnectionTest(connectionString: string, clientOptions?: MongoClientOptions) {
|
|
0 commit comments