Skip to content

Commit

Permalink
Merge branch 'main' into southworks/update/net8
Browse files Browse the repository at this point in the history
  • Loading branch information
JhontSouth committed May 15, 2024
2 parents d5dc1ce + 42c4395 commit b13e266
Show file tree
Hide file tree
Showing 54 changed files with 491 additions and 152 deletions.
2 changes: 1 addition & 1 deletion build/yaml/botbuilder-dotnet-ci-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ steps:
- task: NuGetToolInstaller@1
displayName: 'Use NuGet '

- task: NuGetAuthenticate@0
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
inputs:
nuGetServiceConnections: SDK_Dotnet_V4_org Connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public virtual bool ValidateSignature(HttpRequest request, string jsonPayload)
? request.Headers[SparkSignature].ToString().ToUpperInvariant()
: throw new InvalidOperationException($"HttpRequest is missing \"{SparkSignature}\"");

#pragma warning disable CA5350 // Webex API uses SHA1 as cryptographic algorithm.
using (var hmac = new HMACSHA1(Encoding.UTF8.GetBytes(Options.WebexSecret))) //lgtm[cs/weak-encryption]
#pragma warning disable CA5350
using (var hmac = new HMACSHA1(Encoding.UTF8.GetBytes(Options.WebexSecret))) // CODEQL [cs/weak-encryption] Webex API uses SHA1 as cryptographic algorithm.
{
var hashArray = hmac.ComputeHash(Encoding.UTF8.GetBytes(jsonPayload));
var hash = BitConverter.ToString(hashArray).Replace("-", string.Empty).ToUpperInvariant();
return signature == hash;
}
#pragma warning restore CA5350 // Webex API uses SHA1 as cryptographic algorithm.
#pragma warning restore CA5350
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions libraries/Microsoft.Bot.Builder.Azure.Blobs/BlobsStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public BlobsStorage(string dataConnectionString, string containerName, StorageTr

_jsonSerializer = jsonSerializer ?? JsonSerializer.Create(new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All, // lgtm [cs/unsafe-type-name-handling]
TypeNameHandling = TypeNameHandling.All, // CodeQL [cs/unsafe-type-name-handling] Serialization to and from a trusted source for state storage.
MaxDepth = null,
});

Expand Down Expand Up @@ -120,7 +120,7 @@ public BlobsStorage(Uri blobContainerUri, TokenCredential tokenCredential, Stora

_jsonSerializer = jsonSerializer ?? JsonSerializer.Create(new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All, // lgtm [cs/unsafe-type-name-handling]
TypeNameHandling = TypeNameHandling.All, // CodeQL [cs/unsafe-type-name-handling] Serialization to and from a trusted source for state storage.
MaxDepth = null,
});

