From dd53db1ea07a66c12399efa7b2423deda5348ef1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 1 Nov 2024 08:44:01 -0500 Subject: [PATCH 1/4] Bump the nuget group across 9 directories with 1 update (#6859) Bumps the nuget group with 1 update in the /libraries/Microsoft.Bot.AdaptiveExpressions.Core directory: System.Text.Json. Bumps the nuget group with 1 update in the /libraries/Microsoft.Bot.Builder.AI.LUIS directory: System.Text.Json. Bumps the nuget group with 1 update in the /libraries/Microsoft.Bot.Builder.AI.QnA directory: System.Text.Json. Bumps the nuget group with 1 update in the /libraries/Microsoft.Bot.Builder.Azure.Blobs directory: System.Text.Json. Bumps the nuget group with 1 update in the /libraries/Microsoft.Bot.Builder.Azure.Queues directory: System.Text.Json. Bumps the nuget group with 1 update in the /libraries/Microsoft.Bot.Builder.Dialogs.Adaptive directory: System.Text.Json. Bumps the nuget group with 1 update in the /libraries/integration/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core directory: System.Text.Json. Bumps the nuget group with 1 update in the /libraries/integration/Microsoft.Bot.Builder.Integration.AspNet.Core directory: System.Text.Json. Bumps the nuget group with 1 update in the /tests/Microsoft.Bot.Connector.Streaming.Tests.Client directory: System.Text.Json. Updates `System.Text.Json` from 8.0.4 to 8.0.5 Updates `System.Text.Json` from 8.0.4 to 8.0.5 Updates `System.Text.Json` from 8.0.4 to 8.0.5 Updates `System.Text.Json` from 8.0.4 to 8.0.5 Updates `System.Text.Json` from 8.0.4 to 8.0.5 Updates `System.Text.Json` from 8.0.4 to 8.0.5 Updates `System.Text.Json` from 8.0.4 to 8.0.5 Updates `System.Text.Json` from 8.0.4 to 8.0.5 Updates `System.Text.Json` from 8.0.4 to 8.0.5 --- updated-dependencies: - dependency-name: System.Text.Json dependency-type: direct:production dependency-group: nuget - dependency-name: System.Text.Json dependency-type: direct:production dependency-group: nuget - dependency-name: System.Text.Json dependency-type: direct:production dependency-group: nuget - dependency-name: System.Text.Json dependency-type: direct:production dependency-group: nuget - dependency-name: System.Text.Json dependency-type: direct:production dependency-group: nuget - dependency-name: System.Text.Json dependency-type: direct:production dependency-group: nuget - dependency-name: System.Text.Json dependency-type: direct:production dependency-group: nuget - dependency-name: System.Text.Json dependency-type: direct:production dependency-group: nuget - dependency-name: System.Text.Json dependency-type: direct:production dependency-group: nuget ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../Microsoft.Bot.AdaptiveExpressions.Core.csproj | 2 +- .../Microsoft.Bot.Builder.AI.Luis.csproj | 2 +- .../Microsoft.Bot.Builder.AI.QnA.csproj | 2 +- .../Microsoft.Bot.Builder.Azure.Blobs.csproj | 2 +- .../Microsoft.Bot.Builder.Azure.Queues.csproj | 2 +- .../Microsoft.Bot.Builder.Dialogs.Adaptive.csproj | 2 +- ...soft.Bot.Builder.Integration.ApplicationInsights.Core.csproj | 2 +- .../Microsoft.Bot.Builder.Integration.AspNet.Core.csproj | 2 +- .../Microsoft.Bot.Connector.Streaming.Tests.Client.csproj | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/Microsoft.Bot.AdaptiveExpressions.Core/Microsoft.Bot.AdaptiveExpressions.Core.csproj b/libraries/Microsoft.Bot.AdaptiveExpressions.Core/Microsoft.Bot.AdaptiveExpressions.Core.csproj index b4df3dc5fe..eca5eb9122 100644 --- a/libraries/Microsoft.Bot.AdaptiveExpressions.Core/Microsoft.Bot.AdaptiveExpressions.Core.csproj +++ b/libraries/Microsoft.Bot.AdaptiveExpressions.Core/Microsoft.Bot.AdaptiveExpressions.Core.csproj @@ -40,7 +40,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj b/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj index d9a433eddb..e85d89ad57 100644 --- a/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj +++ b/libraries/Microsoft.Bot.Builder.AI.LUIS/Microsoft.Bot.Builder.AI.Luis.csproj @@ -32,7 +32,7 @@ - + diff --git a/libraries/Microsoft.Bot.Builder.AI.QnA/Microsoft.Bot.Builder.AI.QnA.csproj b/libraries/Microsoft.Bot.Builder.AI.QnA/Microsoft.Bot.Builder.AI.QnA.csproj index ea3425892d..37c4a4ffec 100644 --- a/libraries/Microsoft.Bot.Builder.AI.QnA/Microsoft.Bot.Builder.AI.QnA.csproj +++ b/libraries/Microsoft.Bot.Builder.AI.QnA/Microsoft.Bot.Builder.AI.QnA.csproj @@ -31,7 +31,7 @@ - + diff --git a/libraries/Microsoft.Bot.Builder.Azure.Blobs/Microsoft.Bot.Builder.Azure.Blobs.csproj b/libraries/Microsoft.Bot.Builder.Azure.Blobs/Microsoft.Bot.Builder.Azure.Blobs.csproj index 86ec2e184e..817ae0d180 100644 --- a/libraries/Microsoft.Bot.Builder.Azure.Blobs/Microsoft.Bot.Builder.Azure.Blobs.csproj +++ b/libraries/Microsoft.Bot.Builder.Azure.Blobs/Microsoft.Bot.Builder.Azure.Blobs.csproj @@ -22,7 +22,7 @@ - + diff --git a/libraries/Microsoft.Bot.Builder.Azure.Queues/Microsoft.Bot.Builder.Azure.Queues.csproj b/libraries/Microsoft.Bot.Builder.Azure.Queues/Microsoft.Bot.Builder.Azure.Queues.csproj index eeb08799f1..a83a3ad435 100644 --- a/libraries/Microsoft.Bot.Builder.Azure.Queues/Microsoft.Bot.Builder.Azure.Queues.csproj +++ b/libraries/Microsoft.Bot.Builder.Azure.Queues/Microsoft.Bot.Builder.Azure.Queues.csproj @@ -32,7 +32,7 @@ - + diff --git a/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Microsoft.Bot.Builder.Dialogs.Adaptive.csproj b/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Microsoft.Bot.Builder.Dialogs.Adaptive.csproj index 20e0dc5be8..97b92141a6 100644 --- a/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Microsoft.Bot.Builder.Dialogs.Adaptive.csproj +++ b/libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Microsoft.Bot.Builder.Dialogs.Adaptive.csproj @@ -40,7 +40,7 @@ - + diff --git a/libraries/integration/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.csproj b/libraries/integration/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.csproj index 2a888d69af..4fbf6ee961 100644 --- a/libraries/integration/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.csproj +++ b/libraries/integration/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core/Microsoft.Bot.Builder.Integration.ApplicationInsights.Core.csproj @@ -46,7 +46,7 @@ - + diff --git a/libraries/integration/Microsoft.Bot.Builder.Integration.AspNet.Core/Microsoft.Bot.Builder.Integration.AspNet.Core.csproj b/libraries/integration/Microsoft.Bot.Builder.Integration.AspNet.Core/Microsoft.Bot.Builder.Integration.AspNet.Core.csproj index b4e65f9931..234496b7f2 100644 --- a/libraries/integration/Microsoft.Bot.Builder.Integration.AspNet.Core/Microsoft.Bot.Builder.Integration.AspNet.Core.csproj +++ b/libraries/integration/Microsoft.Bot.Builder.Integration.AspNet.Core/Microsoft.Bot.Builder.Integration.AspNet.Core.csproj @@ -39,7 +39,7 @@ - + diff --git a/tests/Microsoft.Bot.Connector.Streaming.Tests.Client/Microsoft.Bot.Connector.Streaming.Tests.Client.csproj b/tests/Microsoft.Bot.Connector.Streaming.Tests.Client/Microsoft.Bot.Connector.Streaming.Tests.Client.csproj index c64ac56c78..c4eab565ea 100644 --- a/tests/Microsoft.Bot.Connector.Streaming.Tests.Client/Microsoft.Bot.Connector.Streaming.Tests.Client.csproj +++ b/tests/Microsoft.Bot.Connector.Streaming.Tests.Client/Microsoft.Bot.Connector.Streaming.Tests.Client.csproj @@ -7,7 +7,7 @@ - + From 0b16ac09d550da773750f84b57bf2bf80fb3f694 Mon Sep 17 00:00:00 2001 From: tracyboehrer Date: Fri, 1 Nov 2024 09:25:41 -0500 Subject: [PATCH 2/4] Bumped dependencies for System.Text.Json alert (#6864) Co-authored-by: Tracy Boehrer --- .../Microsoft.Bot.Builder.Azure.csproj | 2 +- .../Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj | 6 +++--- .../Microsoft.Bot.Connector.Tests.csproj | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.Azure/Microsoft.Bot.Builder.Azure.csproj b/libraries/Microsoft.Bot.Builder.Azure/Microsoft.Bot.Builder.Azure.csproj index 1dfead4bc6..f95084467f 100644 --- a/libraries/Microsoft.Bot.Builder.Azure/Microsoft.Bot.Builder.Azure.csproj +++ b/libraries/Microsoft.Bot.Builder.Azure/Microsoft.Bot.Builder.Azure.csproj @@ -38,7 +38,7 @@ - + diff --git a/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj b/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj index 67627e6767..4d5d6d4e99 100644 --- a/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj +++ b/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj @@ -29,9 +29,9 @@ - - - + + + diff --git a/tests/Microsoft.Bot.Connector.Tests/Microsoft.Bot.Connector.Tests.csproj b/tests/Microsoft.Bot.Connector.Tests/Microsoft.Bot.Connector.Tests.csproj index f47cda53e0..0014aef311 100644 --- a/tests/Microsoft.Bot.Connector.Tests/Microsoft.Bot.Connector.Tests.csproj +++ b/tests/Microsoft.Bot.Connector.Tests/Microsoft.Bot.Connector.Tests.csproj @@ -13,12 +13,12 @@ - + - + all From 913f7c38d02757add6c15cc518ef8364ade3ca14 Mon Sep 17 00:00:00 2001 From: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:40:49 -0300 Subject: [PATCH 3/4] Tag MsalServiceClientCredentialsFactory obsolete (#6866) --- .../Authentication/MsalServiceClientCredentialsFactory.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/Microsoft.Bot.Connector/Authentication/MsalServiceClientCredentialsFactory.cs b/libraries/Microsoft.Bot.Connector/Authentication/MsalServiceClientCredentialsFactory.cs index 27f6c33d04..d1b8f77287 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/MsalServiceClientCredentialsFactory.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/MsalServiceClientCredentialsFactory.cs @@ -18,6 +18,7 @@ namespace Microsoft.Bot.Connector.Authentication /// /// Credential factory that uses MSAL to acquire tokens. /// + [Obsolete("Use the ServiceClientCredentialsFactory implementation that corresponds to the authentication type (MSI, Certificate, Federated, etc.).", false)] public class MsalServiceClientCredentialsFactory : ServiceClientCredentialsFactory { private readonly IConfidentialClientApplication _clientApplication; From e449b3c93395d2b69c29d660402156516894d8ba Mon Sep 17 00:00:00 2001 From: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:41:02 -0300 Subject: [PATCH 4/4] Create deterministic GeHashCode method (#6860) --- .../CosmosDBKeyEscape.cs | 34 ++++++++++++++++++- .../CosmosDBKeyEscapeTests.cs | 4 ++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder.Azure/CosmosDBKeyEscape.cs b/libraries/Microsoft.Bot.Builder.Azure/CosmosDBKeyEscape.cs index e6e154d669..c191315941 100644 --- a/libraries/Microsoft.Bot.Builder.Azure/CosmosDBKeyEscape.cs +++ b/libraries/Microsoft.Bot.Builder.Azure/CosmosDBKeyEscape.cs @@ -117,11 +117,43 @@ private static string TruncateKeyIfNeeded(string key, bool truncateKeysForCompat if (key.Length > MaxKeyLength) { - var hash = key.GetHashCode().ToString("x", CultureInfo.InvariantCulture); + var hash = key.GetDeterministicHashCode().ToString("x", CultureInfo.InvariantCulture); key = key.Substring(0, MaxKeyLength - hash.Length) + hash; } return key; } + + /// + /// Creates a deterministic hash code by iterating through the string two characters at a time, + /// updating two separate hash values, and then combining them at the end. + /// This approach helps in reducing hash collisions and provides a consistent hash code for the same string across + /// different runs and environments. + /// + /// The string to calculate the hash on. + /// The hash code. + private static int GetDeterministicHashCode(this string str) + { + unchecked + { + var hash1 = (5381 << 16) + 5381; //shifts 5381 left by 16 bits and adds 5381 to it + var hash2 = hash1; + for (var i = 0; i < str.Length; i += 2) + { + // ((hash1 << 5) + hash1) is equivalent to hash1 * 33, which is a common multiplier in hash functions. + // The character str[i] is then XORed with this value. + hash1 = ((hash1 << 5) + hash1) ^ str[i]; + if (i == str.Length - 1) + { + break; + } + + hash2 = ((hash2 << 5) + hash2) ^ str[i + 1]; + } + + //1566083941 is a large prime number used to mix the two hash values together, ensuring a more uniform distribution of hash codes. + return hash1 + (hash2 * 1566083941); + } + } } } diff --git a/tests/Microsoft.Bot.Builder.Azure.Tests/CosmosDBKeyEscapeTests.cs b/tests/Microsoft.Bot.Builder.Azure.Tests/CosmosDBKeyEscapeTests.cs index 1f5ec6f3f2..f924bde1f8 100644 --- a/tests/Microsoft.Bot.Builder.Azure.Tests/CosmosDBKeyEscapeTests.cs +++ b/tests/Microsoft.Bot.Builder.Azure.Tests/CosmosDBKeyEscapeTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Reflection; using Xunit; namespace Microsoft.Bot.Builder.Azure.Tests @@ -40,7 +41,8 @@ public void Long_Key_Should_Be_Truncated() Assert.True(sanitizedKey.Length <= CosmosDbKeyEscape.MaxKeyLength, "Key too long"); // The resulting key should be: - var hash = tooLongKey.GetHashCode().ToString("x"); + var getHashMethod = typeof(CosmosDbKeyEscape).GetMethod("GetDeterministicHashCode", BindingFlags.NonPublic | BindingFlags.Static); + var hash = ((int)getHashMethod.Invoke(null, new object[] { tooLongKey })).ToString("x"); var correctKey = sanitizedKey.Substring(0, CosmosDbKeyEscape.MaxKeyLength - hash.Length) + hash; Assert.Equal(correctKey, sanitizedKey);