Skip to content

Instantly share code, notes, and snippets.

@mcasimir
Last active July 20, 2020 11:02
Show Gist options
  • Save mcasimir/0274c829fc858accafd5695f855effa6 to your computer and use it in GitHub Desktop.
Save mcasimir/0274c829fc858accafd5695f855effa6 to your computer and use it in GitHub Desktop.
Debug COMPASS-4319
const { MongoClient } = require('mongodb');
const assert = require('assert');
const HOST = 'centos-east.win.mongodb-field.com';
const PORT = '27017';
const PRINCIPAL = '[email protected]';
const GSSAPI_SERVICE_NAME = 'mongo-ent';
describe('MongoClient authentication with kerberos', () => {
const options = {
connectWithNoPrimary: true,
readPreference: 'primary',
useNewUrlParser: true
};
const uri = `mongodb://${encodeURIComponent(PRINCIPAL)}@${HOST}:${PORT}?authMechanism=GSSAPI&gssapiServiceName=${GSSAPI_SERVICE_NAME}`;
console.log(uri);
[false, true].forEach((useUnifiedTopology) => {
context(`when useUnifiedTopology: ${useUnifiedTopology}`, () => {
let client;
afterEach(async () => {
if (client) {
await client.close();
}
});
it('should connect to kerberized mongo', async () => {
client = await MongoClient.connect(uri, {
...options,
useUnifiedTopology
});
const result = await client.db().admin().listDatabases();
assert.equal(result.ok, 1);
}).timeout(35000);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment