This repository was 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
NODE-1435: move all auth to connect
#406
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
312899c
refactor(auth): teach providers to not expect raw wire messages
mbroadst ef47a43
feat(auth): add authentication to handshake process
mbroadst ad5d8e3
refactor(auth): ensure all errors are wrapped in MongoError
mbroadst 4a97976
refactor(auth): return auth errors in `connect`
mbroadst 2184f7b
refactor(pool): remove concept of authentication
mbroadst 6f1671d
test(auth): correctly pass credentials to topology, not connect
mbroadst f7be09f
refactor(topologies): remove concept of authentication
mbroadst fa99c8f
refactor(pool): remove concept of authentication
mbroadst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,8 +5,14 @@ const Connection = require('./connection'); | |
const Query = require('./commands').Query; | ||
const createClientInfo = require('../topologies/shared').createClientInfo; | ||
const MongoError = require('../error').MongoError; | ||
const defaultAuthProviders = require('../auth/defaultAuthProviders').defaultAuthProviders; | ||
let AUTH_PROVIDERS; | ||
|
||
function connect(options, callback) { | ||
if (AUTH_PROVIDERS == null) { | ||
AUTH_PROVIDERS = defaultAuthProviders(options.bson); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double checking that we do not allow people to change their |
||
} | ||
|
||
if (options.family !== void 0) { | ||
makeConnection(options.family, options, (err, socket) => { | ||
if (err) { | ||
|
@@ -132,6 +138,14 @@ function performInitialHandshake(conn, options, callback) { | |
// relocated, or at very least restructured. | ||
conn.ismaster = ismaster; | ||
conn.lastIsMasterMS = new Date().getTime() - start; | ||
|
||
const credentials = options.credentials; | ||
if (credentials) { | ||
credentials.resolveAuthMechanism(ismaster); | ||
authenticate(conn, credentials, callback); | ||
return; | ||
} | ||
|
||
callback(null, conn); | ||
}); | ||
} | ||
|
@@ -260,6 +274,7 @@ function makeConnection(family, options, callback) { | |
|
||
const CONNECTION_ERROR_EVENTS = ['error', 'close', 'timeout', 'parseError']; | ||
function runCommand(conn, ns, command, options, callback) { | ||
if (typeof options === 'function') (callback = options), (options = {}); | ||
const socketTimeout = typeof options.socketTimeout === 'number' ? options.socketTimeout : 360000; | ||
const bson = conn.options.bson; | ||
const query = new Query(bson, ns, command, { | ||
|
@@ -293,4 +308,18 @@ function runCommand(conn, ns, command, options, callback) { | |
conn.write(query.toBin()); | ||
} | ||
|
||
function authenticate(conn, credentials, callback) { | ||
const mechanism = credentials.mechanism; | ||
if (!AUTH_PROVIDERS[mechanism]) { | ||
callback(new MongoError(`authMechanism '${mechanism}' not supported`)); | ||
return; | ||
} | ||
|
||
const provider = AUTH_PROVIDERS[mechanism]; | ||
provider.auth(runCommand, [conn], credentials, err => { | ||
if (err) return callback(err); | ||
callback(null, conn); | ||
}); | ||
} | ||
|
||
module.exports = connect; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.