This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not attempt to auth against an arbiter
Fixes NODE-1909
- Loading branch information
1 parent
3c72479
commit 72bb011
Showing
2 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use strict'; | ||
|
||
const BSON = require('bson'); | ||
const mock = require('mongodb-mock-server'); | ||
const expect = require('chai').expect; | ||
|
||
const connect = require('../../../lib/connection/connect'); | ||
const MongoCredentials = require('../../../lib/auth/mongo_credentials').MongoCredentials; | ||
const genClusterTime = require('./common').genClusterTime; | ||
|
||
describe('Connect Tests', function() { | ||
const test = {}; | ||
beforeEach(() => { | ||
return mock.createServer().then(mockServer => { | ||
test.server = mockServer; | ||
test.connectOptions = { | ||
host: test.server.host, | ||
port: test.server.port, | ||
bson: new BSON(), | ||
credentials: new MongoCredentials({ | ||
username: 'testUser', | ||
password: 'pencil', | ||
source: 'admin', | ||
mechanism: 'plain' | ||
}) | ||
}; | ||
}); | ||
}); | ||
|
||
afterEach(() => mock.cleanup()); | ||
it('should auth against a non-arbiter', function(done) { | ||
const whatHappened = {}; | ||
|
||
test.server.setMessageHandler(request => { | ||
const doc = request.document; | ||
const $clusterTime = genClusterTime(Date.now()); | ||
|
||
if (doc.ismaster) { | ||
whatHappened.ismaster = true; | ||
request.reply( | ||
Object.assign({}, mock.DEFAULT_ISMASTER, { | ||
$clusterTime | ||
}) | ||
); | ||
} else if (doc.saslStart) { | ||
whatHappened.saslStart = true; | ||
request.reply({ ok: 1 }); | ||
} | ||
}); | ||
|
||
connect(test.connectOptions, err => { | ||
try { | ||
expect(whatHappened).to.have.property('ismaster', true); | ||
expect(whatHappened).to.have.property('saslStart', true); | ||
} catch (_err) { | ||
err = _err; | ||
} | ||
|
||
done(err); | ||
}); | ||
}); | ||
|
||
it('should not auth against an arbiter', function(done) { | ||
const whatHappened = {}; | ||
test.server.setMessageHandler(request => { | ||
const doc = request.document; | ||
const $clusterTime = genClusterTime(Date.now()); | ||
if (doc.ismaster) { | ||
whatHappened.ismaster = true; | ||
request.reply( | ||
Object.assign({}, mock.DEFAULT_ISMASTER, { | ||
$clusterTime, | ||
arbiterOnly: true | ||
}) | ||
); | ||
} else if (doc.saslStart) { | ||
whatHappened.saslStart = true; | ||
request.reply({ ok: 0 }); | ||
} | ||
}); | ||
|
||
connect(test.connectOptions, err => { | ||
try { | ||
expect(whatHappened).to.have.property('ismaster', true); | ||
expect(whatHappened).to.not.have.property('saslStart'); | ||
} catch (_err) { | ||
err = _err; | ||
} | ||
|
||
done(err); | ||
}); | ||
}); | ||
}); |