|
3 | 3 |
|
4 | 4 | using System;
|
5 | 5 | using System.Globalization;
|
| 6 | +using System.Net.Http; |
6 | 7 | using System.Net.Security;
|
7 | 8 | using System.Security.Cryptography.X509Certificates;
|
8 | 9 | using System.Threading.Tasks;
|
@@ -89,5 +90,43 @@ public void ValidateServerCertificateCallback_ServerCertificateValidationCallbac
|
89 | 90 | Assert.IsNotNull(callback);
|
90 | 91 | }
|
91 | 92 | }
|
| 93 | + |
| 94 | + [TestMethod] |
| 95 | + public async Task SFThrowsWhenGetHttpClientWithValidationIsNotImplementedAsync() |
| 96 | + { |
| 97 | + using (new EnvVariableContext()) |
| 98 | + using (var httpManager = new MockHttpManager(isManagedIdentity: true)) |
| 99 | + { |
| 100 | + SetEnvironmentVariables(ManagedIdentitySource.ServiceFabric, "http://localhost:40342/metadata/identity/oauth2/token"); |
| 101 | + var miBuilder = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.SystemAssigned) |
| 102 | + .WithHttpClientFactory(new MsalSFFactoryNotImplementedException()); |
| 103 | + |
| 104 | + // Disabling the shared cache to avoid the test to pass because of the cache |
| 105 | + miBuilder.Config.AccessorOptions = null; |
| 106 | + var mi = miBuilder.BuildConcrete(); |
| 107 | + |
| 108 | + MsalServiceException ex = await Assert.ThrowsExceptionAsync<MsalServiceException>(async () => |
| 109 | + { |
| 110 | + await mi.AcquireTokenForManagedIdentity(Resource) |
| 111 | + .ExecuteAsync().ConfigureAwait(false); |
| 112 | + }).ConfigureAwait(false); |
| 113 | + |
| 114 | + Assert.IsNotNull(ex); |
| 115 | + Assert.IsInstanceOfType(ex.InnerException, typeof(NotImplementedException)); |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + internal class MsalSFFactoryNotImplementedException : IMsalSFHttpClientFactory |
| 121 | + { |
| 122 | + public HttpClient GetHttpClient(Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> validateServerCert) |
| 123 | + { |
| 124 | + throw new NotImplementedException(); |
| 125 | + } |
| 126 | + |
| 127 | + public HttpClient GetHttpClient() |
| 128 | + { |
| 129 | + return new HttpClient(); |
| 130 | + } |
92 | 131 | }
|
93 | 132 | }
|
0 commit comments