mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 18:00:48 +08:00 
			
		
		
		
	Can authorise routes based on claims, there is also a claims transformation middleware
This commit is contained in:
		@@ -21,14 +21,14 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
        private readonly Mock<IConfigurationValidator> _validator;
 | 
			
		||||
        private Response<IOcelotConfiguration> _config;
 | 
			
		||||
        private YamlConfiguration _yamlConfiguration;
 | 
			
		||||
        private readonly Mock<IClaimToHeaderConfigurationParser> _configParser;
 | 
			
		||||
        private readonly Mock<IClaimToThingConfigurationParser> _configParser;
 | 
			
		||||
        private readonly Mock<ILogger<YamlOcelotConfigurationCreator>> _logger;
 | 
			
		||||
        private readonly YamlOcelotConfigurationCreator _ocelotConfigurationCreator;
 | 
			
		||||
 | 
			
		||||
        public YamlConfigurationCreatorTests()
 | 
			
		||||
        {
 | 
			
		||||
            _logger = new Mock<ILogger<YamlOcelotConfigurationCreator>>();
 | 
			
		||||
            _configParser = new Mock<IClaimToHeaderConfigurationParser>();
 | 
			
		||||
            _configParser = new Mock<IClaimToThingConfigurationParser>();
 | 
			
		||||
            _validator = new Mock<IConfigurationValidator>();
 | 
			
		||||
            _yamlConfig = new Mock<IOptions<YamlConfiguration>>();
 | 
			
		||||
            _ocelotConfigurationCreator = new YamlOcelotConfigurationCreator( 
 | 
			
		||||
@@ -79,9 +79,9 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
                    .WithRequireHttps(false)
 | 
			
		||||
                    .WithScopeSecret("secret")
 | 
			
		||||
                    .WithAuthenticationProviderScopeName("api")
 | 
			
		||||
                    .WithConfigurationHeaderExtractorProperties(new List<ClaimToHeader>
 | 
			
		||||
                    .WithClaimsToHeaders(new List<ClaimToThing>
 | 
			
		||||
                    {
 | 
			
		||||
                        new ClaimToHeader("CustomerId", "CustomerId", "", 0),
 | 
			
		||||
                        new ClaimToThing("CustomerId", "CustomerId", "", 0),
 | 
			
		||||
                    })
 | 
			
		||||
                    .Build()
 | 
			
		||||
            };
 | 
			
		||||
@@ -112,18 +112,18 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
                }
 | 
			
		||||
            }))
 | 
			
		||||
                .And(x => x.GivenTheYamlConfigIsValid())
 | 
			
		||||
                .And(x => x.GivenTheConfigHeaderExtractorReturns(new ClaimToHeader("CustomerId", "CustomerId", "", 0)))
 | 
			
		||||
                .And(x => x.GivenTheConfigHeaderExtractorReturns(new ClaimToThing("CustomerId", "CustomerId", "", 0)))
 | 
			
		||||
                .When(x => x.WhenICreateTheConfig())
 | 
			
		||||
                .Then(x => x.ThenTheReRoutesAre(expected))
 | 
			
		||||
                .And(x => x.ThenTheAuthenticationOptionsAre(expected))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheConfigHeaderExtractorReturns(ClaimToHeader expected)
 | 
			
		||||
        private void GivenTheConfigHeaderExtractorReturns(ClaimToThing expected)
 | 
			
		||||
        {
 | 
			
		||||
            _configParser
 | 
			
		||||
                .Setup(x => x.Extract(It.IsAny<string>(), It.IsAny<string>()))
 | 
			
		||||
                .Returns(new OkResponse<ClaimToHeader>(expected));
 | 
			
		||||
                .Returns(new OkResponse<ClaimToThing>(expected));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user