Skip to content

Commit b25822a

Browse files
committed
test: check when crl loaded
1 parent ca1efd8 commit b25822a

File tree

1 file changed

+45
-22
lines changed

1 file changed

+45
-22
lines changed

test/manual/tls_support.test.ts

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,59 @@ describe('TLS Support', function () {
4848
});
4949

5050
context('when tls filepaths have length > 0', () => {
51-
beforeEach(async () => {
52-
client = new MongoClient(CONNECTION_STRING, tlsSettings);
53-
});
51+
context('when connection will succeed', () => {
52+
beforeEach(async () => {
53+
client = new MongoClient(CONNECTION_STRING, tlsSettings);
54+
});
55+
56+
it('should read in files async at connect time', async () => {
57+
expect(client.options).property('tlsCAFile', TLS_CA_FILE);
58+
expect(client.options).property('tlsCertificateKeyFile', TLS_CERT_KEY_FILE);
59+
expect(client.options).not.have.property('ca');
60+
expect(client.options).not.have.property('key');
61+
expect(client.options).not.have.property('cert');
62+
63+
await client.connect();
64+
65+
expect(client.options).property('ca').to.exist;
66+
expect(client.options).property('key').to.exist;
67+
expect(client.options).property('cert').to.exist;
68+
});
69+
70+
context('when client has been opened and closed more than once', function () {
71+
it('should only read files once', async () => {
72+
await client.connect();
73+
await client.close();
5474

55-
it('should read in files async at connect time', async () => {
56-
expect(client.options).property('tlsCAFile', TLS_CA_FILE);
57-
expect(client.options).property('tlsCertificateKeyFile', TLS_CERT_KEY_FILE);
58-
expect(client.options).not.have.property('ca');
59-
expect(client.options).not.have.property('key');
60-
expect(client.options).not.have.property('cert');
75+
const caFileAccessTime = (await fs.stat(TLS_CA_FILE)).atime;
76+
const certKeyFileAccessTime = (await fs.stat(TLS_CERT_KEY_FILE)).atime;
6177

62-
await client.connect();
78+
await client.connect();
6379

64-
expect(client.options).property('ca').to.exist;
65-
expect(client.options).property('key').to.exist;
66-
expect(client.options).property('cert').to.exist;
80+
expect((await fs.stat(TLS_CA_FILE)).atime).to.deep.equal(caFileAccessTime);
81+
expect((await fs.stat(TLS_CERT_KEY_FILE)).atime).to.deep.equal(certKeyFileAccessTime);
82+
});
83+
});
6784
});
6885

69-
context('when client has been opened and closed more than once', function () {
70-
it('should only read files once', async () => {
71-
await client.connect();
72-
await client.close();
86+
context('when the connection will fail', () => {
87+
beforeEach(async () => {
88+
client = new MongoClient(CONNECTION_STRING, {
89+
tls: true,
90+
tlsCRLFile: TLS_CRL_FILE,
91+
serverSelectionTimeoutMS: 5000,
92+
connectTimeoutMS: 5000
93+
});
94+
});
7395

74-
const caFileAccessTime = (await fs.stat(TLS_CA_FILE)).atime;
75-
const certKeyFileAccessTime = (await fs.stat(TLS_CERT_KEY_FILE)).atime;
96+
it('should read in files async at connect time', async () => {
97+
expect(client.options).property('tlsCRLFile', TLS_CRL_FILE);
98+
expect(client.options).not.have.property('crl');
7699

77-
await client.connect();
100+
const err = await client.connect().catch(e => e);
78101

79-
expect((await fs.stat(TLS_CA_FILE)).atime).to.deep.equal(caFileAccessTime);
80-
expect((await fs.stat(TLS_CERT_KEY_FILE)).atime).to.deep.equal(certKeyFileAccessTime);
102+
expect(err).to.be.instanceof(Error);
103+
expect(client.options).property('crl').to.exist;
81104
});
82105
});
83106
});

0 commit comments

Comments
 (0)