Skip to content

Commit 3ade98f

Browse files
committed
test: fix gssapi tests
1 parent e024ec6 commit 3ade98f

2 files changed

Lines changed: 49 additions & 44 deletions

File tree

test/unit/cmap/auth/gssapi.test.ts

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import {
1010

1111
describe('GSSAPI', () => {
1212
let lookupSpy;
13-
let resolvePtrSpy;
14-
let resolveCnameSpy;
13+
let resolveSpy;
1514

1615
beforeEach(() => {
1716
lookupSpy = sinon.spy(dns, 'lookup');
18-
resolvePtrSpy = sinon.spy(dns, 'resolvePtr');
19-
resolveCnameSpy = sinon.spy(dns, 'resolveCname');
17+
resolveSpy = sinon.spy(dns, 'resolve');
2018
});
2119

2220
afterEach(() => {
@@ -34,8 +32,8 @@ describe('GSSAPI', () => {
3432
});
3533
expect(host).to.equal(hostName);
3634
expect(dns.lookup).to.not.be.called;
37-
expect(dns.resolvePtr).to.not.be.called;
38-
expect(dns.resolveCname).to.not.be.called;
35+
expect(dns.resolve.withArgs(sinon.match.any, 'PTR')).to.not.be.called;
36+
expect(dns.resolve.withArgs(sinon.match.any, 'CNAME')).to.not.be.called;
3937
});
4038
});
4139
}
@@ -44,8 +42,8 @@ describe('GSSAPI', () => {
4442
const resolved = '10gen.cc';
4543

4644
beforeEach(() => {
47-
resolveCnameSpy.restore();
48-
sinon.stub(dns, 'resolveCname').resolves([resolved]);
45+
resolveSpy.restore();
46+
sinon.stub(dns, 'resolve').withArgs(sinon.match.any, 'CNAME').resolves([resolved]);
4947
});
5048

5149
it('performs a cname lookup', async () => {
@@ -54,8 +52,8 @@ describe('GSSAPI', () => {
5452
});
5553
expect(host).to.equal(resolved);
5654
expect(dns.lookup).to.not.be.called;
57-
expect(dns.resolvePtr).to.not.be.called;
58-
expect(dns.resolveCname).to.be.calledOnceWith(hostName);
55+
expect(dns.resolve.withArgs(sinon.match.any, 'PTR')).to.not.be.called;
56+
expect(dns.resolve).to.be.calledOnceWith(hostName, 'CNAME');
5957
});
6058
});
6159

@@ -73,9 +71,9 @@ describe('GSSAPI', () => {
7371

7472
beforeEach(() => {
7573
lookupSpy.restore();
76-
resolvePtrSpy.restore();
74+
resolveSpy.restore();
7775
sinon.stub(dns, 'lookup').resolves(lookedUp);
78-
sinon.stub(dns, 'resolvePtr').resolves([resolved]);
76+
sinon.stub(dns, 'resolve').withArgs(sinon.match.any, 'PTR').resolves([resolved]);
7977
});
8078

8179
it('uses the reverse lookup host', async () => {
@@ -84,8 +82,8 @@ describe('GSSAPI', () => {
8482
});
8583
expect(host).to.equal(resolved);
8684
expect(dns.lookup).to.be.calledOnceWith(hostName);
87-
expect(dns.resolvePtr).to.be.calledOnceWith(lookedUp.address);
88-
expect(dns.resolveCname).to.not.be.called;
85+
expect(dns.resolve).to.be.calledOnceWith(lookedUp.address, 'PTR');
86+
expect(dns.resolve).to.not.be.calledOnceWith(lookedUp.address, 'CNAME');
8987
});
9088
});
9189

