Skip to content

Commit dfba939

Browse files
authored
Merge pull request #293 from microsoft/users/mbarbour/SyncUps
Syncing updates with Nuget release 1.0.4
2 parents 0eb8c32 + a39ce24 commit dfba939

19 files changed

+162
-47
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ buildd.err
2525
buildd.log
2626
buildd.prf
2727
buildd.wrn
28+
*.binlog
2829
data/
2930
objd/
3031
public/lock

src/Build.Common.StandardAndLegacy.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</PropertyGroup>
55

66
<PropertyGroup Condition="'$(TargetFrameworks)' == ''">
7-
<TargetFrameworks Condition="'$(OutputType)' == 'Exe'">net5.0;net48;net462</TargetFrameworks>
7+
<TargetFrameworks Condition="'$(OutputType)' == 'Exe'">net6.0;net48;net462</TargetFrameworks>
88
<TargetFrameworks Condition="'$(OutputType)' != 'Exe'">netstandard2.0;net48;net462</TargetFrameworks>
99
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1010
</PropertyGroup>

src/Build.Shared.props

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
<Project>
2+
<PropertyGroup>
3+
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
4+
</PropertyGroup>
5+
26
<!-- msbuild properties shared for dotnetCore and .NET classic projects: -->
37
<PropertyGroup>
48
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5-
<PackageVersion_AppInsights>2.9.1</PackageVersion_AppInsights>
9+
<PackageVersion_AppInsights>2.10.0</PackageVersion_AppInsights>
610
<PackageVersion_Adal>3.19.8</PackageVersion_Adal>
711
<PackageVersion_MSAL>4.35.1</PackageVersion_MSAL>
812
<PackageVersion_CdsSdk>4.7.9489-v9.0-master</PackageVersion_CdsSdk>
913
<PackageVersion_CrmProxy>4.7.9409-v9.0-master</PackageVersion_CrmProxy>
1014
<PackageVersion_CDSServerNuget>4.6.6061-weekly-2108.5</PackageVersion_CDSServerNuget>
1115
<PackageVersion_CdsSdkProxy>4.7.6346-master</PackageVersion_CdsSdkProxy>
12-
<PackageVersion_Newtonsoft>11.0.2</PackageVersion_Newtonsoft>
16+
<PackageVersion_Newtonsoft>13.0.1</PackageVersion_Newtonsoft>
1317
<PackageVersion_RestClientRuntime>2.3.20</PackageVersion_RestClientRuntime>
1418
<PackageVersion_XrmSdk>9.0.2.42</PackageVersion_XrmSdk>
1519
<PackageVersion_Dep_OutlookXrmSdk>9.0.2.34</PackageVersion_Dep_OutlookXrmSdk>
@@ -19,9 +23,11 @@
1923
<PackageVersion_Microsoft_Extensions>3.1.8</PackageVersion_Microsoft_Extensions>
2024

2125
<!-- Test: -->
26+
<PackageVersion_MicrosoftNETTestSdk>17.2.0</PackageVersion_MicrosoftNETTestSdk>
27+
<PackageVersion_MSTest>2.2.10</PackageVersion_MSTest>
2228
<PackageVersion_Moq>4.16.0</PackageVersion_Moq>
2329
<PackageVersion_XUnit>2.4.1</PackageVersion_XUnit>
24-
<PackageVersion_XUnitRunner>2.4.3</PackageVersion_XUnitRunner>
30+
<PackageVersion_XUnitRunnerVS>2.4.5</PackageVersion_XUnitRunnerVS>
2531
<PackageVersion_FluentAssertions>5.10.3</PackageVersion_FluentAssertions>
2632

2733
<!-- Assembly attributes are set by cake build. We need to disable autogeneration by msbuild -->