Expand All @@ -146,7 +146,7 @@ internal BlobsStorage(BlobContainerClient containerClient, JsonSerializer jsonSe

_jsonSerializer = jsonSerializer ?? JsonSerializer.Create(new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All, // lgtm [cs/unsafe-type-name-handling]
TypeNameHandling = TypeNameHandling.All, // CodeQL [cs/unsafe-type-name-handling] Serialization to and from a trusted source for state storage.
MaxDepth = null,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ internal BlobsTranscriptStore(BlobContainerClient containerClient, JsonSerialize

_jsonSerializer = jsonSerializer ?? JsonSerializer.Create(new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All, // lgtm [cs/unsafe-type-name-handling]
TypeNameHandling = TypeNameHandling.All, // CODEQL [cs/unsafe-type-name-handling] we use All so that we get typed roundtrip out of storage, but we don't use validation because we don't know what types are valid
MaxDepth = null,
});
}
Expand Down
3 changes: 1 addition & 2 deletions libraries/Microsoft.Bot.Builder.Azure/AzureBlobStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class AzureBlobStorage : IStorage
{
private static readonly JsonSerializer JsonSerializer = JsonSerializer.Create(new JsonSerializerSettings
{
// we use All so that we get typed roundtrip out of storage, but we don't use validation because we don't know what types are valid
TypeNameHandling = TypeNameHandling.All, // lgtm [cs/unsafe-type-name-handling]
TypeNameHandling = TypeNameHandling.All, // CODEQL [cs/unsafe-type-name-handling] we use All so that we get typed roundtrip out of storage, but we don't use validation because we don't know what types are valid
MaxDepth = null,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CosmosDbPartitionedStorage : IStorage, IDisposable

private readonly JsonSerializer _jsonSerializer = JsonSerializer.Create(new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All, // lgtm [cs/unsafe-type-name-handling]
TypeNameHandling = TypeNameHandling.All, // CODEQL [cs/unsafe-type-name-handling] we use All so that we get typed roundtrip out of storage, but we don't use validation because we don't know what types are valid
MaxDepth = null
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;
Expand All @@ -12,7 +11,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing.TestActions
/// <summary>
/// Test Script action to assert that the bots' reply matches expectations.
/// </summary>
[DebuggerDisplay("AssertReply{Exact ? \"[Exact]\" : string.Empty}:{GetConditionDescription()}")]
[System.Diagnostics.DebuggerDisplay("AssertReply{Exact ? \"[Exact]\" : string.Empty}:{GetConditionDescription()}")]
public class AssertReply : AssertReplyActivity
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -17,7 +16,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing.TestActions
/// <summary>
/// Basic assertion TestAction, which validates assertions against a reply activity.
/// </summary>
[DebuggerDisplay("AssertReplyActivity:{GetConditionDescription()}")]
[System.Diagnostics.DebuggerDisplay("AssertReplyActivity:{GetConditionDescription()}")]
public class AssertReplyActivity : TestAction
{
/// <summary>
Expand Down Expand Up @@ -89,7 +88,7 @@ public override async Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler
{
var timeout = (int)Timeout;

if (Debugger.IsAttached)
if (System.Diagnostics.Debugger.IsAttached)
{
timeout = int.MaxValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;
Expand All @@ -14,7 +13,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing.TestActions
/// <summary>
/// Assertion that reply from the bot matches one of options.
/// </summary>
[DebuggerDisplay("AssertReplyOneOf:{GetConditionDescription()}")]
[System.Diagnostics.DebuggerDisplay("AssertReplyOneOf:{GetConditionDescription()}")]
public class AssertReplyOneOf : AssertReplyActivity
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Adapters;
Expand All @@ -14,7 +13,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing.TestActions
/// <summary>
/// Send an activity to the bot.
/// </summary>
[DebuggerDisplay("UserActivity")]
[System.Diagnostics.DebuggerDisplay("UserActivity")]
public class UserActivity : TestAction
{
/// <summary>
Expand Down Expand Up @@ -74,13 +73,13 @@ public async override Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler
activity.From = ObjectPath.Clone(Activity.From);
}

Stopwatch sw = new Stopwatch();
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();

await adapter.ProcessActivityAsync(activity, callback, default).ConfigureAwait(false);

sw.Stop();
Trace.TraceInformation($"[Turn Ended => {sw.ElapsedMilliseconds} ms processing UserActivity: {Activity.Text} ]");
System.Diagnostics.Trace.TraceInformation($"[Turn Ended => {sw.ElapsedMilliseconds} ms processing UserActivity: {Activity.Text} ]");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Adapters;
Expand All @@ -13,7 +12,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing.TestActions
/// <summary>
/// Action to script sending typing activity to bot.
/// </summary>
[DebuggerDisplay("UserTyping")]
[System.Diagnostics.DebuggerDisplay("UserTyping")]
public class UserTyping : TestAction
{
/// <summary>
Expand Down Expand Up @@ -55,14 +54,14 @@ public async override Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler
typing.From.Name = User;
}

Stopwatch sw = new Stopwatch();
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();

await adapter.ProcessActivityAsync((Activity)typing, callback, default).ConfigureAwait(false);

sw.Stop();

Trace.TraceInformation($"[Turn Ended => {sw.ElapsedMilliseconds} ms processing UserConversationUpdate[]");
System.Diagnostics.Trace.TraceInformation($"[Turn Ended => {sw.ElapsedMilliseconds} ms processing UserConversationUpdate[]");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Adapters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc,
dc.State.SetValue(propValue.Property.GetValue(dc.State), value);
}

// save all state scopes to their respective botState locations.
await dc.Context.TurnState.Get<DialogStateManager>().SaveAllChangesAsync(cancellationToken).ConfigureAwait(false);

return await dc.EndDialogAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc,

dc.State.SetValue(this.Property.GetValue(dc.State), value);

// save all state scopes to their respective botState locations.
await dc.Context.TurnState.Get<DialogStateManager>().SaveAllChangesAsync(cancellationToken).ConfigureAwait(false);

return await dc.EndDialogAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -1047,7 +1046,7 @@ private async Task<bool> QueueFirstMatchAsync(ActionContext actionContext, Dialo
{
var condition = selection[0];
await actionContext.DebuggerStepAsync(condition, dialogEvent, cancellationToken).ConfigureAwait(false);
Trace.TraceInformation($"Executing Dialog: {Id} Rule[{condition.Id}]: {condition.GetType().Name}: {condition.GetExpression()}");
System.Diagnostics.Trace.TraceInformation($"Executing Dialog: {Id} Rule[{condition.Id}]: {condition.GetType().Name}: {condition.GetExpression()}");

var properties = new Dictionary<string, string>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using AdaptiveExpressions.Properties;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Conditions;
using Microsoft.Bot.Builder.Dialogs.Memory;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;

Expand Down Expand Up @@ -312,7 +313,7 @@ private async Task SendOAuthCardAsync(DialogContext dc, IMessageActivity prompt,
// Save state prior to sending OAuthCard: the invoke response for a token exchange from the root bot could come in
// before this method ends or could land in another instance in scale-out scenarios, which means that if the state is not saved,
// the OAuthInput would not be at the top of the stack, and the token exchange invoke would get discarded.
await dc.Context.TurnState.Get<ConversationState>().SaveChangesAsync(dc.Context, false, cancellationToken).ConfigureAwait(false);
await dc.Context.TurnState.Get<DialogStateManager>().SaveAllChangesAsync(cancellationToken).ConfigureAwait(false);

// Prepare OAuthCard
var title = Title == null ? null : await Title.GetValueAsync(dc, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs.Adaptive.Generators;
Expand All @@ -15,7 +14,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Templates
/// Defines an activity Template where the template expression is local aka "inline"
/// and processed through registered IActivityGenerator/ILanguageGenerator.
/// </summary>
[DebuggerDisplay("{Template}")]
[System.Diagnostics.DebuggerDisplay("{Template}")]
[JsonConverter(typeof(ActivityTemplateConverter))]
public class ActivityTemplate : ITemplate<Activity>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Schema;
Expand Down Expand Up @@ -55,7 +54,7 @@ public XUnitDialogTestLogger(ITestOutputHelper xunitOutputHelper)
/// <returns>A task that represents the work queued to execute.</returns>
public async Task OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken))
{
var stopwatch = new Stopwatch();
var stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
context.TurnState[_stopWatchStateKey] = stopwatch;
await LogIncomingActivityAsync(context, context.Activity, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -100,7 +99,7 @@ protected virtual Task LogIncomingActivityAsync(ITurnContext context, Activity a
/// <returns>A task that represents the work to execute.</returns>
protected virtual Task LogOutgoingActivityAsync(ITurnContext context, Activity activity, CancellationToken cancellationToken = default(CancellationToken))
{
var stopwatch = (Stopwatch)context.TurnState[_stopWatchStateKey];
var stopwatch = (System.Diagnostics.Stopwatch)context.TurnState[_stopWatchStateKey];
var actor = "Bot: ";
if (activity.Type == ActivityTypes.Message)
{
Expand Down
7 changes: 7 additions & 0 deletions libraries/Microsoft.Bot.Builder/ActivityFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.Bot.Builder
Expand Down Expand Up @@ -124,6 +125,12 @@ private static Activity BuildActivity(JObject lgJObj)

switch (property.ToLowerInvariant())
{
case "text":
activity["text"] = value.Type == JTokenType.String ? value : value.ToString(Formatting.None);
break;
case "speak":
activity["speak"] = value.Type == JTokenType.String ? value : value.ToString(Formatting.None);
break;
case "attachments":
activity["attachments"] = JArray.FromObject(GetAttachments(value));
break;
Expand Down
2 changes: 1 addition & 1 deletion libraries/Microsoft.Bot.Builder/ChannelServiceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal override async Task<ClaimsIdentity> AuthenticateAsync(string authHeader
if (!isAuthDisabled)
{
// No auth header. Auth is required. Request is not authorized.
throw new UnauthorizedAccessException();
throw new UnauthorizedAccessException("No Authorization header");
}

// In the scenario where auth is disabled, we still want to have the
Expand Down
7 changes: 3 additions & 4 deletions libraries/Microsoft.Bot.Builder/FileTranscriptLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -69,7 +68,7 @@ public async Task LogActivityAsync(IActivity activity)

var transcriptFile = GetTranscriptFile(activity.ChannelId, activity.Conversation.Id);

if (Debugger.IsAttached && activity.Type == ActivityTypes.Message)
if (System.Diagnostics.Debugger.IsAttached && activity.Type == ActivityTypes.Message)
{
System.Diagnostics.Trace.TraceInformation($"{activity.From.Name ?? activity.From.Id ?? activity.From.Role} [{activity.Type}] {activity.AsMessageActivity()?.Text}");
}
Expand All @@ -85,7 +84,7 @@ public async Task LogActivityAsync(IActivity activity)
{
if ((this._unitTestMode == true && !_started.Contains(transcriptFile)) || !File.Exists(transcriptFile))
{
Trace.TraceInformation($"file://{transcriptFile.Replace("\\", "/")}");
System.Diagnostics.Trace.TraceInformation($"file://{transcriptFile.Replace("\\", "/")}");
_started.Add(transcriptFile);

using (var stream = File.OpenWrite(transcriptFile))
Expand Down Expand Up @@ -119,7 +118,7 @@ public async Task LogActivityAsync(IActivity activity)
#pragma warning restore CA1031 // Do not catch general exception types
{
// try again
Trace.TraceError($"Try {i + 1} - Failed to log activity because: {e.GetType()} : {e.Message}");
System.Diagnostics.Trace.TraceError($"Try {i + 1} - Failed to log activity because: {e.GetType()} : {e.Message}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/Microsoft.Bot.Builder/MemoryStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MemoryStorage : IStorage
{
private static readonly JsonSerializer StateJsonSerializer = new JsonSerializer()
{
TypeNameHandling = TypeNameHandling.All, // lgtm [cs/unsafe-type-name-handling]
TypeNameHandling = TypeNameHandling.All, // CODEQL [cs/unsafe-type-name-handling] we use All so that we get typed roundtrip out of storage, but we don't use validation because we don't know what types are valid
ReferenceLoopHandling = ReferenceLoopHandling.Error,
MaxDepth = null
};
Expand Down

0 comments on commit b13e266

Please sign in to comment.