예제 #1
0
        public async Task TcpCheckAttribute_IsInvalidPortValue()
        {
            const string host = "127.0.0.1";
            const int    port = 5672;

            var settings = await SettingsProcessor.ProcessAsync <TestTcpCheckModel>($"{{'HostInfo': {{'HostPort': '{host}:{port}'}} }}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Failed", message);

            settings = await SettingsProcessor.ProcessAsync <TestTcpCheckModel>($"{{'Host': '{host}', 'Port': 'not a port'}}");

            message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.NotNull(message);
            Assert.Equal($"Check of the 'Host' field value [{host}] is failed: Invalid port value in property 'Port'", message);

            settings = await SettingsProcessor.ProcessAsync <TestTcpCheckModel>($"{{'Host': '{host}', 'Port': '{port}'}}");

            message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Failed", message);

            settings = await SettingsProcessor.ProcessAsync <TestTcpCheckModel>($"{{'Server': '{host}'}}");

            message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Failed", message);
        }
예제 #2
0
        public async Task OkWithOptionalJson()
        {
            var model = await SettingsProcessor.ProcessAsync <TestOptionAttrModel>(_jsonTest);

            CheckModel(model);
            Assert.Null(model.Test4);
            Assert.Null(model.SubObjectOptional);
        }
예제 #3
0
        public void OkWithOptionalJson()
        {
            var model = SettingsProcessor.Process <TestOptionAttrModel>(_jsonTest);

            CheckModel(model);
            Assert.Null(model.Test4);
            Assert.Null(model.SubObjectOptional);
        }
예제 #4
0
        public async Task HttpCheckAttribute_IsInvalidUrl()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestHttpCheckModel>(
                $"{{'Service': {{'ServiceUrl': 'not_url_at_all'}}, 'Url': '{ServiceUrl}/', 'Port':5672, 'Num': 1234}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Failed", message);
        }
예제 #5
0
        public async Task HttpCheckAttribute_IsOk()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestHttpCheckModel>(
                $"{{'Service': {{'ServiceUrl': '{ServiceUrl}'}}, 'Url': '{ServiceUrl}', 'Port':5672, 'Num': 1234}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Null(message);
        }
예제 #6
0
        public async Task HttpCheckAttribute_IsEmptyField()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestHttpCheckModel>(
                $"{{'Service': {{'ServiceUrl': '{ServiceUrl}'}}, 'Url': '', 'Port':5672, 'Num': 1234}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Empty setting value", message);
        }
        protected override async Task <ConfigurationModel> Load()
        {
            var processingResult = await SettingsProcessor.ProcessForConfigurationAsync <ConfigurationModel>(_settingsJson);

            var settings = processingResult.Item1;

            SetSettingsConfigurationRoot(processingResult.Item2);
            return(settings);
        }
예제 #8
0
        public async Task AmqpCheckAttribute_IsInvalidConnectionString()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestAmqpCheckModel>(
                "{'ConnStr': 'amqp://*****:*****@localhost:5672', 'Rabbit': {'ConnString': 'rabbit-registration.lykke-service.svc.cluster.local:5672'}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Contains("Failed", message);
        }
예제 #9
0
        public async Task TcpCheckAttribute_WrongPortProperty()
        {
            var settings = await SettingsProcessor.ProcessAsync <WrongTestTcpCheckModel>("{'Host': '127.0.0.1', 'Port': '5672'}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.NotNull(message);
            Assert.Equal("Check of the 'Host' field value [127.0.0.1] is failed: Property 'ServicePort' not found", message);
        }
예제 #10
0
        public async Task HttpCheckAttribute_IsListOk()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestHttpCheckListModel>(
                $"{{'Services': ['{ServiceUrl}'],'List': ['{ServiceUrl}'],'IList': ['{ServiceUrl}']," +
                $"'RoList': ['{ServiceUrl}'],'RoCollection': ['{ServiceUrl}'],'Enumerable': ['{ServiceUrl}']}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Null(message);
        }
예제 #11
0
        public async Task TcpCheckAttribute_IsInvalidPort()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestTcpCheckModel>(
                "{'HostInfo': {'HostPort': '127.0.0.1:zzz'}, 'Host': '127.0.0.1', 'Port': 5672, 'Server': '127.0.0.1'}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.NotNull(message);
            Assert.Contains("Invalid port", message);
        }
예제 #12
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            OAuthSettings settings = new OAuthSettings();

            if (Environment.IsProduction() && string.IsNullOrEmpty(Configuration["SettingsUrl"]))
            {
                throw new Exception("SettingsUrl is not found");
            }

            if (string.IsNullOrEmpty(Configuration["SettingsUrl"]))
            {
                Configuration.Bind(settings);
            }
            else
            {
                settings = SettingsProcessor.Process <OAuthSettings>(Configuration["SettingsUrl"].GetStringAsync().Result);
            }

            services.AddSingleton <IOAuthSettings>(settings);

            services.AddAuthentication(options => { options.SignInScheme = "ServerCookie"; });

            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.AddCors(options =>
            {
                options.AddPolicy("Lykke", builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials();
                });
            });

            services.AddMvc()
            .AddViewLocalization()
            .AddDataAnnotationsLocalization()
            .AddMvcOptions(o => { o.Filters.Add(typeof(UnhandledExceptionFilter)); });

            services.AddDistributedMemoryCache();

            services.AddAutoMapper();

            services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(30); });

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedProto;
            });

            WebDependencies.Create(services);

            return(ApiDependencies.Create(services, settings));
        }
