public async void RemoteLoadAsync_ConfigServerReturnsLessThanBadRequest()
        {
            // Arrange
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Response     = "";
            TestConfigServerStartup.ReturnStatus = 204;
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);



            ConfigServerClientSettings settings = new ConfigServerClientSettings();

            settings.Uri       = "http://localhost:8888";
            settings.Name      = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient(), envir);
            string path = provider.GetConfigServerUri(null);

            // Act and Assert
            ConfigEnvironment result = await provider.RemoteLoadAsync(path);

            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value);
            Assert.Null(result);
        }
        public void GetConfigServerUri_NoLabel()
        {
            // Arrange
            ConfigServerClientSettings settings = new ConfigServerClientSettings() { Name = "myName", Environment = "Production" };
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);

            // Act and Assert
            string path = provider.GetConfigServerUri();
            Assert.Equal(settings.Uri + "/" + settings.Name + "/" + settings.Environment, path);
        }
        public async void RemoteLoadAsync_ConfigServerReturnsGood()
        {
            // Arrange
            var environment           = @"
{
    'name': 'testname',
    'profiles': ['Production'],
    'label': 'testlabel',
    'version': 'testversion',
    'propertySources': [ 
        { 
            'name': 'source',
            'source': {
                'key1': 'value1',
                'key2': 10
            }
        }
    ]
}";
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Response     = environment;
            TestConfigServerStartup.ReturnStatus = 200;
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);


            ConfigServerClientSettings settings = new ConfigServerClientSettings();

            settings.Uri       = "http://localhost:8888";
            settings.Name      = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient(), envir);
            string path = provider.GetConfigServerUri(null);

            // Act and Assert
            ConfigEnvironment env = await provider.RemoteLoadAsync(path);

            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value);
            Assert.NotNull(env);
            Assert.Equal("testname", env.Name);
            Assert.NotNull(env.Profiles);
            Assert.Equal(1, env.Profiles.Count);
            Assert.Equal("testlabel", env.Label);
            Assert.Equal("testversion", env.Version);
            Assert.NotNull(env.PropertySources);
            Assert.Equal(1, env.PropertySources.Count);
            Assert.Equal("source", env.PropertySources[0].Name);
            Assert.NotNull(env.PropertySources[0].Source);
            Assert.Equal(2, env.PropertySources[0].Source.Count);
            Assert.Equal("value1", env.PropertySources[0].Source["key1"]);
            Assert.Equal((long)10, env.PropertySources[0].Source["key2"]);
        }
Example #4
0
        public void GetConfigServerUri_NoBaseUri_Throws()
        {
            // Arrange
            ConfigServerClientSettings settings = new ConfigServerClientSettings()
            {
                Name = "myName", Environment = "Production"
            };
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);

            // Act and Assert
            Assert.Throws <ArgumentException>(() => provider.GetConfigServerUri(null, null));
        }
Example #5
0
        public void GetConfigServerUri_WithEndingSlash()
        {
            // Arrange
            ConfigServerClientSettings settings = new ConfigServerClientSettings()
            {
                Uri = "http://localhost:9999/", Name = "myName", Environment = "Production"
            };
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);

            // Act and Assert
            string path = provider.GetConfigServerUri(settings.RawUris[0], null);

            Assert.Equal("http://localhost:9999/" + settings.Name + "/" + settings.Environment, path);
        }
Example #6
0
        public void GetConfigServerUri_WithLabelContainingSlash()
        {
            // Arrange
            ConfigServerClientSettings settings = new ConfigServerClientSettings()
            {
                Name = "myName", Environment = "Production", Label = "myLabel/version"
            };
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);

            // Act and Assert
            string path = provider.GetConfigServerUri(settings.RawUris[0], settings.Label);

            Assert.Equal(settings.RawUris[0] + settings.Name + "/" + settings.Environment + "/" + "myLabel(_)version", path);
        }
