-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
277 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
....Tests/Extensibility/Implementation/Authentication/TransmissionCredentialEnvelopeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#if !NET452 && !NET46 | ||
namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementation.Authentication | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.ApplicationInsights.Channel; | ||
using Microsoft.ApplicationInsights.DataContracts; | ||
using Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
/// <summary> | ||
/// These tests verify that <see cref="Transmission"/> can receive and store an instance of <see cref="Azure.Core.TokenCredential"/>. | ||
/// </summary> | ||
/// <remarks> | ||
/// These tests do not run in NET452 OR NET46. | ||
/// In these cases, the test runner is NET452 or NET46 and Azure.Core.TokenCredential is NOT SUPPORTED in these frameworks. | ||
/// This does not affect the end user because we REQUIRE the end user to create their own instance of TokenCredential. | ||
/// This ensures that the end user is consuming the AI SDK in one of the newer frameworks. | ||
/// </remarks> | ||
[TestClass] | ||
[TestCategory("AAD")] | ||
public class TransmissionCredentialEnvelopeTests | ||
{ | ||
private readonly Uri testUri = new Uri("https://127.0.0.1/"); | ||
|
||
[TestMethod] | ||
public async Task VerifyTransmissionSendAsync_Default() | ||
{ | ||
var handler = new HandlerForFakeHttpClient | ||
{ | ||
InnerHandler = new HttpClientHandler(), | ||
OnSendAsync = (req, cancellationToken) => | ||
{ | ||
// VALIDATE | ||
Assert.IsNull(req.Headers.Authorization); | ||
return Task.FromResult<HttpResponseMessage>(new HttpResponseMessage()); | ||
} | ||
}; | ||
|
||
using (var fakeHttpClient = new HttpClient(handler)) | ||
{ | ||
var expectedContentType = "content/type"; | ||
var expectedContentEncoding = "contentEncoding"; | ||
var items = new List<ITelemetry> { new EventTelemetry() }; | ||
|
||
// Instantiate Transmission with the mock HttpClient | ||
var transmission = new Transmission(testUri, new byte[] { 1, 2, 3, 4, 5 }, fakeHttpClient, expectedContentType, expectedContentEncoding); | ||
|
||
var result = await transmission.SendAsync(); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public async Task VerifyTransmissionSendAsync_WithCredential_SetsAuthHeader() | ||
{ | ||
var credendialEnvelope = new ReflectionCredentialEnvelope(new MockCredential()); | ||
var token = credendialEnvelope.GetToken(); | ||
|
||
|
||
var handler = new HandlerForFakeHttpClient | ||
{ | ||
InnerHandler = new HttpClientHandler(), | ||
OnSendAsync = (req, cancellationToken) => | ||
{ | ||
// VALIDATE | ||
Assert.AreEqual(AuthConstants.AuthorizationTokenPrefix.Trim(), req.Headers.Authorization.Scheme); | ||
Assert.AreEqual(token, req.Headers.Authorization.Parameter); | ||
return Task.FromResult<HttpResponseMessage>(new HttpResponseMessage()); | ||
} | ||
}; | ||
|
||
using (var fakeHttpClient = new HttpClient(handler)) | ||
{ | ||
var expectedContentType = "content/type"; | ||
var expectedContentEncoding = "contentEncoding"; | ||
var items = new List<ITelemetry> { new EventTelemetry() }; | ||
|
||
// Instantiate Transmission with the mock HttpClient | ||
var transmission = new Transmission(testUri, new byte[] { 1, 2, 3, 4, 5 }, fakeHttpClient, expectedContentType, expectedContentEncoding); | ||
transmission.CredentialEnvelope = credendialEnvelope; | ||
|
||
var result = await transmission.SendAsync(); | ||
} | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.