Skip to content

Commit

Permalink
Address PR and add UT
Browse files Browse the repository at this point in the history
  • Loading branch information
bgavrilMS committed Oct 29, 2024
1 parent 3c285e3 commit 5f177c6
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 323 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Reflection;
using System.Text.RegularExpressions;

namespace Microsoft.Identity.Web
namespace Microsoft.Identity.Web.Diagnostics
{
internal static class IdHelper
{
Expand Down Expand Up @@ -37,13 +37,13 @@ internal static class IdHelper
});

public static string GetIdWebVersion()
{
{
return s_idWebVersion.Value;
}

public static string CreateTelemetryInfo()
{
return string.Format(CultureInfo.InvariantCulture, IDWebSku + s_idWebVersion.Value);
return string.Format(CultureInfo.InvariantCulture, IDWebSku + GetIdWebVersion());
}
}
}
633 changes: 317 additions & 316 deletions src/Microsoft.Identity.Web.DownstreamApi/DownstreamApi.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Microsoft.Identity.Web.TokenAcquisition\IdHelper.cs" Link="IdHelper.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\README.md">
<Pack>True</Pack>
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Identity.Web.OWIN/AppBuilderExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.Owin.Security.Jwt;
using Microsoft.Owin.Security.OAuth;
using Microsoft.Owin.Security.OpenIdConnect;
using Microsoft.Identity.Web.Diagnostics;
using Owin;

namespace Microsoft.Identity.Web
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Net.Http;
using Microsoft.Identity.Client;
using Microsoft.Identity.Web.Diagnostics;

namespace Microsoft.Identity.Web
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Identity.Web.Diagnostics;

namespace Microsoft.Identity.Web
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,51 @@ public async Task UpdateRequestAsync_WithContent_AddsContentToRequest()
// Arrange
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "https://example.com");
var content = new StringContent("test content");
var options = new DownstreamApiOptions();

// Act
await _input.UpdateRequestAsync(httpRequestMessage, content, new DownstreamApiOptions(), false, null, CancellationToken.None);
await _input.UpdateRequestAsync(httpRequestMessage, content, options, false, null, CancellationToken.None);

// Assert
Assert.Equal(content, httpRequestMessage.Content);
Assert.Equal("application/json", httpRequestMessage.Headers.Accept.Single().MediaType);
Assert.Equal("text/plain", httpRequestMessage.Content?.Headers.ContentType?.MediaType);
Assert.Equal(options.AcquireTokenOptions.ExtraQueryParameters, DownstreamApi.CallerSDKDetails);
}


[Fact]
public async Task UpdateRequestAsync_AddsToExtraQP()
{
// Arrange
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "https://example.com");
var content = new StringContent("test content");
var options = new DownstreamApiOptions() {
AcquireTokenOptions = new AcquireTokenOptions() {
ExtraQueryParameters = new Dictionary<string, string>()
{
{ "n1", "v1" },
{ "n2", "v2" },
{ "caller-sdk-id", "bogus" } // value will be overwritten by the SDK
}
} };

// Act
await _input.UpdateRequestAsync(httpRequestMessage, content, options, false, null, CancellationToken.None);

// Assert
Assert.Equal(content, httpRequestMessage.Content);
Assert.Equal("application/json", httpRequestMessage.Headers.Accept.Single().MediaType);
Assert.Equal("text/plain", httpRequestMessage.Content?.Headers.ContentType?.MediaType);
Assert.Equal("v1", options.AcquireTokenOptions.ExtraQueryParameters["n1"]);
Assert.Equal("v2", options.AcquireTokenOptions.ExtraQueryParameters["n2"]);
Assert.Equal(
DownstreamApi.CallerSDKDetails["caller-sdk-id"],
options.AcquireTokenOptions.ExtraQueryParameters["caller-sdk-id"] );
Assert.Equal(
DownstreamApi.CallerSDKDetails["caller-sdk-ver"],
options.AcquireTokenOptions.ExtraQueryParameters["caller-sdk-ver"]);

}

[Theory]
Expand All @@ -83,6 +120,7 @@ public async Task UpdateRequestAsync_WithScopes_AddsAuthorizationHeaderToRequest
Assert.Equal("ey", httpRequestMessage.Headers.Authorization?.Parameter);
Assert.Equal("Bearer", httpRequestMessage.Headers.Authorization?.Scheme);
Assert.Equal("application/json", httpRequestMessage.Headers.Accept.Single().MediaType);
Assert.Equal(options.AcquireTokenOptions.ExtraQueryParameters, DownstreamApi.CallerSDKDetails);
}

[Fact]
Expand Down

0 comments on commit 5f177c6

Please sign in to comment.