Skip to content

Commit

Permalink
merge drivers v2.25.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Apr 14, 2024
2 parents 65de66c + 46eafc9 commit 3ec640a
Show file tree
Hide file tree
Showing 73 changed files with 2,207 additions and 369 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ src/packages
benchmarks/MongoDB.Driver.Benchmarks/BenchmarkDotNet.Artifacts
benchmarks/MongoDB.Driver.Benchmarks/data

# AWS Lambda Function Tests Artifacts
tests/FaasTests/LambdaTests/.aws-sam

# Other
artifacts
packages
Expand Down
214 changes: 214 additions & 0 deletions CSharpDriver.sln.DotSettings

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ Task("TestGssapiNetStandard20").IsDependentOn("TestGssapi");
Task("TestGssapiNetStandard21").IsDependentOn("TestGssapi");
Task("TestGssapiNet60").IsDependentOn("TestGssapi");

Task("TestMongoDbOidc")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"MongoDbOidc\""));

Task("TestServerless")
.IsDependentOn("Build")
.DoesForEach(
Expand Down Expand Up @@ -439,6 +446,7 @@ Task("SmokeTestsNetCoreApp21").IsDependentOn("SmokeTests");
Task("SmokeTestsNetCoreApp31").IsDependentOn("SmokeTests");
Task("SmokeTestsNet50").IsDependentOn("SmokeTests");
Task("SmokeTestsNet60").IsDependentOn("SmokeTests");
Task("SmokeTestsNet80").IsDependentOn("SmokeTests");

Task("TestsPackaging")
.IsDependentOn("TestsPackagingProjectReference")
Expand Down Expand Up @@ -658,6 +666,7 @@ Setup<BuildConfig>(
string s when s.EndsWith("net472") => "net472",
string s when s.EndsWith("net50") => "net5.0",
string s when s.EndsWith("net60") => "net6.0",
string s when s.EndsWith("net80") => "net8.0",
_ => null
};

Expand Down Expand Up @@ -690,7 +699,7 @@ public class BuildConfig
string[] CreateLoggers(string projectName)
{
var testResultsFile = outputDirectory.Combine("test-results").Combine($"TEST-{projectName}-{target.ToLowerInvariant()}-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}.xml");

// Evergreen CI server requires JUnit output format to display test results
var junitLogger = $"junit;LogFilePath={testResultsFile};FailureBodyFormat=Verbose";
var consoleLogger = "console;verbosity=detailed";
Expand Down
2 changes: 2 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ if($FoundDotNetCliVersion -ne $DotNetVersion) {
& bash $ScriptPath --install-dir "$InstallPath" --channel 2.1 --no-path
& bash $ScriptPath --install-dir "$InstallPath" --channel 3.1 --no-path
& bash $ScriptPath --install-dir "$InstallPath" --channel 5.0 --no-path
& bash $ScriptPath --install-dir "$InstallPath" --channel 8.0 --no-path
& bash $ScriptPath --version "$DotNetVersion" --install-dir "$InstallPath" --channel "$DotNetChannel" --no-path

Remove-PathVariable "$InstallPath"
Expand All @@ -113,6 +114,7 @@ if($FoundDotNetCliVersion -ne $DotNetVersion) {
& $ScriptPath -Channel 2.1 -InstallDir $InstallPath;
& $ScriptPath -Channel 3.1 -InstallDir $InstallPath;
& $ScriptPath -Channel 5.0 -InstallDir $InstallPath;
& $ScriptPath -Channel 8.0 -InstallDir $InstallPath;
& $ScriptPath -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;

Remove-PathVariable "$InstallPath"
Expand Down
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ if [ "$DOTNET_VERSION" != "$DOTNET_INSTALLED_VERSION" ]; then
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 2.1 --architecture x64 --install-dir .dotnet --no-path
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 3.1 --architecture x64 --install-dir .dotnet --no-path
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 5.0 --architecture x64 --install-dir .dotnet --no-path
if [[ ! "$OS" =~ macOS|macos ]]; then # net8 is not supported on macOS 11
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 8.0 --architecture x64 --install-dir .dotnet --no-path
fi
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION --install-dir .dotnet --no-path
export PATH="$SCRIPT_DIR/.dotnet":$PATH
export DOTNET_ROOT="$SCRIPT_DIR/.dotnet"
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/MongoDB.Bson/IO/JsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,10 @@ private BsonValue ParseRegularExpressionExtendedJsonCanonical()
throw new FormatException(message);
}
var value = nextToken.StringValue;
if (value.Contains("\0"))
{
throw new FormatException($"$regularExpression {name} cannot contain embedded nulls.");
}

switch (name)
{
Expand Down
17 changes: 15 additions & 2 deletions src/MongoDB.Bson/IO/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -814,12 +814,12 @@ protected override void Dispose(bool disposing)
// private methods
private string EscapedString(string value)
{
if (value.All(c => !NeedsEscaping(c)))
if (!NeedsEscaping(value))
{
return value;
}

var sb = new StringBuilder(value.Length);
var sb = new StringBuilder(value.Length * 2);

foreach (char c in value)
{
Expand Down Expand Up @@ -935,6 +935,19 @@ private string GuidToString(BsonBinarySubType subType, byte[] bytes, GuidReprese
}
}

private static bool NeedsEscaping(string text)
{
foreach (var letter in text)
{
if (NeedsEscaping(letter))
{
return true;
}
}

return false;
}

private static bool NeedsEscaping(char c)
{
switch (c)
Expand Down
24 changes: 20 additions & 4 deletions src/MongoDB.Bson/ObjectModel/BsonDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ public BsonDocument(BsonElement element)
Add(element);
}

/// <summary>
/// Initializes a new instance of the BsonDocument by coping elements from another BsonDocument.
/// </summary>
/// <param name="document">The document whose elements will be copied</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public BsonDocument(BsonDocument document)
{
if (document == null)
{
throw new ArgumentNullException(nameof(document));
}

_allowDuplicateNames = document.AllowDuplicateNames;
AddRange(document);
}

/// <summary>
/// Initializes a new instance of the BsonDocument class and adds new elements from a dictionary of key/value pairs.
/// </summary>
Expand Down Expand Up @@ -733,7 +749,7 @@ public virtual void Clear()
/// <returns>A shallow clone of the document.</returns>
public override BsonValue Clone()
{
BsonDocument clone = new BsonDocument();
BsonDocument clone = new BsonDocument() { AllowDuplicateNames = AllowDuplicateNames };
foreach (BsonElement element in _elements)
{
clone.Add(element.Clone());
Expand All @@ -745,7 +761,7 @@ public override BsonValue Clone()
/// Compares this document to another document.
/// </summary>
/// <param name="rhs">The other document.</param>
/// <returns>A 32-bit signed integer that indicates whether this document is less than, equal to, or greather than the other.</returns>
/// <returns>A 32-bit signed integer that indicates whether this document is less than, equal to, or greater than the other.</returns>
public virtual int CompareTo(BsonDocument rhs)
{
if (rhs == null) { return 1; }
Expand Down Expand Up @@ -776,7 +792,7 @@ public virtual int CompareTo(BsonDocument rhs)
/// Compares the BsonDocument to another BsonValue.
/// </summary>
/// <param name="other">The other BsonValue.</param>
/// <returns>A 32-bit signed integer that indicates whether this BsonDocument is less than, equal to, or greather than the other BsonValue.</returns>
/// <returns>A 32-bit signed integer that indicates whether this BsonDocument is less than, equal to, or greater than the other BsonValue.</returns>
public override int CompareTo(BsonValue other)
{
if (other == null) { return 1; }
Expand Down Expand Up @@ -818,7 +834,7 @@ public virtual bool ContainsValue(BsonValue value)
/// <returns>A deep clone of the document.</returns>
public override BsonValue DeepClone()
{
BsonDocument clone = new BsonDocument();
BsonDocument clone = new BsonDocument() { AllowDuplicateNames = AllowDuplicateNames };
foreach (BsonElement element in _elements)
{
clone.Add(element.DeepClone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Etherna.MongoDB.Bson.Serialization.Attributes
public class BsonRepresentationAttribute : BsonSerializationOptionsAttribute
{
// private fields
private BsonType _representation;
private readonly BsonType _representation;
private bool _allowOverflow;
private bool _allowTruncation;

Expand All @@ -37,6 +37,8 @@ public class BsonRepresentationAttribute : BsonSerializationOptionsAttribute
public BsonRepresentationAttribute(BsonType representation)
{
_representation = representation;
_allowOverflow = false;
_allowTruncation = representation == BsonType.Decimal128;
}

// public properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private BsonCreatorMap ChooseBestCreator(Dictionary<string, object> values)

if (creatorMap == null)
{
throw new BsonSerializationException("No matching creator found.");
throw new BsonSerializationException($"No matching creator found for class {_classMap.ClassType.FullName}.");
}

return creatorMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public DecimalSerializer()
/// </summary>
/// <param name="representation">The representation.</param>
public DecimalSerializer(BsonType representation)
: this(representation, new RepresentationConverter(false, false))
: this(representation, new RepresentationConverter(allowOverflow: false, allowTruncation: true))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void Authenticate(IConnection connection, ConnectionDescription descripti
if (!description.HelloResult.HasSaslSupportedMechs
&& Feature.ScramSha256Authentication.IsSupported(description.MaxWireVersion))
{
var command = CustomizeInitialHelloCommand(HelloHelper.CreateCommand(_serverApi, loadBalanced: connection.Settings.LoadBalanced));
var command = CustomizeInitialHelloCommand(HelloHelper.CreateCommand(_serverApi, loadBalanced: connection.Settings.LoadBalanced), cancellationToken);
var helloProtocol = HelloHelper.CreateProtocol(command, _serverApi);
var helloResult = HelloHelper.GetResult(connection, helloProtocol, cancellationToken);
var mergedHelloResult = new HelloResult(description.HelloResult.Wrapped.Merge(helloResult.Wrapped));
Expand All @@ -111,7 +111,7 @@ public async Task AuthenticateAsync(IConnection connection, ConnectionDescriptio
if (!description.HelloResult.HasSaslSupportedMechs
&& Feature.ScramSha256Authentication.IsSupported(description.MaxWireVersion))
{
var command = CustomizeInitialHelloCommand(HelloHelper.CreateCommand(_serverApi, loadBalanced: connection.Settings.LoadBalanced));
var command = CustomizeInitialHelloCommand(HelloHelper.CreateCommand(_serverApi, loadBalanced: connection.Settings.LoadBalanced), cancellationToken);
var helloProtocol = HelloHelper.CreateProtocol(command, _serverApi);
var helloResult = await HelloHelper.GetResultAsync(connection, helloProtocol, cancellationToken).ConfigureAwait(false);
var mergedHelloResult = new HelloResult(description.HelloResult.Wrapped.Merge(helloResult.Wrapped));
Expand All @@ -125,12 +125,12 @@ public async Task AuthenticateAsync(IConnection connection, ConnectionDescriptio
}

/// <inheritdoc/>
public BsonDocument CustomizeInitialHelloCommand(BsonDocument helloCommand)
public BsonDocument CustomizeInitialHelloCommand(BsonDocument helloCommand, CancellationToken cancellationToken)
{
var saslSupportedMechs = CreateSaslSupportedMechsRequest(_credential.Source, _credential.Username);
helloCommand = helloCommand.Merge(saslSupportedMechs);
_speculativeAuthenticator = new ScramSha256Authenticator(_credential, _randomStringGenerator, _serverApi);
return _speculativeAuthenticator.CustomizeInitialHelloCommand(helloCommand);
return _speculativeAuthenticator.CustomizeInitialHelloCommand(helloCommand, cancellationToken);
}

private static BsonDocument CreateSaslSupportedMechsRequest(string authenticationDatabaseName, string userName)
Expand Down
67 changes: 33 additions & 34 deletions src/MongoDB.Driver.Core/Core/Authentication/GssapiAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using System.Net;
using System.Security;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Etherna.MongoDB.Driver.Core.Connections;
using Etherna.MongoDB.Driver.Core.Misc;

Expand All @@ -29,6 +31,14 @@ namespace Etherna.MongoDB.Driver.Core.Authentication
public sealed class GssapiAuthenticator : SaslAuthenticator
{
// constants
/// <summary>
/// The name of the mechanism.
/// </summary>
public const string MechanismName = "GSSAPI";
/// <summary>
/// The default service name.
/// </summary>
public const string DefaultServiceName = "mongodb";
private const string __canonicalizeHostNamePropertyName = "CANONICALIZE_HOST_NAME";
private const string __realmPropertyName = "REALM";
private const string __serviceNamePropertyName = "SERVICE_NAME";
Expand All @@ -46,28 +56,6 @@ public static string CanonicalizeHostNamePropertyName
get { return __canonicalizeHostNamePropertyName; }
}

/// <summary>
/// Gets the default service name.
/// </summary>
/// <value>
/// The default service name.
/// </value>
public static string DefaultServiceName
{
get { return "mongodb"; }
}

/// <summary>
/// Gets the name of the mechanism.
/// </summary>
/// <value>
/// The name of the mechanism.
/// </value>
public static string MechanismName
{
get { return "GSSAPI"; }
}

/// <summary>
/// Gets the name of the realm property.
/// </summary>
Expand Down Expand Up @@ -224,22 +212,17 @@ public string Name
get { return MechanismName; }
}

public ISaslStep Initialize(IConnection connection, SaslConversation conversation, ConnectionDescription description)
public ISaslStep Initialize(
IConnection connection,
SaslConversation conversation,
ConnectionDescription description,
CancellationToken cancellationToken)
{
Ensure.IsNotNull(connection, nameof(connection));
Ensure.IsNotNull(description, nameof(description));

string hostName;
var dnsEndPoint = connection.EndPoint as DnsEndPoint;
if (dnsEndPoint != null)
{
hostName = dnsEndPoint.Host;
}
else if (connection.EndPoint is IPEndPoint)
{
hostName = ((IPEndPoint)connection.EndPoint).Address.ToString();
}
else
var hostName = connection.EndPoint.GetHostAndPort().Host;
if (string.IsNullOrEmpty(hostName))
{
throw new MongoAuthenticationException(connection.ConnectionId, "Only DnsEndPoint and IPEndPoint are supported for GSSAPI authentication.");
}
Expand All @@ -255,6 +238,13 @@ public ISaslStep Initialize(IConnection connection, SaslConversation conversatio

return new FirstStep(_serviceName, hostName, _realm, _username, _password, conversation);
}

public Task<ISaslStep> InitializeAsync(
IConnection connection,
SaslConversation conversation,
ConnectionDescription description,
CancellationToken cancellationToken)
=> Task.FromResult(Initialize(connection, conversation, description, cancellationToken));
}

private class FirstStep : ISaslStep
Expand Down Expand Up @@ -315,6 +305,9 @@ public ISaslStep Transition(SaslConversation conversation, byte[] bytesReceivedF

return new NegotiateStep(_authorizationId, _context, bytesToSendToServer);
}

public Task<ISaslStep> TransitionAsync(SaslConversation conversation, byte[] bytesReceivedFromServer, CancellationToken cancellationToken)
=> Task.FromResult(Transition(conversation, bytesReceivedFromServer));
}

private class InitializeStep : ISaslStep
Expand Down Expand Up @@ -359,6 +352,9 @@ public ISaslStep Transition(SaslConversation conversation, byte[] bytesReceivedF

return new NegotiateStep(_authorizationId, _context, bytesToSendToServer);
}

public Task<ISaslStep> TransitionAsync(SaslConversation conversation, byte[] bytesReceivedFromServer, CancellationToken cancellationToken)
=> Task.FromResult(Transition(conversation, bytesReceivedFromServer));
}

private class NegotiateStep : ISaslStep
Expand Down Expand Up @@ -427,6 +423,9 @@ public ISaslStep Transition(SaslConversation conversation, byte[] bytesReceivedF

return new CompletedStep(bytesToSendToServer);
}

public Task<ISaslStep> TransitionAsync(SaslConversation conversation, byte[] bytesReceivedFromServer, CancellationToken cancellationToken)
=> Task.FromResult(Transition(conversation, bytesReceivedFromServer));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public interface IAuthenticator
/// Optionally customizes hello or legacy hello command.
/// </summary>
/// <param name="helloCommand">Initial command.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Optionally mutated command.</returns>
BsonDocument CustomizeInitialHelloCommand(BsonDocument helloCommand);
BsonDocument CustomizeInitialHelloCommand(BsonDocument helloCommand, CancellationToken cancellationToken);
}
}
Loading

0 comments on commit 3ec640a

Please sign in to comment.