@@ -94,9 +92,12 @@ describe('GSSAPI', () => {
9492

9593
beforeEach(() => {
9694
lookupSpy.restore();
97-
resolvePtrSpy.restore();
95+
resolveSpy.restore();
9896
sinon.stub(dns, 'lookup').resolves(lookedUp);
99-
sinon.stub(dns, 'resolvePtr').resolves([resolved, 'example.com']);
97+
sinon
98+
.stub(dns, 'resolve')
99+
.withArgs(sinon.match.any, 'PTR')
100+
.resolves([resolved, 'example.com']);
100101
});
101102

102103
it('uses the first found reverse lookup host', async () => {
@@ -105,8 +106,8 @@ describe('GSSAPI', () => {
105106
});
106107
expect(host).to.equal(resolved);
107108
expect(dns.lookup).to.be.calledOnceWith(hostName);
108-
expect(dns.resolvePtr).to.be.calledOnceWith(lookedUp.address);
109-
expect(dns.resolveCname).to.not.be.called;
109+
expect(dns.resolve).to.be.calledOnceWith(lookedUp.address, 'PTR');
110+
expect(dns.resolve).to.not.be.calledOnceWith(sinon.match.any, 'CNAME');
110111
});
111112
});
112113
});
@@ -116,11 +117,11 @@ describe('GSSAPI', () => {
116117

117118
beforeEach(() => {
118119
lookupSpy.restore();
119-
resolvePtrSpy.restore();
120-
resolveCnameSpy.restore();
120+
resolveSpy.restore();
121121
sinon.stub(dns, 'lookup').resolves(lookedUp);
122-
sinon.stub(dns, 'resolvePtr').rejects(new Error('failed'));
123-
sinon.stub(dns, 'resolveCname').resolves([cname]);
122+
const stub = sinon.stub(dns, 'resolve');
123+
stub.withArgs(sinon.match.any, 'PTR').rejects(new Error('failed'));
124+
stub.withArgs(sinon.match.any, 'CNAME').resolves([cname]);
124125
});
125126

126127
it('falls back to a cname lookup', async () => {
@@ -130,17 +131,17 @@ describe('GSSAPI', () => {
130131

131132
expect(host).to.equal(cname);
132133
expect(dns.lookup).to.be.calledOnceWith(hostName);
133-
expect(dns.resolvePtr).to.be.calledOnceWith(lookedUp.address);
134-
expect(dns.resolveCname).to.be.calledWith(hostName);
134+
expect(dns.resolve).to.be.calledWith(lookedUp.address, 'PTR');
135+
expect(dns.resolve).to.be.calledWith(hostName, 'CNAME');
135136
});
136137
});
137138

138139
context('when the reverse lookup is empty', () => {
139140
beforeEach(() => {
140141
lookupSpy.restore();
141-
resolvePtrSpy.restore();
142+
resolveSpy.restore();
142143
sinon.stub(dns, 'lookup').resolves(lookedUp);
143-
sinon.stub(dns, 'resolvePtr').resolves([]);
144+
sinon.stub(dns, 'resolve').withArgs(sinon.match.any, 'PTR').resolves([]);
144145
});
145146

146147
it('uses the provided host', async () => {
@@ -149,8 +150,8 @@ describe('GSSAPI', () => {
149150
});
150151
expect(host).to.equal(hostName);
151152
expect(dns.lookup).to.be.calledOnceWith(hostName);
152-
expect(dns.resolvePtr).to.be.calledOnceWith(lookedUp.address);
153-
expect(dns.resolveCname).to.not.be.called;
153+
expect(dns.resolve).to.be.calledOnceWith(lookedUp.address, 'PTR');
154+
expect(dns.resolve).to.not.be.calledWith(sinon.match.any, 'CNAME');
154155
});
155156
});
156157
});
@@ -168,8 +169,8 @@ describe('GSSAPI', () => {
168169

169170
expect(error.message).to.equal('failed');
170171
expect(dns.lookup).to.be.calledOnceWith(hostName);
171-
expect(dns.resolvePtr).to.not.be.called;
172-
expect(dns.resolveCname).to.not.be.called;
172+
expect(dns.resolve).to.not.be.calledWith(sinon.match.any, 'PTR');
173+
expect(dns.resolve).to.not.be.calledWith(sinon.match.any, 'CNAME');
173174
});
174175
});
175176
});
@@ -181,14 +182,14 @@ describe('GSSAPI', () => {
181182
const hostName = 'example.com';
182183

183184
beforeEach(() => {
184-
resolveCnameSpy.restore();
185-
sinon.stub(dns, 'resolveCname').rejects(new Error('failed'));
185+
resolveSpy.restore();
186+
sinon.stub(dns, 'resolve').withArgs(sinon.match.any, 'CNAME').rejects(new Error('failed'));
186187
});
187188

188189
it('falls back to the provided host name', async () => {
189190
const host = await resolveCname(hostName);
190191
expect(host).to.equal(hostName);
191-
expect(dns.resolveCname).to.be.calledOnceWith(hostName);
192+
expect(dns.resolve).to.be.calledOnceWith(hostName, 'CNAME');
192193
});
193194
});
194195

