Versatile OpenID Connect stack for ASP.NET Core and Microsoft.Owin (compatible with ASP.NET 4.6.1)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

47 lines
1.7 KiB

/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/openiddict/openiddict-core for more information concerning
* the license and the contributors participating to this project.
*/
using System.Text;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Http;
using Xunit;
namespace OpenIddict.Client.AspNetCore.Tests;
public class OpenIddictClientAspNetCoreHelpersTests
{
[Fact]
public async Task ReadBackchannelNotificationAsync_ReturnsNotification()
{
// Arrange
var context = new DefaultHttpContext();
context.Request.Method = HttpMethods.Post;
context.Request.ContentType = "application/json";
context.Request.Headers.Authorization = "Bearer 8C3C7A6D";
context.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("""{ "auth_req_id": "F6B3B1E4" }"""));
// Act
var notification = await context.Request.ReadBackchannelNotificationAsync();
// Assert
Assert.NotNull(notification);
Assert.Equal("8C3C7A6D", notification.ClientNotificationToken);
Assert.Equal("F6B3B1E4", notification.AuthenticationRequestId);
}
[Fact]
public async Task ReadBackchannelNotificationAsync_ReturnsNullForNonPostRequests()
{
// Arrange
var context = new DefaultHttpContext();
context.Request.Method = HttpMethods.Get;
context.Request.ContentType = "application/json";
context.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("""{ "auth_req_id": "F6B3B1E4" }"""));
// Act and assert
Assert.Null(await context.Request.ReadBackchannelNotificationAsync());
}
}