Skip to content

Commit 15fe9aa

Browse files
authored
test(NODE-3763): expand tls/ssl options parsing tests (#3057)
1 parent 0a830e2 commit 15fe9aa

File tree

1 file changed

+88
-7
lines changed

1 file changed

+88
-7
lines changed

test/unit/connection_string.test.js

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,94 @@ describe('Connection String', function () {
116116
expect(options.replicaSet).to.equal('123abc');
117117
});
118118

119+
context('when both tls and ssl options are provided', function () {
120+
context('when the options are provided in the URI', function () {
121+
context('when the options are equal', function () {
122+
context('when both options are true', function () {
123+
const options = parseOptions('mongodb://localhost/?tls=true&ssl=true');
124+
125+
it('sets the tls option', function () {
126+
expect(options.tls).to.be.true;
127+
});
128+
129+
it('does not set the ssl option', function () {
130+
expect(options.ssl).to.be.undefined;
131+
});
132+
});
133+
134+
context('when both options are false', function () {
135+
const options = parseOptions('mongodb://localhost/?tls=false&ssl=false');
136+
137+
it('sets the tls option', function () {
138+
expect(options.tls).to.be.false;
139+
});
140+
141+
it('does not set the ssl option', function () {
142+
expect(options.ssl).to.be.undefined;
143+
});
144+
});
145+
});
146+
147+
context('when the options are not equal', function () {
148+
it('raises an error', function () {
149+
expect(() => {
150+
parseOptions('mongodb://localhost/?tls=true&ssl=false');
151+
}).to.throw(MongoParseError, 'All values of tls/ssl must be the same.');
152+
});
153+
});
154+
});
155+
156+
context('when the options are provided in the options', function () {
157+
context('when the options are equal', function () {
158+
context('when both options are true', function () {
159+
const options = parseOptions('mongodb://localhost/', { tls: true, ssl: true });
160+
161+
it('sets the tls option', function () {
162+
expect(options.tls).to.be.true;
163+
});
164+
165+
it('does not set the ssl option', function () {
166+
expect(options.ssl).to.be.undefined;
167+
});
168+
});
169+
170+
context('when both options are false', function () {
171+
context('when the URI is an SRV URI', function () {
172+
const options = parseOptions('mongodb+srv://localhost/', { tls: false, ssl: false });
173+
174+
it('overrides the tls option', function () {
175+
expect(options.tls).to.be.false;
176+
});
177+
178+
it('does not set the ssl option', function () {
179+
expect(options.ssl).to.be.undefined;
180+
});
181+
});
182+
183+
context('when the URI is not SRV', function () {
184+
const options = parseOptions('mongodb://localhost/', { tls: false, ssl: false });
185+
186+
it('sets the tls option', function () {
187+
expect(options.tls).to.be.false;
188+
});
189+
190+
it('does not set the ssl option', function () {
191+
expect(options.ssl).to.be.undefined;
192+
});
193+
});
194+
});
195+
});
196+
197+
context('when the options are not equal', function () {
198+
it('raises an error', function () {
199+
expect(() => {
200+
parseOptions('mongodb://localhost/', { tls: true, ssl: false });
201+
}).to.throw(MongoParseError, 'All values of tls/ssl must be the same.');
202+
});
203+
});
204+
});
205+
});
206+
119207
describe('validation', function () {
120208
it('should validate compressors options', function () {
121209
expect(() => parseOptions('mongodb://localhost/?compressors=bunnies')).to.throw(
@@ -137,13 +225,6 @@ describe('Connection String', function () {
137225
'Invalid read preference mode "llamasPreferred"'
138226
);
139227
});
140-
141-
it('should validate non-equal tls values', function () {
142-
expect(() => parseOptions('mongodb://localhost/?tls=true&tls=false')).to.throw(
143-
MongoParseError,
144-
'All values of tls/ssl must be the same.'
145-
);
146-
});
147228
});
148229

149230
describe('spec tests', function () {

0 commit comments

Comments
 (0)