Skip to content

Commit 018d041

Browse files
committed
test(NODE-5548): add failure tests
1 parent d166fb6 commit 018d041

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

test/manual/tls_support.test.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ describe('TLS Support', function () {
5151
expect(client.options).property('tlsCertificateKeyFile', TLS_CERT_KEY_FILE);
5252
expect(client.options).not.have.property('ca');
5353
expect(client.options).not.have.property('key');
54-
expect(client.options).not.have.property('cert');
5554

5655
await client.connect();
5756

5857
expect(client.options).property('ca').to.exist;
5958
expect(client.options).property('key').to.exist;
60-
expect(client.options).property('cert').to.exist;
6159
});
6260

6361
context('when client has been opened and closed more than once', function () {
@@ -108,6 +106,42 @@ describe('TLS Support', function () {
108106
});
109107
});
110108
});
109+
110+
context('when tlsCertificateKeyFile is provided, but tlsCAFile is missing', () => {
111+
let client: MongoClient;
112+
beforeEach(() => {
113+
client = new MongoClient(CONNECTION_STRING, {
114+
tls: true,
115+
tlsCertificateKeyFile: TLS_CERT_KEY_FILE
116+
});
117+
});
118+
afterEach(async () => {
119+
if (client) await client.close();
120+
});
121+
122+
it('throws an error', async () => {
123+
const err = await client.connect().catch(e => e);
124+
expect(err).to.be.instanceOf(Error);
125+
});
126+
});
127+
128+
context('when tlsCAFile is provided, but tlsCertificateKeyFile is missing', () => {
129+
let client: MongoClient;
130+
beforeEach(() => {
131+
client = new MongoClient(CONNECTION_STRING, {
132+
tls: true,
133+
tlsCAFile: TLS_CA_FILE
134+
});
135+
});
136+
afterEach(async () => {
137+
if (client) await client.close();
138+
});
139+
140+
it('throws an error', async () => {
141+
const err = await client.connect().catch(e => e);
142+
expect(err).to.be.instanceOf(Error);
143+
});
144+
});
111145
});
112146

113147
function makeConnectionTest(connectionString: string, clientOptions?: MongoClientOptions) {

0 commit comments

Comments
 (0)