Skip to content

Commit 6578333

Browse files
committed
pr feedback: added tests that verify the wildcards in default allowed hosts
1 parent b6276b4 commit 6578333

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

test/unit/utils.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ObjectId } from 'bson';
44
import { expect } from 'chai';
55
import * as sinon from 'sinon';
66

7+
import { DEFAULT_ALLOWED_HOSTS } from '../../src/cmap/auth/mongo_credentials';
78
import { LEGACY_HELLO_COMMAND } from '../../src/constants';
89
import { MongoInvalidArgumentError, MongoRuntimeError } from '../../src/error';
910
import { decorateWithExplain, Explain } from '../../src/explain';
@@ -155,6 +156,19 @@ describe('driver utils', function () {
155156
});
156157
});
157158

159+
context('when using default allowed hosts', function () {
160+
it('returns false', function () {
161+
for (const host of DEFAULT_ALLOWED_HOSTS) {
162+
// Only test the wildcard hosts, the non-wildcard hosts are tested in other test cases
163+
if (!host.startsWith('*.')) {
164+
continue;
165+
}
166+
const wrongHost = host.replace('*.', 'test-');
167+
expect(hostMatchesWildcards(wrongHost, DEFAULT_ALLOWED_HOSTS)).to.be.false;
168+
}
169+
});
170+
});
171+
158172
context('when the host matches a FQDN', function () {
159173
it('returns true', function () {
160174
expect(hostMatchesWildcards('mongodb.net', ['*.mongodb.net', 'other'])).to.be.true;

0 commit comments

Comments
 (0)