|
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.using Microsoft.AspNetCore.Authorization;
|
3 | 3 |
|
4 | 4 | using System;
|
| 5 | +using Microsoft.AspNetCore.Authentication.AzureAD.UI; |
5 | 6 | using Microsoft.AspNetCore.Authentication.Cookies;
|
6 | 7 | using Microsoft.AspNetCore.Authentication.JwtBearer;
|
7 | 8 | using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
8 |
| -using Microsoft.AspNetCore.Authentication.AzureAD.UI; |
9 | 9 | using Microsoft.Extensions.DependencyInjection;
|
10 | 10 | using Microsoft.Extensions.Logging;
|
11 | 11 | using Microsoft.Extensions.Logging.Abstractions;
|
@@ -237,6 +237,28 @@ public void AddAzureAD_ThrowsWhenCookieSchemeIsAlreadyInUse()
|
237 | 237 | Assert.Equal(expectedMessage, exception.Message);
|
238 | 238 | }
|
239 | 239 |
|
| 240 | + [Fact] |
| 241 | + public void AddAzureAD_ThrowsWhenInstanceIsNotSet() |
| 242 | + { |
| 243 | + // Arrange |
| 244 | + var services = new ServiceCollection(); |
| 245 | + services.AddSingleton<ILoggerFactory>(new NullLoggerFactory()); |
| 246 | + |
| 247 | + services.AddAuthentication() |
| 248 | + .AddAzureAD(o => { }); |
| 249 | + |
| 250 | + var provider = services.BuildServiceProvider(); |
| 251 | + var azureADOptionsMonitor = provider.GetService<IOptionsMonitor<AzureADOptions>>(); |
| 252 | + |
| 253 | + var expectedMessage = "The 'Instance' option must be provided."; |
| 254 | + |
| 255 | + // Act & Assert |
| 256 | + var exception = Assert.Throws<OptionsValidationException>( |
| 257 | + () => azureADOptionsMonitor.Get(AzureADDefaults.AuthenticationScheme)); |
| 258 | + |
| 259 | + Assert.Contains(expectedMessage, exception.Failures); |
| 260 | + } |
| 261 | + |
240 | 262 | [Fact]
|
241 | 263 | public void AddAzureADBearer_AddsAllAuthenticationHandlers()
|
242 | 264 | {
|
@@ -400,5 +422,27 @@ public void AddAzureADBearer_ThrowsWhenBearerSchemeIsAlreadyInUse()
|
400 | 422 |
|
401 | 423 | Assert.Equal(expectedMessage, exception.Message);
|
402 | 424 | }
|
| 425 | + |
| 426 | + [Fact] |
| 427 | + public void AddAzureADBearer_ThrowsWhenInstanceIsNotSet() |
| 428 | + { |
| 429 | + // Arrange |
| 430 | + var services = new ServiceCollection(); |
| 431 | + services.AddSingleton<ILoggerFactory>(new NullLoggerFactory()); |
| 432 | + |
| 433 | + services.AddAuthentication() |
| 434 | + .AddAzureADBearer(o => { }); |
| 435 | + |
| 436 | + var provider = services.BuildServiceProvider(); |
| 437 | + var azureADOptionsMonitor = provider.GetService<IOptionsMonitor<AzureADOptions>>(); |
| 438 | + |
| 439 | + var expectedMessage = "The 'Instance' option must be provided."; |
| 440 | + |
| 441 | + // Act & Assert |
| 442 | + var exception = Assert.Throws<OptionsValidationException>( |
| 443 | + () => azureADOptionsMonitor.Get(AzureADDefaults.AuthenticationScheme)); |
| 444 | + |
| 445 | + Assert.Contains(expectedMessage, exception.Failures); |
| 446 | + } |
403 | 447 | }
|
404 | 448 | }
|
0 commit comments