src/GeneralTools/DataverseClient/Client/Auth/MSALHttpHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.PowerPlatform.Dataverse.Client.Auth
1414
{
1515
internal class MSALHttpRetryHandlerHelper : DelegatingHandler
1616
{
17-
private readonly int MaxRetryCount = ClientServiceProviders.Instance.GetService<IOptions<ConfigurationOptions>>().Value.MsalRetryCount;
17+
private readonly int MaxRetryCount = ClientServiceProviders.Instance.GetService<IOptions<ConfigurationOptions>>().Value.MSALRetryCount;
1818

1919
/// <summary>
2020
/// Handel Failure and retry

src/GeneralTools/DataverseClient/Client/ConnectionService.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,20 +1320,20 @@ private async Task<IOrganizationService> InitServiceAsync()
13201320
return null;
13211321
}
13221322

1323-
// Do a WHO AM I request to make sure the connection is good.
1324-
if (!UseExternalConnection)
1325-
{
1326-
Guid guIntialTrackingID = Guid.NewGuid();
1327-
logEntry.Log(string.Format("Beginning Validation of Dataverse Connection. RequestID: {0}", guIntialTrackingID.ToString()));
1328-
dtQueryTimer.Restart();
1329-
user = await GetWhoAmIDetails(dvService, guIntialTrackingID).ConfigureAwait(false);
1330-
dtQueryTimer.Stop();
1331-
logEntry.Log(string.Format(CultureInfo.InvariantCulture, "Validation of Dataverse Connection Complete, total duration: {0}", dtQueryTimer.Elapsed.ToString()));
1332-
}
1333-
else
1334-
{
1335-
logEntry.Log("External Dataverse Connection Provided, Skipping Validation");
1336-
}
1323+
//// Do a WHO AM I request to make sure the connection is good.
1324+
//if (!UseExternalConnection)
1325+
//{
1326+
// Guid guIntialTrackingID = Guid.NewGuid();
1327+
// logEntry.Log(string.Format("Beginning Validation of Dataverse Connection. RequestID: {0}", guIntialTrackingID.ToString()));
1328+
// dtQueryTimer.Restart();
1329+
// user = await GetWhoAmIDetails(dvService, guIntialTrackingID).ConfigureAwait(false);
1330+
// dtQueryTimer.Stop();
1331+
// logEntry.Log(string.Format(CultureInfo.InvariantCulture, "Validation of Dataverse Connection Complete, total duration: {0}", dtQueryTimer.Elapsed.ToString()));
1332+
//}
1333+
//else
1334+
//{
1335+
// logEntry.Log("External Dataverse Connection Provided, Skipping Validation");
1336+
//}
13371337

13381338
return (IOrganizationService)dvService;
13391339

@@ -1528,11 +1528,11 @@ private async Task RefreshInstanceDetails(IOrganizationService dvService, Uri ur
15281528

15291529
var request = new RetrieveCurrentOrganizationRequest() { AccessType = 0, RequestId = trackingID };
15301530
RetrieveCurrentOrganizationResponse resp;
1531-
logEntry.Log(string.Format(CultureInfo.InvariantCulture, "Execute Command - RetrieveCurrentOrganizationRequest : RequestId={0}", dtQueryTimer.Elapsed.ToString()));
1531+
logEntry.Log(string.Format(CultureInfo.InvariantCulture, "Execute Command - RetrieveCurrentOrganizationRequest : RequestId={0}", trackingID));
15321532
if (_configuration.Value.UseWebApiLoginFlow)
15331533
{
15341534
OrganizationResponse orgResp = await Command_WebAPIProcess_ExecuteAsync(
1535-
request, null, false, null, Guid.Empty, false, _configuration.Value.MaxRetryCount, _configuration.Value.RetryPauseTime, new CancellationToken(), uriOfInstance).ConfigureAwait(false);
1535+
request, null, false, null, Guid.Empty, false, _configuration.Value.MaxRetryCount, _configuration.Value.RetryPauseTime, new CancellationToken(), uriOfInstance, true).ConfigureAwait(false);
15361536
try
15371537
{
15381538
resp = (RetrieveCurrentOrganizationResponse)orgResp;
@@ -1643,7 +1643,7 @@ internal async Task<WhoAmIResponse> GetWhoAmIDetails(IOrganizationService dvServ
16431643
if (_configuration.Value.UseWebApiLoginFlow)
16441644
{
16451645
resp = (WhoAmIResponse)(await Command_WebAPIProcess_ExecuteAsync(
1646-
req, null, false, null, Guid.Empty, false, _configuration.Value.MaxRetryCount, _configuration.Value.RetryPauseTime, new CancellationToken()).ConfigureAwait(false));
1646+
req, null, false, null, Guid.Empty, false, _configuration.Value.MaxRetryCount, _configuration.Value.RetryPauseTime, new CancellationToken(), inLoginFlow:true).ConfigureAwait(false));
16471647
}
16481648
else
16491649
{
@@ -1738,11 +1738,11 @@ internal void SetClonedProperties(ServiceClient sourceClient)
17381738
#region WebAPI Interface Utilities
17391739

17401740
internal async Task<OrganizationResponse> Command_WebAPIProcess_ExecuteAsync(OrganizationRequest req, string logMessageTag, bool bypassPluginExecution,
1741-
MetadataUtility metadataUtlity, Guid callerId, bool disableConnectionLocking, int maxRetryCount, TimeSpan retryPauseTime, CancellationToken cancellationToken, Uri uriOfInstance = null)
1741+
MetadataUtility metadataUtlity, Guid callerId, bool disableConnectionLocking, int maxRetryCount, TimeSpan retryPauseTime, CancellationToken cancellationToken, Uri uriOfInstance = null, bool inLoginFlow = false)
17421742
{
17431743
cancellationToken.ThrowIfCancellationRequested();
17441744

1745-
if (!Utilities.IsRequestValidForTranslationToWebAPI(req)) // THIS WILL GET REMOVED AT SOME POINT, TEMP FOR TRANSTION //TODO:REMOVE ON COMPELTE
1745+
if (!Utilities.IsRequestValidForTranslationToWebAPI(req , inLoginFlow)) // THIS WILL GET REMOVED AT SOME POINT, TEMP FOR TRANSTION //TODO:REMOVE ON COMPELTE
17461746
{
17471747
logEntry.Log("Execute Organization Request failed, WebAPI is only supported for limited type of messages at this time.", TraceEventType.Error);
17481748
return null;
@@ -1927,7 +1927,6 @@ internal async Task<OrganizationResponse> Command_WebAPIProcess_ExecuteAsync(Org
19271927
{
19281928
postUri = $"{postUri}?{addedQueryParams}";
19291929
}
1930-
19311930
// Execute request
19321931
var sResp = await Command_WebExecuteAsync(postUri, bodyOfRequest, methodToExecute, headers, "application/json", logMessageTag, callerId, disableConnectionLocking, maxRetryCount, retryPauseTime, uriOfInstance, cancellationToken: cancellationToken).ConfigureAwait(false);
19331932
if (sResp != null && sResp.IsSuccessStatusCode)
@@ -1962,7 +1961,6 @@ internal async Task<OrganizationResponse> Command_WebAPIProcess_ExecuteAsync(Org
19621961
else
19631962
{
19641963
var json = await sResp.Content.ReadAsStringAsync().ConfigureAwait(false);
1965-
19661964
if (_knownTypesFactory.TryCreate($"{req.RequestName}Response", out var response, json))
19671965
{
19681966
OrganizationResponse resp = (OrganizationResponse)response;

src/GeneralTools/DataverseClient/Client/DataverseTraceLogger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal sealed class DataverseTraceLogger : TraceLoggerBase
2424
// Internal connection of exceptions since last clear.
2525
private List<Exception> _ActiveExceptionsList;
2626

27-
private ILogger _logger;
27+
internal ILogger _logger;
2828

2929
#region Properties
3030
/// <summary>
@@ -318,9 +318,9 @@ public void LogFailure(OrganizationRequest req, Guid requestTrackingId, Guid? se
318318

319319
internal string GetFormatedRequestSessionIdString( Guid requestId, Guid? sessionId )
320320
{
321-
return string.Format("RequestID={0} {1}",
321+
return string.Format("RequestID={0}{1}",
322322
requestId.ToString(),
323-
sessionId.HasValue && sessionId.Value != Guid.Empty ? $": SessionID={sessionId.Value.ToString()} : " : "");
323+
sessionId.HasValue && sessionId.Value != Guid.Empty ? $" : SessionID={sessionId.Value.ToString()} : " : "");
324324
}
325325

326326
/// <summary>

src/GeneralTools/DataverseClient/Client/ServiceClient.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ internal WhoAmIResponse SystemUser
390390
return _connectionSvc.CurrentUser;
391391
else
392392
{
393-
WhoAmIResponse resp = _connectionSvc.GetWhoAmIDetails(this).ConfigureAwait(false).GetAwaiter().GetResult();
393+
WhoAmIResponse resp = Task.Run(async () => await _connectionSvc.GetWhoAmIDetails(this).ConfigureAwait(false)).Result;
394394
_connectionSvc.CurrentUser = resp;
395395
return resp;
396396
}
@@ -1056,6 +1056,11 @@ internal void ConnectToService(string connectionString, ILogger logger = null)
10561056
MakeSecureString(password), domainname, string.Empty, string.Empty, useSsl, parsedConnStr.UseUniqueConnectionInstance, null, instanceUrl: parsedConnStr.SkipDiscovery ? parsedConnStr.ServiceUri : null, externalLogger: logger);
10571057

10581058
break;
1059+
case AuthenticationType.ExternalTokenManagement:
1060+
CreateServiceConnection(null, parsedConnStr.AuthenticationType, string.Empty, string.Empty, string.Empty, null,
1061+
string.Empty, null, string.Empty, string.Empty, string.Empty, true, parsedConnStr.UseUniqueConnectionInstance, null,
1062+
string.Empty, null, PromptBehavior.Never, null, string.Empty, StoreName.My, null, parsedConnStr.ServiceUri, externalLogger: logger);
1063+
break;
10591064
}
10601065
}
10611066

@@ -1369,6 +1374,7 @@ public ServiceClient Clone(System.Reflection.Assembly strongTypeAsm, ILogger log
13691374
{
13701375
// Get Current Access Token.
13711376
// This will get the current access token
1377+
if (logger == null) logger = _logEntry._logger;
13721378
proxy.HeaderToken = this.CurrentAccessToken;
13731379
var SvcClient = new ServiceClient(proxy, true, _connectionSvc.AuthenticationTypeInUse, _connectionSvc?.OrganizationVersion, logger: logger);
13741380
SvcClient._connectionSvc.SetClonedProperties(this);

src/GeneralTools/DataverseClient/Client/Utils/Utils.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,15 @@ public static bool IsValidOnlineHost(Uri hostUri)
264264
/// This is a temp method to support the staged transition to the webAPI and will be removed or reintegrated with the overall pipeline at some point in the future.
265265
/// </summary>
266266
/// <param name="req"></param>
267+
/// <param name="inLoginFlow"></param>
267268
/// <returns></returns>
268-
internal static bool IsRequestValidForTranslationToWebAPI(OrganizationRequest req)
269+
internal static bool IsRequestValidForTranslationToWebAPI(OrganizationRequest req, bool inLoginFlow = false)
269270
{
270271
bool useWebApi = ClientServiceProviders.Instance.GetService<IOptions<ConfigurationOptions>>().Value.UseWebApi;
271-
bool useWebApiForLogin = ClientServiceProviders.Instance.GetService<IOptions<ConfigurationOptions>>().Value.UseWebApiLoginFlow;
272+
bool useWebApiForLogin = false;
273+
if (inLoginFlow)
274+
useWebApiForLogin = ClientServiceProviders.Instance.GetService<IOptions<ConfigurationOptions>>().Value.UseWebApiLoginFlow;
275+
272276
switch (req.RequestName.ToLowerInvariant())
273277
{
274278
case "create":

src/GeneralTools/DataverseClient/UnitTests/CdsClient_Core_Tests/DataverseClient_Core_UnitTests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
<Import Project="..\..\..\..\Build.Common.core.props" />
1212

1313
<ItemGroup>
14-
<PackageReference Include="FluentAssertions" Version="5.10.3" />
14+
<PackageReference Include="FluentAssertions" Version="$(PackageVersion_FluentAssertions)" />
1515
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.8" />
1616
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.8" />
1717
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.8" />
18-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
18+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(PackageVersion_MicrosoftNETTestSdk)" />
1919
<PackageReference Include="Moq" Version="$(PackageVersion_Moq)" />
2020
<PackageReference Include="xunit" Version="$(PackageVersion_XUnit)" />
21-
<PackageReference Include="xunit.runner.visualstudio" Version="$(PackageVersion_XUnit)" />
21+
<PackageReference Include="xunit.runner.visualstudio" Version="$(PackageVersion_XUnitRunnerVS)" />
2222
<PackageReference Include="coverlet.collector" Version="1.0.1" />
2323
</ItemGroup>
2424

src/GeneralTools/DataverseClient/UnitTests/CdsClient_Core_Tests/ServiceClientTests.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,50 @@ public void ConnectUsingServiceIdentity_ClientSecret_Consetup()
816816
ValidateConnection(client);
817817
}
818818

819+
[SkippableConnectionTest]
820+
[Trait("Category", "Live Connect Required")]
821+
public void ConnectUsingServiceIdentity_ClientSecret_ExternalAuth_CtorV1()
822+
{
823+
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
824+
var Conn_Url = System.Environment.GetEnvironmentVariable("XUNITCONNTESTURI");
825+
826+
// Connection params.
827+
var client = new ServiceClient(new Uri(Conn_Url), testSupport.GetS2SAccessTokenForRequest , true, Ilogger);
828+
Assert.True(client.IsReady, "Failed to Create Connection via Constructor");
829+
830+
// Validate connection
831+
ValidateConnection(client , usingExternalAuth:true);
832+
}
833+
834+
[SkippableConnectionTest]
835+
[Trait("Category", "Live Connect Required")]
836+
public void ConnectUsingServiceIdentity_ClientSecret_ExternalAuth_Consetup()
837+
{
838+
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
839+
840+
ConnectionOptions connectionOptions = new ConnectionOptions()
841+
{
842+
AccessTokenProviderFunctionAsync = testSupport.GetS2SAccessTokenForRequest,
843+
ServiceUri = new Uri(System.Environment.GetEnvironmentVariable("XUNITCONNTESTURI")),
844+
Logger = Ilogger
845+
};
846+
847+
// Connection params.
848+
var client = new ServiceClient(connectionOptions, deferConnection: true);
849+
Assert.NotNull(client);
850+
Assert.False(client.IsReady, "Client is showing True on Deferred Connection.");
851+
Assert.True(client.Connect(), "Connection was not activated");
852+
Assert.True(client.IsReady, "Failed to Create Connection via Constructor");
853+
854+
// Validate connection
855+
ValidateConnection(client , usingExternalAuth:true);
856+
857+
// test clone
858+
var clientClone = client.Clone();
859+
ValidateConnection(clientClone, usingExternalAuth: true);
860+
}
861+
862+
819863
/// <summary>
820864
/// This Tests connection for UID/PW via connection string - direct connect.
821865
/// </summary>
@@ -977,9 +1021,10 @@ public void ConnectUsingUserIdentity_UIDPW_ConSetup()
9771021

9781022
#region connectionValidationHelper
9791023

980-
private void ValidateConnection(ServiceClient client)
1024+
private void ValidateConnection(ServiceClient client , bool usingExternalAuth = false)
9811025
{
982-
client._connectionSvc.AuthContext.Should().NotBeNull();
1026+
if (!usingExternalAuth)
1027+
client._connectionSvc.AuthContext.Should().NotBeNull();
9831028

9841029
// Validate it
9851030
var rslt = client.Execute(new WhoAmIRequest());

0 commit comments

Comments
 (0)