예제 #13
0
        public async Task AmqpCheckAttribute_IsDictionaryOk()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestAmqpCheckDictionaryModel>("{'Rabbits': {'first': {'ConnString': 'amqp://*****:*****@localhost:5672'}}," +
                                                                                               "'IDict': {'first': {'ConnString': 'amqp://*****:*****@localhost:5672'}}," +

                                                                                               "'RoDict': {'first': {'ConnString': 'amqp://*****:*****@localhost:5672'}}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Null(message);
        }
예제 #14
0
        public async Task TcpCheckAttribute_IsDictionaryOk()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestTcpCheckDictionaryModel>("{'Endpoints': {'first': {'HostPort': '127.0.0.1:5672'}}," +
                                                                                              "'IDict': {'first': {'HostPort': '127.0.0.1:5672'}}," +

                                                                                              "'RoDict': {'first': {'HostPort': '127.0.0.1:5672'}}}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Null(message);
        }
예제 #15
0
        public async Task HttpCheckAttribute_IsDictionaryOk()
        {
            var settings = await SettingsProcessor.ProcessAsync <TestHttpCheckDictioinaryModel>(
                $"{{'Services': {{'first': {{'ServiceUrl': '{ServiceUrl}'}} }}," +
                $"'IDict': {{'first': {{'ServiceUrl': '{ServiceUrl}'}} }}," +
                $"'RoDict': {{'first': {{'ServiceUrl': '{ServiceUrl}'}} }} }}");

            string message = await SettingsProcessor.CheckDependenciesAsync(settings);

            Assert.Null(message);
        }
        public static TestSettings <TValue> FormatJsonString(string value)
        {
            if (null == value)
            {
                return(SettingsProcessor.Process <TestSettings <TValue> >("{ 'value': null }"));
            }

            value = value
                    .Replace(@"\", @"\\")
                    .Replace(@"""", @"\\""")
                    .Replace(@"'", @"\\'");
            value = "\"" + value + "\"";
            return(FormatJson(value));
        }
예제 #17
0
        public async Task Test_NegativeNumbers_IsOk()
        {
            string json = "{'Int': -1234, " +
                          "'Double': -10.4, " +
                          "'Float': -10.4, " +
                          "'Decimal': -10.2}";

            var model = await SettingsProcessor.ProcessAsync <TestConvert>(json);

            Assert.Equal(-1234, model.Int);
            Assert.Equal(-10.4, Math.Round(model.Double, 2));
            Assert.Equal(-10.4, Math.Round(model.Float, 2));
            Assert.Equal((decimal) - 10.2, model.Decimal);
        }
예제 #18
0
        protected override async Task <TSettings> Load()
        {
            Console.WriteLine($"{DateTime.UtcNow} Reading settings");

            var content = await File.ReadAllTextAsync(_settingsFilePath);

            var processingResult = await SettingsProcessor.ProcessForConfigurationAsync <TSettings>(content);

            var settings = processingResult.Item1;

            SetSettingsConfigurationRoot(processingResult.Item2);

            await SettingsProcessor.CheckDependenciesAsync(settings);

            return(settings);
        }
예제 #19
0
        public MessageHandler(TelegramBotClient client, BotMenu botMenu, SettingsProcessor settingsProcessor, ILanguageDetector languageLanguageDetector,
                              ITranslator translator, IMetrics metrics, IOptions <Blacklists> blacklistsOptions, MessageValidator validator, UsersDatabaseService users, GroupsBlacklistService groupsBlacklist)
        {
            _client            = client;
            _botMenu           = botMenu;
            _settingsProcessor = settingsProcessor;
            _translator        = translator;
            _metrics           = metrics;
            _languageDetector  = languageLanguageDetector;
            _blacklist         = blacklistsOptions.Value;
            _validator         = validator;
            _users             = users;
            _groupsBlacklist   = groupsBlacklist;

            _botUsername = _client.GetMeAsync().Result.Username;
        }
예제 #20
0
        public async Task GetSetting()
        {
            var settingsServiceMock = new Mock <ISettingsService>();

            settingsServiceMock.Setup(x => x.GetSetting(It.IsAny <string>())).Returns("value").Verifiable();

            var processor = new SettingsProcessor(settingsServiceMock.Object);

            var result = await processor.ProcessAsync("getsetting", "key");

            settingsServiceMock.Verify(x => x.GetSetting(It.Is <string>(key => key == "key")));

            Assert.NotNull(result);
            Assert.True(result.IsSuccess);

            var dto = result.Content as SettingValueDto;

            Assert.NotNull(dto);
            Assert.Equal("key", dto.Key);
            Assert.Equal("value", dto.Value);
        }
예제 #21
0
        public async Task TcpCheckAttribute_IsArrayOk()
        {
            var checkList = new List <(string, string)>
            {
                ("Endpoints", "127.0.0.1:5672"),
                ("List", "127.0.0.1:5672"),
                ("IList", "127.0.0.1:5672"),
                ("RoList", "127.0.0.1:5672"),
                ("RoCollection", "127.0.0.1:5672"),
                ("Enumerable", "127.0.0.1:5672")
            };

            foreach (var pair in checkList)
            {
                var settings = await SettingsProcessor.ProcessAsync <TestTcpCheckArrayModel>($"{{'{pair.Item1}': [{{'HostPort': '{pair.Item2}'}}] }}");

                string message = await SettingsProcessor.CheckDependenciesAsync(settings);

                Assert.Contains("Failed", message);
            }
        }
예제 #22
0
        public async Task AmqpCheckAttribute_IsListOk()
        {
            var checkList = new List <(string, string)>
            {
                ("Rabbits", "amqp://*****:*****@localhost:5672"),
                ("List", "amqp://*****:*****@localhost:5672"),
                ("IList", "amqp://*****:*****@localhost:5672"),
                ("RoList", "amqp://*****:*****@localhost:5672"),
                ("RoCollection", "amqp://*****:*****@localhost:5672"),
                ("Enumerable", "amqp://*****:*****@localhost:5672")
            };

            foreach (var pair in checkList)
            {
                var settings = await SettingsProcessor.ProcessAsync <TestAmqpCheckListModel>($"{{'{pair.Item1}': ['{pair.Item2}'] }}");

                string message = await SettingsProcessor.CheckDependenciesAsync(settings);

                Assert.Contains("Failed", message);
            }
        }
예제 #23
0
        private static T ReadXml <T>(string fileName)
        {
            var path = Path.Combine(DeploymentEnvironmentVariables.RootDirectory, fileName);

            try
            {
                return(SettingsProcessor.ReadSettings <T>(path));
            }
            catch (UnauthorizedAccessException ex)
            {
                ExitInstallation(ex, $"Failed to read {path}. Access to the file denied", ExitCode.FailedToReadSettings);
            }
            catch (InvalidOperationException ex)
            {
                ExitInstallation(ex, $"Failed to deserialized {path}. Verify that {path} is a valid xml file", ExitCode.FailedToReadSettings);
            }
            catch (Exception ex)
            {
                ExitInstallation(ex, $"Failed to read {path}", ExitCode.FailedToReadSettings);
            }
            return(default(T));
        }
예제 #24
0
 public async Task IncorrectJson()
 {
     await Assert.ThrowsAsync <IncorrectJsonFormatException>(async() => await SettingsProcessor.ProcessAsync <TestModel>(_jsonTest.Substring(10)));
 }
예제 #25
0
        public void OkJson()
        {
            var model = SettingsProcessor.Process <TestModel>(_jsonTest);

            CheckModel(model);
        }
예제 #26
0
        public void SubFieldArrayMissJson()
        {
            var ex = Assert.Throws <RequiredFieldEmptyException>(() => SettingsProcessor.Process <TestModel>(_jsonTest.Replace(@"""test2"":24,", String.Empty)));

            Assert.Equal(ex.FieldName, "SubArray.2.Test2");
        }
예제 #27
0
 public void IncorrectJson()
 {
     Assert.Throws <IncorrectJsonFormatException>(() => SettingsProcessor.Process <TestModel>(_jsonTest.Substring(10)));
 }
예제 #28
0
 public void EmptyJson()
 {
     Assert.Throws <JsonStringEmptyException>(() => SettingsProcessor.Process <TestModel>(string.Empty));
 }
예제 #29
0
        public async Task SubFieldArrayMissJson()
        {
            var ex = await Assert.ThrowsAsync <RequiredFieldEmptyException>(async() => await SettingsProcessor.ProcessAsync <TestModel>(_jsonTest.Replace(@"""test2"":24,", String.Empty)));

            Assert.Equal("SubArray.2.Test2", ex.FieldName);
        }
예제 #30
0
        public async Task OkJson()
        {
            var model = await SettingsProcessor.ProcessAsync <TestModel>(_jsonTest);

            CheckModel(model);
        }