@@ -198,14 +199,14 @@ describe('GSSAPI', () => {
198199
const resolved = '10gen.cc';
199200

200201
beforeEach(() => {
201-
resolveCnameSpy.restore();
202-
sinon.stub(dns, 'resolveCname').resolves([resolved]);
202+
resolveSpy.restore();
203+
sinon.stub(dns, 'resolve').withArgs(sinon.match.any, 'CNAME').resolves([resolved]);
203204
});
204205

205206
it('uses the result', async () => {
206207
const host = await resolveCname(hostName);
207208
expect(host).to.equal(resolved);
208-
expect(dns.resolveCname).to.be.calledOnceWith(hostName);
209+
expect(dns.resolve).to.be.calledOnceWith(hostName, 'CNAME');
209210
});
210211
});
211212

@@ -214,14 +215,17 @@ describe('GSSAPI', () => {
214215
const resolved = '10gen.cc';
215216

216217
beforeEach(() => {
217-
resolveCnameSpy.restore();
218-
sinon.stub(dns, 'resolveCname').resolves([resolved, hostName]);
218+
resolveSpy.restore();
219+
sinon
220+
.stub(dns, 'resolve')
221+
.withArgs(sinon.match.any, 'CNAME')
222+
.resolves([resolved, hostName]);
219223
});
220224

221225
it('uses the first result', async () => {
222226
const host = await resolveCname(hostName);
223227
expect(host).to.equal(resolved);
224-
expect(dns.resolveCname).to.be.calledOnceWith(hostName);
228+
expect(dns.resolve).to.be.calledOnceWith(hostName, 'CNAME');
225229
});
226230
});
227231
});
@@ -230,14 +234,14 @@ describe('GSSAPI', () => {
230234
const hostName = 'example.com';
231235

232236
beforeEach(() => {
233-
resolveCnameSpy.restore();
234-
sinon.stub(dns, 'resolveCname').resolves([]);
237+
resolveSpy.restore();
238+
sinon.stub(dns, 'resolve').withArgs(sinon.match.any, 'CNAME').resolves([]);
235239
});
236240

237241
it('falls back to using the provided host', async () => {
238242
const host = await resolveCname(hostName);
239243
expect(host).to.equal(hostName);
240-
expect(dns.resolveCname).to.be.calledOnceWith(hostName);
244+
expect(dns.resolve).to.be.calledOnceWith(hostName, 'CNAME');
241245
});
242246
});
243247
});

test/unit/connection_string.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,12 @@ describe('Connection String', function () {
633633

634634
// first call is for stubbing resolve
635635
// second call is for stubbing resolve
636-
sinon.stub(dns.promises, 'resolve').callsFake(async () => {
636+
const stub = sinon.stub(dns.promises, 'resolve');
637+
stub.withArgs(sinon.match.any, 'SRV').callsFake(async () => {
637638
return mockAddress;
638639
});
639640

640-
sinon.stub(dns.promises, 'resolve').callsFake(async () => {
641+
stub.withArgs(sinon.match.any, 'TXT').callsFake(async () => {
641642
return mockRecord;
642643
});
643644
}

0 commit comments

Comments
 (0)