Example #7
0
        public void GetConfigServerUri_NoLabel()
        {
            // Arrange
            ConfigServerClientSettings settings = new ConfigServerClientSettings()
            {
                Name = "myName", Environment = "Production"
            };
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);

            // Act and Assert
            string path = provider.GetConfigServerUri(settings.RawUris[0], null);

            Assert.Equal(settings.RawUris[0] + settings.Name + "/" + settings.Environment, path);
        }
        public void GetConfigServerUri_WithExtraPathInfo()
        {
            // Arrange
            var settings = new ConfigServerClientSettings()
            {
                Uri = "http://localhost:9999/myPath/path/", Name = "myName", Environment = "Production"
            };
            var provider = new ConfigServerConfigurationProvider(settings);

            // Act and Assert
            var path = provider.GetConfigServerUri(settings.RawUris[0], null);

            Assert.Equal("http://localhost:9999/myPath/path/" + settings.Name + "/" + settings.Environment, path);
        }
        public void GetConfigServerUri_WithLabel()
        {
            // Arrange
            var settings = new ConfigServerClientSettings()
            {
                Name = "myName", Environment = "Production", Label = "myLabel"
            };
            var provider = new ConfigServerConfigurationProvider(settings);

            // Act and Assert
            var path = provider.GetConfigServerUri(settings.RawUris[0], settings.Label);

            Assert.Equal(settings.RawUris[0] + settings.Name + "/" + settings.Environment + "/" + settings.Label, path);
        }
        public void GetConfigServerUri_NoEndingSlash()
        {
            // Arrange
            IHostingEnvironment        env      = new HostingEnvironment();
            ConfigServerClientSettings settings = new ConfigServerClientSettings()
            {
                Uri = "http://localhost:9999", Name = "myName", Environment = "Production"
            };
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, env);

            // Act and Assert
            string path = provider.GetConfigServerUri(null);

            Assert.Equal("http://localhost:9999/" + settings.Name + "/" + settings.Environment, path);
        }
        public void GetConfigServerUri_WithLabel()
        {
            // Arrange
            IHostingEnvironment        env      = new HostingEnvironment();
            ConfigServerClientSettings settings = new ConfigServerClientSettings()
            {
                Name = "myName", Environment = "Production", Label = "myLabel"
            };
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, env);

            // Act and Assert
            string path = provider.GetConfigServerUri(settings.Label);

            Assert.Equal(settings.RawUri + settings.Name + "/" + settings.Environment + "/" + settings.Label, path);
        }
        public void GetRequestMessage_AddsBasicAuthIfPassword()
        {
            ConfigServerClientSettings settings = new ConfigServerClientSettings();

            settings.Uri         = "http://*****:*****@localhost:8888/";
            settings.Name        = "foo";
            settings.Environment = "development";
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);

            string requestURI = provider.GetConfigServerUri(null);
            var    request    = provider.GetRequestMessage(requestURI);

            Assert.Equal(HttpMethod.Get, request.Method);
            Assert.Equal(requestURI, request.RequestUri.ToString());
            Assert.NotNull(request.Headers.Authorization);
            Assert.Equal("Basic", request.Headers.Authorization.Scheme);
            Assert.Equal(provider.GetEncoded("user", "password"), request.Headers.Authorization.Parameter);
        }
        public void GetRequestMessage_AddsVaultToken_IfNeeded()
        {
            ConfigServerClientSettings settings = new ConfigServerClientSettings();

            settings.Uri         = "http://localhost:8888/";
            settings.Name        = "foo";
            settings.Environment = "development";
            settings.Token       = "MyVaultToken";
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings);

            string requestURI = provider.GetConfigServerUri(null);
            var    request    = provider.GetRequestMessage(requestURI);

            Assert.Equal(HttpMethod.Get, request.Method);
            Assert.Equal(requestURI, request.RequestUri.ToString());
            Assert.True(request.Headers.Contains(ConfigServerConfigurationProvider.TOKEN_HEADER));
            var headerValues = request.Headers.GetValues(ConfigServerConfigurationProvider.TOKEN_HEADER);

            Assert.Contains("MyVaultToken", headerValues);
        }
        public async void RemoteLoadAsync_ConfigServerReturnsGreaterThanEqualBadRequest()
        {
            // Arrange
            IHostingEnvironment envir = new HostingEnvironment();

            TestConfigServerStartup.Response     = string.Empty;
            TestConfigServerStartup.ReturnStatus = 500;
            var builder = new WebHostBuilder().UseStartup <TestConfigServerStartup>().UseEnvironment(envir.EnvironmentName);
            var server  = new TestServer(builder);

            ConfigServerClientSettings settings = new ConfigServerClientSettings();

            settings.Uri       = "http://localhost:8888";
            settings.Name      = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());
            string path = provider.GetConfigServerUri(null);

            // Act and Assert
            HttpRequestException ex = await Assert.ThrowsAsync <HttpRequestException>(() => provider.RemoteLoadAsync(path));

            Assert.NotNull(TestConfigServerStartup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, TestConfigServerStartup.LastRequest.Path.Value);
        }
        public async void RemoteLoadAsync_ConfigServerReturnsGood()
        {
            // Arrange
            var environment = @"
{
    'name': 'testname',
    'profiles': ['Production'],
    'label': 'testlabel',
    'version': 'testversion',
    'propertySources': [ 
        { 
            'name': 'source',
            'source': {
                'key1': 'value1',
                'key2': 10
            }
        }
    ]
}";
            var startup = new TestConfigServerStartup(environment, 200);
            var server = TestServer.Create(startup.Configure);
            ConfigServerClientSettings settings = new ConfigServerClientSettings();
            settings.Name = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());
            string path = provider.GetConfigServerUri();

            // Act and Assert
            Environment env = await provider.RemoteLoadAsync(path);
            Assert.NotNull(startup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, startup.LastRequest.Path.Value);
            Assert.NotNull(env);
            Assert.Equal("testname", env.Name);
            Assert.NotNull(env.Profiles);
            Assert.Equal(1, env.Profiles.Count);
            Assert.Equal("testlabel", env.Label);
            Assert.Equal("testversion", env.Version);
            Assert.NotNull(env.PropertySources);
            Assert.Equal(1, env.PropertySources.Count);
            Assert.Equal("source", env.PropertySources[0].Name);
            Assert.NotNull(env.PropertySources[0].Source);
            Assert.Equal(2, env.PropertySources[0].Source.Count);
            Assert.Equal("value1", env.PropertySources[0].Source["key1"]);
            Assert.Equal((long)10, env.PropertySources[0].Source["key2"]);
        }
        public async void RemoteLoadAsync_ConfigServerReturnsNotOkStatus()
        {
            // Arrange
            var startup = new TestConfigServerStartup("",500);
            var server = TestServer.Create(startup.Configure);
            ConfigServerClientSettings settings = new ConfigServerClientSettings();
            settings.Name = "myName";
            server.BaseAddress = new Uri(settings.Uri);
            ConfigServerConfigurationProvider provider = new ConfigServerConfigurationProvider(settings, server.CreateClient());
            string path = provider.GetConfigServerUri();

            // Act and Assert
            Environment result = await provider.RemoteLoadAsync(path);
            Assert.NotNull(startup.LastRequest);
            Assert.Equal("/" + settings.Name + "/" + settings.Environment, startup.LastRequest.Path.Value);
            Assert.Null(result);
        }