Skip to content

CSHARP-5106: Disallow comma character in authMechanismProperties conn… #1354

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

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

sanych-sun
Copy link
Member

…ection string value

@sanych-sun sanych-sun requested a review from a team as a code owner June 17, 2024 20:03
@sanych-sun sanych-sun requested review from rstam and removed request for a team June 17, 2024 20:03
@damieng
Copy link
Member

damieng commented Jun 18, 2024

Is this the right branch? While there are two tests regarding commas there's a ton of seemingly unrelated connection stuff in this PR.

@sanych-sun
Copy link
Member Author

Yep, this is the proper branch. CSharp driver has the appropriate functionality done in scope of OIDC implementation. This changes needed to add spec tests to verify the behavior + some minor fixes in spec tests. So the most changes are about spec tests sync (*.yml and *.json files were copied from spec repository)


if (Environment == "test" && !string.IsNullOrEmpty(PrincipalName))
{
throw new ArgumentException($"{nameof(PrincipalName)} is not supported by {Environment} environment.", nameof(PrincipalName));
Copy link
Contributor

Choose a reason for hiding this comment

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

ArgumentException seems weird here (there is no argument named PrincipalName, that's a property name). But I do see that there is lots of code above this that already does that.

This seems more like a configuration error than an argument exception.

Not sure what the correct exception should be though, .NET does not seem to have an appropriate exception for configuration errors.

If we want to be thorough we could define our own ConfigurationException class.

Alternatively consider throwing NotSupportedException?

Or just ignore this whole comment and throw ArgumentException... :)

Copy link
Member

Choose a reason for hiding this comment

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

I normally go with InvalidOperationException

The exception that is thrown when a method call is invalid for the object's current state.

https://learn.microsoft.com/en-us/dotnet/api/system.invalidoperationexception?view=net-8.0&redirectedfrom=MSDN

Copy link
Contributor

Choose a reason for hiding this comment

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

I wondered about that. Usually "invalid operation" is thrown by methods. The meaning is that the "operation" is not valid in the current state of the object, but that if you changed the state of the object you might be able to call the method again (i.e. execute the operation) successfully.

No method was called (by the user) in this case. I suppose you could argue that the "operation" here is the constructor call.

Copy link
Member Author

Choose a reason for hiding this comment

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

@rstam as it turned out we do have MongoConfigurationException. I'll switch to using it here... the only question should I change all exceptions in the method to throw MongoConfigurationException instead of ArgumentException? Changing that would be a breaking change, but the code is relatively new so probably we can do that. @JamesKovacs WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

MongoConfigurationException seems quite appropriate here. Although it is technically a breaking to change from ArgumentException to MongoConfigurationException, it's acceptable since OIDC was recently introduced and thus hasn't been widely adopted by our user community yet.

@sanych-sun sanych-sun requested review from rstam and JamesKovacs June 26, 2024 22:09
Copy link
Contributor

@JamesKovacs JamesKovacs left a comment

Choose a reason for hiding this comment

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

LGTM

@sanych-sun sanych-sun merged commit fc7df86 into mongodb:master Jun 27, 2024
27 of 31 checks passed
@sanych-sun sanych-sun deleted the csharp5106 branch June 27, 2024 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants