|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Net.Http; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using Microsoft.AspNetCore.Http; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Microsoft.AspNetCore.Authentication.Test.OpenIdConnect |
| 11 | +{ |
| 12 | + public class OpenIdConnectAuthenticateTests |
| 13 | + { |
| 14 | + [Fact] |
| 15 | + public async Task RegularGetRequestToCallbackPathSkips() |
| 16 | + { |
| 17 | + // Arrange |
| 18 | + var settings = new TestSettings( |
| 19 | + opt => |
| 20 | + { |
| 21 | + opt.Authority = TestServerBuilder.DefaultAuthority; |
| 22 | + opt.CallbackPath = new PathString("/"); |
| 23 | + opt.SkipUnrecognizedRequests = true; |
| 24 | + opt.ClientId = "Test Id"; |
| 25 | + }); |
| 26 | + |
| 27 | + var server = settings.CreateTestServer(handler: async context => |
| 28 | + { |
| 29 | + await context.Response.WriteAsync("Hi from the callback path"); |
| 30 | + }); |
| 31 | + |
| 32 | + // Act |
| 33 | + var transaction = await server.SendAsync("/"); |
| 34 | + |
| 35 | + // Assert |
| 36 | + Assert.Equal("Hi from the callback path", transaction.ResponseText); |
| 37 | + } |
| 38 | + |
| 39 | + [Fact] |
| 40 | + public async Task RegularPostRequestToCallbackPathSkips() |
| 41 | + { |
| 42 | + // Arrange |
| 43 | + var settings = new TestSettings( |
| 44 | + opt => |
| 45 | + { |
| 46 | + opt.Authority = TestServerBuilder.DefaultAuthority; |
| 47 | + opt.CallbackPath = new PathString("/"); |
| 48 | + opt.SkipUnrecognizedRequests = true; |
| 49 | + opt.ClientId = "Test Id"; |
| 50 | + }); |
| 51 | + |
| 52 | + var server = settings.CreateTestServer(handler: async context => |
| 53 | + { |
| 54 | + await context.Response.WriteAsync("Hi from the callback path"); |
| 55 | + }); |
| 56 | + |
| 57 | + // Act |
| 58 | + var request = new HttpRequestMessage(HttpMethod.Post, "/"); |
| 59 | + request.Content = new FormUrlEncodedContent(new Dictionary<string, string>()); |
| 60 | + |
| 61 | + var transaction = await server.SendAsync(request, cookieHeader: null); |
| 62 | + |
| 63 | + // Assert |
| 64 | + Assert.Equal("Hi from the callback path", transaction.ResponseText); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments