mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 12:50:49 +08:00 
			
		
		
		
	Can authorise routes based on claims, there is also a claims transformation middleware
This commit is contained in:
		@@ -4,7 +4,6 @@ using System.Security.Claims;
 | 
			
		||||
using Microsoft.AspNetCore.Http;
 | 
			
		||||
using Microsoft.Extensions.Primitives;
 | 
			
		||||
using Moq;
 | 
			
		||||
using Ocelot.Claims.Parser;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
using Ocelot.Errors;
 | 
			
		||||
using Ocelot.HeaderBuilder;
 | 
			
		||||
@@ -15,11 +14,13 @@ using Xunit;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.HeaderBuilder
 | 
			
		||||
{
 | 
			
		||||
    using Ocelot.Infrastructure.Claims.Parser;
 | 
			
		||||
 | 
			
		||||
    public class AddHeadersToRequestTests
 | 
			
		||||
    {
 | 
			
		||||
        private readonly AddHeadersToRequest _addHeadersToRequest;
 | 
			
		||||
        private readonly Mock<IClaimsParser> _parser;
 | 
			
		||||
        private List<ClaimToHeader> _configuration;
 | 
			
		||||
        private List<ClaimToThing> _configuration;
 | 
			
		||||
        private HttpContext _context;
 | 
			
		||||
        private Response _result;
 | 
			
		||||
        private Response<string> _claimValue;
 | 
			
		||||
@@ -42,9 +43,9 @@ namespace Ocelot.UnitTests.HeaderBuilder
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            this.Given(
 | 
			
		||||
                x => x.GivenConfigurationHeaderExtractorProperties(new List<ClaimToHeader>
 | 
			
		||||
                x => x.GivenConfigurationHeaderExtractorProperties(new List<ClaimToThing>
 | 
			
		||||
                {
 | 
			
		||||
                    new ClaimToHeader("header-key", "", "", 0)
 | 
			
		||||
                    new ClaimToThing("header-key", "", "", 0)
 | 
			
		||||
                }))
 | 
			
		||||
                .Given(x => x.GivenHttpContext(context))
 | 
			
		||||
                .And(x => x.GivenTheClaimParserReturns(new OkResponse<string>("value")))
 | 
			
		||||
@@ -68,9 +69,9 @@ namespace Ocelot.UnitTests.HeaderBuilder
 | 
			
		||||
            context.Request.Headers.Add("header-key", new StringValues("initial"));
 | 
			
		||||
 | 
			
		||||
            this.Given(
 | 
			
		||||
                x => x.GivenConfigurationHeaderExtractorProperties(new List<ClaimToHeader>
 | 
			
		||||
                x => x.GivenConfigurationHeaderExtractorProperties(new List<ClaimToThing>
 | 
			
		||||
                {
 | 
			
		||||
                    new ClaimToHeader("header-key", "", "", 0)
 | 
			
		||||
                    new ClaimToThing("header-key", "", "", 0)
 | 
			
		||||
                }))
 | 
			
		||||
                .Given(x => x.GivenHttpContext(context))
 | 
			
		||||
                .And(x => x.GivenTheClaimParserReturns(new OkResponse<string>("value")))
 | 
			
		||||
@@ -84,9 +85,9 @@ namespace Ocelot.UnitTests.HeaderBuilder
 | 
			
		||||
        public void should_return_error()
 | 
			
		||||
        {
 | 
			
		||||
            this.Given(
 | 
			
		||||
               x => x.GivenConfigurationHeaderExtractorProperties(new List<ClaimToHeader>
 | 
			
		||||
               x => x.GivenConfigurationHeaderExtractorProperties(new List<ClaimToThing>
 | 
			
		||||
               {
 | 
			
		||||
                    new ClaimToHeader("", "", "", 0)
 | 
			
		||||
                    new ClaimToThing("", "", "", 0)
 | 
			
		||||
               }))
 | 
			
		||||
               .Given(x => x.GivenHttpContext(new DefaultHttpContext()))
 | 
			
		||||
               .And(x => x.GivenTheClaimParserReturns(new ErrorResponse<string>(new List<Error>
 | 
			
		||||
@@ -104,7 +105,7 @@ namespace Ocelot.UnitTests.HeaderBuilder
 | 
			
		||||
            header.Value.First().ShouldBe(_claimValue.Data);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenConfigurationHeaderExtractorProperties(List<ClaimToHeader> configuration)
 | 
			
		||||
        private void GivenConfigurationHeaderExtractorProperties(List<ClaimToThing> configuration)
 | 
			
		||||
        {
 | 
			
		||||
            _configuration = configuration;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user