mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 15:10:50 +08:00 
			
		
		
		
	removed another pointless abstraction
This commit is contained in:
		@@ -1,9 +1,5 @@
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore.Authorization;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
using Ocelot.Cache;
 | 
			
		||||
using Ocelot.Configuration.Provider;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Cache
 | 
			
		||||
{
 | 
			
		||||
@@ -11,7 +7,7 @@ namespace Ocelot.Cache
 | 
			
		||||
    [Route("outputcache")]
 | 
			
		||||
    public class OutputCacheController : Controller
 | 
			
		||||
    {
 | 
			
		||||
        private IOcelotCache<CachedResponse> _cache;
 | 
			
		||||
        private readonly IOcelotCache<CachedResponse> _cache;
 | 
			
		||||
 | 
			
		||||
        public OutputCacheController(IOcelotCache<CachedResponse> cache)
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,22 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Configuration.Authentication
 | 
			
		||||
{
 | 
			
		||||
    public class HashMatcher : IHashMatcher
 | 
			
		||||
    {
 | 
			
		||||
        public bool Match(string password, string salt, string hash)
 | 
			
		||||
        {
 | 
			
		||||
            byte[] s = Convert.FromBase64String(salt);
 | 
			
		||||
 | 
			
		||||
            string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
 | 
			
		||||
                password: password,
 | 
			
		||||
                salt: s,
 | 
			
		||||
                prf: KeyDerivationPrf.HMACSHA256,
 | 
			
		||||
                iterationCount: 10000,
 | 
			
		||||
                numBytesRequested: 256 / 8));
 | 
			
		||||
 | 
			
		||||
                return hashed == hash;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +0,0 @@
 | 
			
		||||
namespace Ocelot.Configuration.Authentication
 | 
			
		||||
{
 | 
			
		||||
    public interface IHashMatcher
 | 
			
		||||
    {
 | 
			
		||||
        bool Match(string password, string salt, string hash);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,8 +1,5 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using IdentityServer4.AccessTokenValidation;
 | 
			
		||||
using IdentityServer4.Models;
 | 
			
		||||
using Ocelot.Configuration.Provider;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Configuration.Creator
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -2,34 +2,34 @@ using System;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore.Authorization;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
using Ocelot.Configuration.File;
 | 
			
		||||
using Ocelot.Configuration.Provider;
 | 
			
		||||
using Ocelot.Configuration.Setter;
 | 
			
		||||
using Ocelot.Raft;
 | 
			
		||||
using Rafty.Concensus;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Configuration
 | 
			
		||||
{
 | 
			
		||||
    using Repository;
 | 
			
		||||
 | 
			
		||||
    [Authorize]
 | 
			
		||||
    [Route("configuration")]
 | 
			
		||||
    public class FileConfigurationController : Controller
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IFileConfigurationProvider _configGetter;
 | 
			
		||||
        private readonly IFileConfigurationSetter _configSetter;
 | 
			
		||||
        private readonly IServiceProvider _serviceProvider;
 | 
			
		||||
        private readonly IFileConfigurationRepository _repo;
 | 
			
		||||
        private readonly IFileConfigurationSetter _setter;
 | 
			
		||||
        private readonly IServiceProvider _provider;
 | 
			
		||||
 | 
			
		||||
        public FileConfigurationController(IFileConfigurationProvider getFileConfig, IFileConfigurationSetter configSetter, IServiceProvider serviceProvider)
 | 
			
		||||
        public FileConfigurationController(IFileConfigurationRepository repo, IFileConfigurationSetter setter, IServiceProvider provider)
 | 
			
		||||
        {
 | 
			
		||||
            _configGetter = getFileConfig;
 | 
			
		||||
            _configSetter = configSetter;
 | 
			
		||||
            _serviceProvider = serviceProvider;
 | 
			
		||||
            _repo = repo;
 | 
			
		||||
            _setter = setter;
 | 
			
		||||
            _provider = provider;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [HttpGet]
 | 
			
		||||
        public async Task<IActionResult> Get()
 | 
			
		||||
        {
 | 
			
		||||
            var response = await _configGetter.Get();
 | 
			
		||||
            var response = await _repo.Get();
 | 
			
		||||
 | 
			
		||||
            if(response.IsError)
 | 
			
		||||
            {
 | 
			
		||||
@@ -43,7 +43,7 @@ namespace Ocelot.Configuration
 | 
			
		||||
        public async Task<IActionResult> Post([FromBody]FileConfiguration fileConfiguration)
 | 
			
		||||
        {
 | 
			
		||||
            //todo - this code is a bit shit sort it out..
 | 
			
		||||
            var test = _serviceProvider.GetService(typeof(INode));
 | 
			
		||||
            var test = _provider.GetService(typeof(INode));
 | 
			
		||||
            if (test != null)
 | 
			
		||||
            {
 | 
			
		||||
                var node = (INode)test;
 | 
			
		||||
@@ -56,7 +56,7 @@ namespace Ocelot.Configuration
 | 
			
		||||
                return new OkObjectResult(result.Command.Configuration);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var response = await _configSetter.Set(fileConfiguration);
 | 
			
		||||
            var response = await _setter.Set(fileConfiguration);
 | 
			
		||||
 | 
			
		||||
            if (response.IsError)
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,23 +0,0 @@
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Ocelot.Configuration.File;
 | 
			
		||||
using Ocelot.Configuration.Repository;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Configuration.Provider
 | 
			
		||||
{
 | 
			
		||||
    public class FileConfigurationProvider : IFileConfigurationProvider
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IFileConfigurationRepository _repo;
 | 
			
		||||
 | 
			
		||||
        public FileConfigurationProvider(IFileConfigurationRepository repo)
 | 
			
		||||
        {
 | 
			
		||||
            _repo = repo;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        public async Task<Response<FileConfiguration>> Get()
 | 
			
		||||
        {
 | 
			
		||||
            var fileConfig = await _repo.Get();
 | 
			
		||||
            return new OkResponse<FileConfiguration>(fileConfig.Data);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,11 +0,0 @@
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Ocelot.Configuration.File;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Configuration.Provider
 | 
			
		||||
{
 | 
			
		||||
    public interface IFileConfigurationProvider
 | 
			
		||||
    {
 | 
			
		||||
        Task<Response<FileConfiguration>> Get();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -7,7 +7,7 @@ using Ocelot.Responses;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Configuration.Repository
 | 
			
		||||
{
 | 
			
		||||
    public class FileConfigurationRepository : IFileConfigurationRepository
 | 
			
		||||
    public class DiskFileConfigurationRepository : IFileConfigurationRepository
 | 
			
		||||
    {
 | 
			
		||||
        private readonly string _configFilePath;
 | 
			
		||||
 | 
			
		||||
@@ -15,7 +15,7 @@ namespace Ocelot.Configuration.Repository
 | 
			
		||||
 | 
			
		||||
        private const string ConfigurationFileName = "ocelot";
 | 
			
		||||
 | 
			
		||||
        public FileConfigurationRepository(IHostingEnvironment hostingEnvironment)
 | 
			
		||||
        public DiskFileConfigurationRepository(IHostingEnvironment hostingEnvironment)
 | 
			
		||||
        {
 | 
			
		||||
            _configFilePath = $"{AppContext.BaseDirectory}/{ConfigurationFileName}{(string.IsNullOrEmpty(hostingEnvironment.EnvironmentName) ? string.Empty : ".")}{hostingEnvironment.EnvironmentName}.json";
 | 
			
		||||
        }
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Configuration.Repository
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -6,13 +6,13 @@ using Ocelot.Responses;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.Configuration.Setter
 | 
			
		||||
{
 | 
			
		||||
    public class FileConfigurationSetter : IFileConfigurationSetter
 | 
			
		||||
    public class FileAndInternalConfigurationSetter : IFileConfigurationSetter
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IInternalConfigurationRepository _configRepo;
 | 
			
		||||
        private readonly IInternalConfigurationCreator _configCreator;
 | 
			
		||||
        private readonly IFileConfigurationRepository _repo;
 | 
			
		||||
 | 
			
		||||
        public FileConfigurationSetter(
 | 
			
		||||
        public FileAndInternalConfigurationSetter(
 | 
			
		||||
            IInternalConfigurationRepository configRepo, 
 | 
			
		||||
            IInternalConfigurationCreator configCreator, 
 | 
			
		||||
            IFileConfigurationRepository repo)
 | 
			
		||||
@@ -8,11 +8,9 @@ namespace Ocelot.DependencyInjection
 | 
			
		||||
    using Ocelot.Authorisation;
 | 
			
		||||
    using Ocelot.Cache;
 | 
			
		||||
    using Ocelot.Claims;
 | 
			
		||||
    using Ocelot.Configuration.Authentication;
 | 
			
		||||
    using Ocelot.Configuration.Creator;
 | 
			
		||||
    using Ocelot.Configuration.File;
 | 
			
		||||
    using Ocelot.Configuration.Parser;
 | 
			
		||||
    using Ocelot.Configuration.Provider;
 | 
			
		||||
    using Ocelot.Configuration.Repository;
 | 
			
		||||
    using Ocelot.Configuration.Setter;
 | 
			
		||||
    using Ocelot.Configuration.Validator;
 | 
			
		||||
@@ -40,8 +38,6 @@ namespace Ocelot.DependencyInjection
 | 
			
		||||
    using IdentityServer4.AccessTokenValidation;
 | 
			
		||||
    using Microsoft.AspNetCore.Builder;
 | 
			
		||||
    using Ocelot.Configuration;
 | 
			
		||||
    using Ocelot.Configuration.Builder;
 | 
			
		||||
    using FileConfigurationProvider = Ocelot.Configuration.Provider.FileConfigurationProvider;
 | 
			
		||||
    using Microsoft.Extensions.DependencyInjection.Extensions;
 | 
			
		||||
    using System.Net.Http;
 | 
			
		||||
    using Butterfly.Client.AspNetCore;
 | 
			
		||||
@@ -86,9 +82,8 @@ namespace Ocelot.DependencyInjection
 | 
			
		||||
            _services.TryAddSingleton<IRateLimitOptionsCreator, RateLimitOptionsCreator>();
 | 
			
		||||
            _services.TryAddSingleton<IBaseUrlFinder, BaseUrlFinder>();
 | 
			
		||||
            _services.TryAddSingleton<IRegionCreator, RegionCreator>();
 | 
			
		||||
            _services.TryAddSingleton<IFileConfigurationRepository, FileConfigurationRepository>();
 | 
			
		||||
            _services.TryAddSingleton<IFileConfigurationSetter, FileConfigurationSetter>();
 | 
			
		||||
            _services.TryAddSingleton<IFileConfigurationProvider, FileConfigurationProvider>();
 | 
			
		||||
            _services.TryAddSingleton<IFileConfigurationRepository, DiskFileConfigurationRepository>();
 | 
			
		||||
            _services.TryAddSingleton<IFileConfigurationSetter, FileAndInternalConfigurationSetter>();
 | 
			
		||||
            _services.TryAddSingleton<IQosProviderHouse, QosProviderHouse>();
 | 
			
		||||
            _services.TryAddSingleton<IQoSProviderFactory, QoSProviderFactory>();
 | 
			
		||||
            _services.TryAddSingleton<IServiceDiscoveryProviderFactory, ServiceDiscoveryProviderFactory>();
 | 
			
		||||
@@ -287,7 +282,6 @@ namespace Ocelot.DependencyInjection
 | 
			
		||||
        private void AddIdentityServer(IIdentityServerConfiguration identityServerConfiguration, IAdministrationPath adminPath) 
 | 
			
		||||
        {
 | 
			
		||||
            _services.TryAddSingleton<IIdentityServerConfiguration>(identityServerConfiguration);
 | 
			
		||||
            _services.TryAddSingleton<IHashMatcher, HashMatcher>();
 | 
			
		||||
            var identityServerBuilder = _services
 | 
			
		||||
                .AddIdentityServer(o => {
 | 
			
		||||
                    o.IssuerUri = "Ocelot";
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
using Ocelot.Configuration.Provider;
 | 
			
		||||
using Ocelot.Configuration.Repository;
 | 
			
		||||
using Ocelot.DownstreamRouteFinder.Finder;
 | 
			
		||||
using Ocelot.Infrastructure.Extensions;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,7 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
using Microsoft.Extensions.Options;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
using Ocelot.Configuration.Provider;
 | 
			
		||||
using Ocelot.Configuration.Repository;
 | 
			
		||||
using Ocelot.Middleware;
 | 
			
		||||
using Rafty.Concensus;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,8 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using Ocelot.Authentication;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
using Ocelot.Configuration.Provider;
 | 
			
		||||
using Ocelot.Middleware;
 | 
			
		||||
using Rafty.Concensus;
 | 
			
		||||
using Rafty.FiniteStateMachine;
 | 
			
		||||
@@ -16,13 +12,13 @@ namespace Ocelot.Raft
 | 
			
		||||
    [ExcludeFromCoverage]
 | 
			
		||||
    public class HttpPeer : IPeer
 | 
			
		||||
    {
 | 
			
		||||
        private string _hostAndPort;
 | 
			
		||||
        private HttpClient _httpClient;
 | 
			
		||||
        private JsonSerializerSettings _jsonSerializerSettings;
 | 
			
		||||
        private string _baseSchemeUrlAndPort;
 | 
			
		||||
        private readonly string _hostAndPort;
 | 
			
		||||
        private readonly HttpClient _httpClient;
 | 
			
		||||
        private readonly JsonSerializerSettings _jsonSerializerSettings;
 | 
			
		||||
        private readonly string _baseSchemeUrlAndPort;
 | 
			
		||||
        private BearerToken _token;
 | 
			
		||||
        private IInternalConfiguration _config;
 | 
			
		||||
        private IIdentityServerConfiguration _identityServerConfiguration;
 | 
			
		||||
        private readonly IInternalConfiguration _config;
 | 
			
		||||
        private readonly IIdentityServerConfiguration _identityServerConfiguration;
 | 
			
		||||
 | 
			
		||||
        public HttpPeer(string hostAndPort, HttpClient httpClient, IBaseUrlFinder finder, IInternalConfiguration config, IIdentityServerConfiguration identityServerConfiguration)
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,60 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Moq;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
using Ocelot.Configuration.File;
 | 
			
		||||
using Ocelot.Responses;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using Ocelot.Configuration.Provider;
 | 
			
		||||
using Ocelot.Configuration.Repository;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
{
 | 
			
		||||
    public class FileConfigurationProviderTests
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IFileConfigurationProvider _provider;
 | 
			
		||||
        private Mock<IFileConfigurationRepository> _repo;
 | 
			
		||||
        private FileConfiguration _result;
 | 
			
		||||
        private FileConfiguration _fileConfiguration;
 | 
			
		||||
 | 
			
		||||
        public FileConfigurationProviderTests()
 | 
			
		||||
        {
 | 
			
		||||
            _repo = new Mock<IFileConfigurationRepository>();
 | 
			
		||||
            _provider = new FileConfigurationProvider(_repo.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_return_file_configuration()
 | 
			
		||||
        {
 | 
			
		||||
            var config = new FileConfiguration();
 | 
			
		||||
 | 
			
		||||
            this.Given(x => x.GivenTheConfigurationIs(config))
 | 
			
		||||
                .When(x => x.WhenIGetTheReRoutes())
 | 
			
		||||
                .Then(x => x.ThenTheRepoIsCalledCorrectly())
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheConfigurationIs(FileConfiguration fileConfiguration)
 | 
			
		||||
        {
 | 
			
		||||
            _fileConfiguration = fileConfiguration;
 | 
			
		||||
            _repo
 | 
			
		||||
                .Setup(x => x.Get())
 | 
			
		||||
                .ReturnsAsync(new OkResponse<FileConfiguration>(fileConfiguration));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void WhenIGetTheReRoutes()
 | 
			
		||||
        {
 | 
			
		||||
            _result = _provider.Get().Result.Data;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheRepoIsCalledCorrectly()
 | 
			
		||||
        {
 | 
			
		||||
            _repo
 | 
			
		||||
                .Verify(x => x.Get(), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -23,7 +23,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
        public FileConfigurationRepositoryTests()
 | 
			
		||||
        {
 | 
			
		||||
            _hostingEnvironment.Setup(he => he.EnvironmentName).Returns(_environmentName);
 | 
			
		||||
            _repo = new FileConfigurationRepository(_hostingEnvironment.Object);
 | 
			
		||||
            _repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
@@ -75,7 +75,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
        {
 | 
			
		||||
            _environmentName = null;
 | 
			
		||||
            _hostingEnvironment.Setup(he => he.EnvironmentName).Returns(_environmentName);
 | 
			
		||||
            _repo = new FileConfigurationRepository(_hostingEnvironment.Object);
 | 
			
		||||
            _repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenIHaveAConfiguration(FileConfiguration fileConfiguration)
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
    public class FileConfigurationSetterTests
 | 
			
		||||
    {
 | 
			
		||||
        private FileConfiguration _fileConfiguration;
 | 
			
		||||
        private FileConfigurationSetter _configSetter;
 | 
			
		||||
        private FileAndInternalConfigurationSetter _configSetter;
 | 
			
		||||
        private Mock<IInternalConfigurationRepository> _configRepo;
 | 
			
		||||
        private Mock<IInternalConfigurationCreator> _configCreator;
 | 
			
		||||
        private Response<IInternalConfiguration> _configuration;
 | 
			
		||||
@@ -30,7 +30,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
            _repo = new Mock<IFileConfigurationRepository>();
 | 
			
		||||
            _configRepo = new Mock<IInternalConfigurationRepository>();
 | 
			
		||||
            _configCreator = new Mock<IInternalConfigurationCreator>();
 | 
			
		||||
            _configSetter = new FileConfigurationSetter(_configRepo.Object, _configCreator.Object, _repo.Object);
 | 
			
		||||
            _configSetter = new FileAndInternalConfigurationSetter(_configRepo.Object, _configCreator.Object, _repo.Object);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
 
 | 
			
		||||
@@ -1,76 +0,0 @@
 | 
			
		||||
using Ocelot.Configuration.Authentication;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.Configuration
 | 
			
		||||
{
 | 
			
		||||
    public class HashMatcherTests
 | 
			
		||||
    {
 | 
			
		||||
        private string _password;
 | 
			
		||||
        private string _hash;
 | 
			
		||||
        private string _salt;
 | 
			
		||||
        private bool _result;
 | 
			
		||||
        private HashMatcher _hashMatcher;
 | 
			
		||||
 | 
			
		||||
        public HashMatcherTests()
 | 
			
		||||
        {
 | 
			
		||||
            _hashMatcher = new HashMatcher();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_match_hash()
 | 
			
		||||
        {   
 | 
			
		||||
            var hash = "kE/mxd1hO9h9Sl2VhGhwJUd9xZEv4NP6qXoN39nIqM4=";
 | 
			
		||||
            var salt = "zzWITpnDximUNKYLiUam/w==";
 | 
			
		||||
            var password = "secret";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => GivenThePassword(password))
 | 
			
		||||
                .And(x => GivenTheHash(hash))
 | 
			
		||||
                .And(x => GivenTheSalt(salt))
 | 
			
		||||
                .When(x => WhenIMatch())
 | 
			
		||||
                .Then(x => ThenTheResultIs(true))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [Fact]
 | 
			
		||||
        public void should_not_match_hash()
 | 
			
		||||
        {
 | 
			
		||||
            var hash = "kE/mxd1hO9h9Sl2VhGhwJUd9xZEv4NP6qXoN39nIqM4=";
 | 
			
		||||
            var salt = "zzWITpnDximUNKYLiUam/w==";
 | 
			
		||||
            var password = "secret1";
 | 
			
		||||
 | 
			
		||||
            this.Given(x => GivenThePassword(password))
 | 
			
		||||
                .And(x => GivenTheHash(hash))
 | 
			
		||||
                .And(x => GivenTheSalt(salt))
 | 
			
		||||
                .When(x => WhenIMatch())
 | 
			
		||||
                .Then(x => ThenTheResultIs(false))
 | 
			
		||||
                .BDDfy();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenThePassword(string password)
 | 
			
		||||
        {
 | 
			
		||||
            _password = password;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheHash(string hash)
 | 
			
		||||
        {
 | 
			
		||||
            _hash = hash;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GivenTheSalt(string salt)
 | 
			
		||||
        {
 | 
			
		||||
            _salt = salt;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void WhenIMatch()
 | 
			
		||||
        {
 | 
			
		||||
            _result = _hashMatcher.Match(_password, _salt, _hash);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheResultIs(bool expected)
 | 
			
		||||
        {
 | 
			
		||||
            _result.ShouldBe(expected);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -8,32 +8,30 @@ using Ocelot.Responses;
 | 
			
		||||
using TestStack.BDDfy;
 | 
			
		||||
using Xunit;
 | 
			
		||||
using Shouldly;
 | 
			
		||||
using Ocelot.Configuration.Provider;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
using Ocelot.Raft;
 | 
			
		||||
using Rafty.Concensus;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using Rafty.FiniteStateMachine;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.UnitTests.Controllers
 | 
			
		||||
{
 | 
			
		||||
    using Ocelot.Configuration.Repository;
 | 
			
		||||
 | 
			
		||||
    public class FileConfigurationControllerTests
 | 
			
		||||
    {
 | 
			
		||||
        private FileConfigurationController _controller;
 | 
			
		||||
        private Mock<IFileConfigurationProvider> _configGetter;
 | 
			
		||||
        private Mock<IFileConfigurationSetter> _configSetter;
 | 
			
		||||
        private readonly FileConfigurationController _controller;
 | 
			
		||||
        private readonly Mock<IFileConfigurationRepository> _repo;
 | 
			
		||||
        private readonly Mock<IFileConfigurationSetter> _setter;
 | 
			
		||||
        private IActionResult _result;
 | 
			
		||||
        private FileConfiguration _fileConfiguration;
 | 
			
		||||
        private Mock<IServiceProvider> _provider;
 | 
			
		||||
        private readonly Mock<IServiceProvider> _provider;
 | 
			
		||||
        private Mock<INode> _node;
 | 
			
		||||
 | 
			
		||||
        public FileConfigurationControllerTests()
 | 
			
		||||
        {
 | 
			
		||||
            _provider = new Mock<IServiceProvider>();
 | 
			
		||||
            _configGetter = new Mock<IFileConfigurationProvider>();
 | 
			
		||||
            _configSetter = new Mock<IFileConfigurationSetter>();
 | 
			
		||||
            _controller = new FileConfigurationController(_configGetter.Object, _configSetter.Object, _provider.Object);
 | 
			
		||||
            _repo = new Mock<IFileConfigurationRepository>();
 | 
			
		||||
            _setter = new Mock<IFileConfigurationSetter>();
 | 
			
		||||
            _controller = new FileConfigurationController(_repo.Object, _setter.Object, _provider.Object);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        [Fact]
 | 
			
		||||
@@ -140,14 +138,14 @@ namespace Ocelot.UnitTests.Controllers
 | 
			
		||||
 | 
			
		||||
        private void GivenTheConfigSetterReturns(Response response)
 | 
			
		||||
        {
 | 
			
		||||
            _configSetter
 | 
			
		||||
            _setter
 | 
			
		||||
                .Setup(x => x.Set(It.IsAny<FileConfiguration>()))
 | 
			
		||||
                .ReturnsAsync(response);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ThenTheConfigrationSetterIsCalledCorrectly()
 | 
			
		||||
        {
 | 
			
		||||
            _configSetter
 | 
			
		||||
            _setter
 | 
			
		||||
                .Verify(x => x.Set(_fileConfiguration), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -168,7 +166,7 @@ namespace Ocelot.UnitTests.Controllers
 | 
			
		||||
 | 
			
		||||
        private void GivenTheGetConfigurationReturns(Ocelot.Responses.Response<FileConfiguration> fileConfiguration)
 | 
			
		||||
        {
 | 
			
		||||
            _configGetter
 | 
			
		||||
            _repo
 | 
			
		||||
                .Setup(x => x.Get())
 | 
			
		||||
                .ReturnsAsync(fileConfiguration);
 | 
			
		||||
        }
 | 
			
		||||
@@ -180,7 +178,7 @@ namespace Ocelot.UnitTests.Controllers
 | 
			
		||||
 | 
			
		||||
        private void TheTheGetFileConfigurationIsCalledCorrectly()
 | 
			
		||||
        {
 | 
			
		||||
               _configGetter
 | 
			
		||||
               _repo
 | 
			
		||||
                .Verify(x => x.Get(), Times.Once);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,6 @@
 | 
			
		||||
using Moq;
 | 
			
		||||
using Ocelot.Configuration;
 | 
			
		||||
using Ocelot.Configuration.Builder;
 | 
			
		||||
using Ocelot.Configuration.Creator;
 | 
			
		||||
using Ocelot.Configuration.Provider;
 | 
			
		||||
using Ocelot.DownstreamRouteFinder;
 | 
			
		||||
using Ocelot.DownstreamRouteFinder.Finder;
 | 
			
		||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user