Skip to content

Commit 20c8d55

Browse files
committed
test(NODE-2939): update enum and tests
1 parent 3c6d586 commit 20c8d55

File tree

4 files changed

+37
-60
lines changed

4 files changed

+37
-60
lines changed

src/cmap/auth/gssapi.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Callback, ns } from '../../utils';
1313
import { AuthContext, AuthProvider } from './auth_provider';
1414

1515
/** @public */
16-
export const CanonicalizationProperties = Object.freeze({
16+
export const CanonicalizationValues = Object.freeze({
1717
on: true,
1818
off: false,
1919
none: 'none',
@@ -22,13 +22,13 @@ export const CanonicalizationProperties = Object.freeze({
2222
} as const);
2323

2424
/** @public */
25-
export type CanonicalizationProperties =
26-
typeof CanonicalizationProperties[keyof typeof CanonicalizationProperties];
25+
export type CanonicalizationValues =
26+
typeof CanonicalizationValues[keyof typeof CanonicalizationValues];
2727

2828
type MechanismProperties = {
2929
/** @deprecated use `CANONICALIZE_HOST_NAME` instead */
3030
gssapiCanonicalizeHostName?: boolean;
31-
CANONICALIZE_HOST_NAME?: CanonicalizationProperties;
31+
CANONICALIZE_HOST_NAME?: CanonicalizationValues;
3232
SERVICE_HOST?: string;
3333
SERVICE_NAME?: string;
3434
SERVICE_REALM?: string;
@@ -193,14 +193,14 @@ function performGssapiCanonicalizeHostName(
193193
callback: Callback<string>
194194
): void {
195195
const mode = mechanismProperties.CANONICALIZE_HOST_NAME;
196-
if (!mode || mode === CanonicalizationProperties.none) {
196+
if (!mode || mode === CanonicalizationValues.none) {
197197
return callback(undefined, host);
198198
}
199199

200200
// If forward and reverse or true
201201
if (
202-
mode === CanonicalizationProperties.on ||
203-
mode === CanonicalizationProperties.forwardAndReverse
202+
mode === CanonicalizationValues.on ||
203+
mode === CanonicalizationValues.forwardAndReverse
204204
) {
205205
// Perform the lookup of the ip address.
206206
dns.lookup(host, (error, address) => {

src/cmap/auth/mongo_credentials.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { Document } from '../../bson';
33
import { MongoAPIError, MongoMissingCredentialsError } from '../../error';
44
import { emitWarningOnce } from '../../utils';
5-
import { CanonicalizationProperties } from './gssapi';
5+
import { CanonicalizationValues } from './gssapi';
66
import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './providers';
77

88
// https://github.com./mongodb/specifications/blob/master/source/auth/auth.rst
@@ -31,7 +31,7 @@ export interface AuthMechanismProperties extends Document {
3131
SERVICE_HOST?: string;
3232
SERVICE_NAME?: string;
3333
SERVICE_REALM?: string;
34-
CANONICALIZE_HOST_NAME?: CanonicalizationProperties;
34+
CANONICALIZE_HOST_NAME?: CanonicalizationValues;
3535
AWS_SESSION_TOKEN?: string;
3636
}
3737

@@ -170,7 +170,7 @@ export class MongoCredentials {
170170
}
171171

172172
const canonicalization = this.mechanismProperties.CANONICALIZE_HOST_NAME ?? false;
173-
if (!Object.values(CanonicalizationProperties).includes(canonicalization)) {
173+
if (!Object.values(CanonicalizationValues).includes(canonicalization)) {
174174
throw new MongoAPIError(`Invalid CANONICALIZE_HOST_NAME value: ${canonicalization}`);
175175
}
176176
}

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export type {
176176
ResumeToken,
177177
UpdateDescription
178178
} from './change_stream';
179-
export type { CanonicalizationProperties } from './cmap/auth/gssapi';
179+
export type { CanonicalizationValues } from './cmap/auth/gssapi';
180180
export type {
181181
AuthMechanismProperties,
182182
MongoCredentials,

test/manual/kerberos.test.js

+26-49
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,39 @@ describe('Kerberos', function () {
8888
}
8989
});
9090

91-
context('when the value is true', function () {
92-
it('successfully authenticates', function (done) {
93-
const client = new MongoClient(
94-
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:true&maxPoolSize=1`
95-
);
96-
client.connect(function (err, client) {
97-
if (err) return done(err);
98-
expect(dns.resolveCname).to.be.calledOnce;
99-
verifyKerberosAuthentication(client, done);
91+
for (const option of [true, 'forward']) {
92+
context(`when the value is ${option}`, function () {
93+
it('authenticates with a forward cname lookup', function (done) {
94+
const client = new MongoClient(
95+
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:${option}&maxPoolSize=1`
96+
);
97+
client.connect(function (err, client) {
98+
if (err) return done(err);
99+
expect(dns.resolveCname).to.be.calledOnce;
100+
verifyKerberosAuthentication(client, done);
101+
});
100102
});
101103
});
102-
});
104+
}
103105

104-
context('when the value is forward', function () {
105-
it('successfully authenticates', function (done) {
106-
const client = new MongoClient(
107-
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:forward&maxPoolSize=1`
108-
);
109-
client.connect(function (err, client) {
110-
if (err) return done(err);
111-
expect(dns.resolveCname).to.be.calledOnce;
112-
verifyKerberosAuthentication(client, done);
106+
for (const option of [false, 'none']) {
107+
context(`when the value is ${option}`, function () {
108+
it('authenticates with no dns lookups', function (done) {
109+
const client = new MongoClient(
110+
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:${option}&maxPoolSize=1`
111+
);
112+
client.connect(function (err, client) {
113+
if (err) return done(err);
114+
expect(dns.resolveCname).to.not.be.called;
115+
expect(dns.lookup).to.not.be.called;
116+
verifyKerberosAuthentication(client, done);
117+
});
113118
});
114119
});
115-
});
120+
}
116121

117122
context('when the value is forwardAndReverse', function () {
118-
it('successfully authenticates', function (done) {
123+
it('authenticates with a forward dns lookup and a reverse ptr lookup', function (done) {
119124
const client = new MongoClient(
120125
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:forwardAndReverse&maxPoolSize=1`
121126
);
@@ -127,34 +132,6 @@ describe('Kerberos', function () {
127132
});
128133
});
129134
});
130-
131-
context('when the value is false', function () {
132-
it('successfully authenticates', function (done) {
133-
const client = new MongoClient(
134-
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:false&maxPoolSize=1`
135-
);
136-
client.connect(function (err, client) {
137-
if (err) return done(err);
138-
expect(dns.resolveCname).to.not.be.calledOnce;
139-
expect(dns.lookup).to.not.be.calledOnce;
140-
verifyKerberosAuthentication(client, done);
141-
});
142-
});
143-
});
144-
145-
context('when the value is none', function () {
146-
it('successfully authenticates', function (done) {
147-
const client = new MongoClient(
148-
`${krb5Uri}&authMechanismProperties=SERVICE_NAME:mongodb,CANONICALIZE_HOST_NAME:none&maxPoolSize=1`
149-
);
150-
client.connect(function (err, client) {
151-
if (err) return done(err);
152-
expect(dns.resolveCname).to.not.be.calledOnce;
153-
expect(dns.lookup).to.not.be.calledOnce;
154-
verifyKerberosAuthentication(client, done);
155-
});
156-
});
157-
});
158135
});
159136

160137
// Unskip this test when a proper setup is available - see NODE-3060

0 commit comments

Comments
 (0)