Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWIFT-1161 MongoConnectionString authentication options support #631

Closed
wants to merge 8 commits into from

Conversation

bynn
Copy link
Contributor

@bynn bynn commented Apr 10, 2021

This currently doesn't have the accepted behavior for specifying the database and the authSource and I wanted to get some feedback on how I can improve the design

Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Tests/MongoSwiftTests/AuthTests.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
@bynn bynn requested a review from kmahar April 12, 2021 22:23
@bynn bynn changed the title SWIFT-1161 SWIFT-1161 MongoConnectionString authentication options support Apr 12, 2021
Copy link
Contributor

@kmahar kmahar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for making those changes! my next batch of comments is mainly around trying to make the logic flow a little more clear for future readers of the code, and ensuring we're handling edge cases

Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Tests/MongoSwiftTests/ConnectionStringTests.swift Outdated Show resolved Hide resolved
Tests/MongoSwiftTests/AuthTests.swift Outdated Show resolved Hide resolved
Tests/MongoSwiftTests/AuthTests.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
case "authSource":
self.credential?.source = value
case "authMechanism":
if value == "GSSAPI", self.credential?.source == self.database {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be helpful to leave a comment here explaining why you set it to nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that I think about it... we only have to do this because we preemptively fill in the default DB before calling this method, right?
I think it would be better if we could just hold off on populating that field until we're sure it's actually relevant to do so (maybe you could pass the default DB name into this method or something)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now only sets it when it needs to

Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
Sources/MongoSwift/MongoConnectionString.swift Outdated Show resolved Hide resolved
try MongoConnectionString.percentDecode(from: userInfoExists[1]) : nil
)
}
guard let authAndOptions = identifiersAndOptions.count == 2 ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this variable actually contains the auth DB and options right? (authAndOptions sounds like maybe it contains the user info too)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to authDBAndOptions

}
self.credential?.mechanismProperties = authMechanismProperties
default:
break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should never happen right? throwing an InternalError might be appropriate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wasn't sure on what to write but i tried to write something in the terms of MongoUnreachableError

}

private mutating func applyAndValidateAuthOptions(authOptions: [String: String]) throws {
guard self.credential != nil else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I realized x509 auth actually does not require a username, and neither does AWS:

https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#mongocredential-properties-1
https://github.com/mongodb/specifications/blob/master/source/auth/auth.rst#mongocredential-properties-5

there is a test case for that - "should recognize the mechanism with no username (MONGODB-X509)" I would think we would fail it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was never setting the mechanism because the credential was empty but I'm not sure why authTest wouldn't catch that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for MONGO-AWS it didn't exist in the MongoCredential so i didn't write anything for it. Does the swift driver support it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also currently, im duplicating a lot of code and the whole point of having a separate validate and apply was that we didn't have to do that so I'm not sure how to make this cleaner.

case "authSource":
self.credential?.source = value
case "authMechanism":
if value == "GSSAPI", self.credential?.source == self.database {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that I think about it... we only have to do this because we preemptively fill in the default DB before calling this method, right?
I think it would be better if we could just hold off on populating that field until we're sure it's actually relevant to do so (maybe you could pass the default DB name into this method or something)

Tests/MongoSwiftTests/AuthTests.swift Outdated Show resolved Hide resolved
Tests/MongoSwiftTests/AuthTests.swift Outdated Show resolved Hide resolved
@bynn bynn requested a review from kmahar April 15, 2021 23:57
@kmahar
Copy link
Contributor

kmahar commented Jul 16, 2021

we're closing this PR now as it now longer merges cleanly, however we will keep this branch around for when we have time to revisit the project, so we can use Bynn's work.

@kmahar kmahar closed this Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants