testcontainers / testcontainers-dotnet

A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
https://dotnet.testcontainers.org
MIT License
3.79k stars 275 forks source link

[Enhancement]: Explicit no-authentication mode for MongoDb #982

Closed the-avid-engineer closed 1 year ago

the-avid-engineer commented 1 year ago

Problem

The 3.0 release broke MongoDb no-authentication mode, which makes replica set mode easier to use (see https://github.com/testcontainers/testcontainers-dotnet/issues/538)

If you explicitly use new MongoDbBuilder().WithUsername(null).WithPassword(null), the code will now default to using mongo for the username and password, and if you use empty string instead of null, a runtime error is throwing saying these fields are required, which means it is now impossible to use no-authentication mode out of the box.

Solution

Provide a property on MongoDbConfiguration called useDefaultCredentials that defaults to true to preserve current behavior, but can be set to false to get the desired behavior.

Benefit

This allows for running mongodb in replica set mode without having to set up the extra bits that are required when authentication is enabled, and having an explicit feature to not use the default credentials will hopefully prevent a regression

Alternatives

I can only think of workarounds, not alternatives

Would you like to help contributing this enhancement?

Yes

the-avid-engineer commented 1 year ago

PR https://github.com/testcontainers/testcontainers-dotnet/pull/983