mirror of
https://github.com/bitwarden/server.git
synced 2025-04-23 22:15:10 -05:00

- Add Authorize<T> attribute - Add IOrganizationRequirement and example implementation - Add OrganizationRequirementHandler - Add extension methods (replacing ICurrentContext) - Move custom permissions claim definitions --- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com>
29 lines
903 B
C#
29 lines
903 B
C#
using Bit.Api.AdminConsole.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.Test.AdminConsole.Authorization;
|
|
|
|
public class HttpContextExtensionsTests
|
|
{
|
|
[Fact]
|
|
public async Task WithFeaturesCacheAsync_OnlyExecutesCallbackOnce()
|
|
{
|
|
var httpContext = new DefaultHttpContext();
|
|
var callback = Substitute.For<Func<Task<string>>>();
|
|
callback().Returns(Task.FromResult("hello world"));
|
|
|
|
// Call once
|
|
var result1 = await httpContext.WithFeaturesCacheAsync(callback);
|
|
Assert.Equal("hello world", result1);
|
|
await callback.ReceivedWithAnyArgs(1).Invoke();
|
|
|
|
// Call again - callback not executed again
|
|
var result2 = await httpContext.WithFeaturesCacheAsync(callback);
|
|
Assert.Equal("hello world", result2);
|
|
await callback.ReceivedWithAnyArgs(1).Invoke();
|
|
}
|
|
|
|
}
|