Пример #1
0
        public async Task RetrieveUniqueId_InvalidRequest_SiteId_Returns404()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest httpRequest = new TestHttpRequest();

            httpRequest.Path = "/smokeTest/SiteId";
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>();
            IPluginTypesService  pluginTypesService   = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>();

            TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse);
            ILogger         logger      = new Logger();


            using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(null, pluginHelperServices,
                                                                           pluginTypesService, settingsProvider, logger))
            {
                List <WebSmokeTestItem> smokeTests = sut.SmokeTests;

                Assert.IsTrue(smokeTests.Count > 1);

                await sut.Invoke(httpContext);

                Assert.AreEqual(404, httpResponse.StatusCode);
            }
        }
        public SpiderMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider routeProvider,
                                IRouteDataService routeDataService, IPluginHelperService pluginHelperService,
                                IPluginTypesService pluginTypesService, ISettingsProvider settingsProvider)
        {
            if (routeProvider == null)
            {
                throw new ArgumentNullException(nameof(routeProvider));
            }

            if (routeDataService == null)
            {
                throw new ArgumentNullException(nameof(routeDataService));
            }

            if (pluginHelperService == null)
            {
                throw new ArgumentNullException(nameof(pluginHelperService));
            }

            _next = next;

            _userSessionManagerLoaded = pluginHelperService.PluginLoaded("UserSessionMiddleware.Plugin.dll", out int version);

            _deniedSpiderRoutes = new List <DeniedRoute>();
            LoadSpiderData(routeProvider, routeDataService, pluginTypesService);

            SpiderSettings settings = settingsProvider.GetSettings <SpiderSettings>("Spider.Plugin");

            _processStaticFiles = settings.ProcessStaticFiles;

            if (!String.IsNullOrEmpty(settings.StaticFileExtensions))
            {
                _staticFileExtensions = settings.StaticFileExtensions;
            }
        }
Пример #3
0
        public async Task BadEggValidationSuccess()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest  httpRequest  = new TestHttpRequest();
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginClassesService pluginServices       = new pm.PluginServices(_testPluginBadEgg) as IPluginClassesService;
            IPluginHelperService  pluginHelperServices = _testPluginBadEgg.GetRequiredService <IPluginHelperService>();
            IPluginTypesService   pluginTypesService   = _testPluginBadEgg.GetRequiredService <IPluginTypesService>();
            INotificationService  notificationService  = _testPluginBadEgg.GetRequiredService <INotificationService>();
            IIpValidation         iPValidation         = new TestIPValidation();

            TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse);

            httpRequest.SetContext(httpContext);
            MockLoginProvider loginProvider = new MockLoginProvider();

            MockClaimsProvider        claimsProvider                                      = new MockClaimsProvider(pluginServices);
            TestAuthenticationService authenticationService                               = new TestAuthenticationService();
            bool                                   nextDelegateCalled                     = false;
            RequestDelegate                        requestDelegate                        = async(context) => { nextDelegateCalled = true; await Task.Delay(0); };
            ActionDescriptorCollection             actionDescriptorCollection             = new ActionDescriptorCollection(new List <ActionDescriptor>(), 1);
            TestActionDescriptorCollectionProvider testActionDescriptorCollectionProvider = new TestActionDescriptorCollectionProvider(actionDescriptorCollection);
            RouteDataServices                      routeDataServices                      = new RouteDataServices();

            BadEggMiddleware badEgg = new BadEggMiddleware(requestDelegate, testActionDescriptorCollectionProvider,
                                                           routeDataServices, pluginHelperServices, pluginTypesService, iPValidation,
                                                           settingsProvider, notificationService);

            await badEgg.Invoke(httpContext);

            Assert.IsTrue(nextDelegateCalled);
        }
Пример #4
0
        public async Task Validate_TestEndCalled_ISmokeTestProviderNotRegistered_Void()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest httpRequest = new TestHttpRequest();

            httpRequest.Path = "/smokeTest/end/";
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>();
            IPluginTypesService  pluginTypesService   = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>();
            IServiceCollection   serviceCollection    = new ServiceCollection() as IServiceCollection;

            TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse,
                                                              serviceCollection.BuildServiceProvider());
            ILogger         logger             = new Logger();
            bool            nextDelegateCalled = false;
            RequestDelegate requestDelegate    = async(context) => { nextDelegateCalled = true; await Task.Delay(0); };

            using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices,
                                                                           pluginTypesService, settingsProvider, logger))
            {
                List <WebSmokeTestItem> smokeTests = sut.SmokeTests;

                Assert.IsTrue(smokeTests.Count > 1);

                await sut.Invoke(httpContext);

                Assert.IsFalse(nextDelegateCalled);
                Assert.AreEqual(200, httpResponse.StatusCode);
                Assert.IsNull(httpResponse.ContentType);
            }
        }
Пример #5
0
        public RestrictIpMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider routeProvider,
                                    IRouteDataService routeDataService, IPluginHelperService pluginHelperService,
                                    IPluginTypesService pluginTypesService, ISettingsProvider settingsProvider, ILogger logger)
        {
            if (routeProvider == null)
            {
                throw new ArgumentNullException(nameof(routeProvider));
            }

            if (routeDataService == null)
            {
                throw new ArgumentNullException(nameof(routeDataService));
            }

            if (pluginHelperService == null)
            {
                throw new ArgumentNullException(nameof(pluginHelperService));
            }

            _next             = next;
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            _localIpAddresses = new HashSet <string>();
            _restrictedRoutes = new Dictionary <string, List <string> >();
            GetLocalIpAddresses(_localIpAddresses);
            RestrictIpSettings settings = settingsProvider.GetSettings <RestrictIpSettings>("RestrictedIpRoutes.Plugin");

            _disabled = settings.Disabled;

            if (_disabled)
            {
                _logger.AddToLog(LogLevel.Information, RestrictedIpDisabled);
            }

            LoadRestrictedIpRouteData(routeProvider, routeDataService, pluginTypesService, settings);
        }
Пример #6
0
        public BreadcrumbMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider routeProvider,
                                    IRouteDataService routeDataService, IPluginHelperService pluginHelperService,
                                    IPluginTypesService pluginTypesService, ISettingsProvider settingsProvider,
                                    IPluginClassesService pluginClassesService, ILogger logger)
        {
            if (routeProvider == null)
            {
                throw new ArgumentNullException(nameof(routeProvider));
            }

            if (routeDataService == null)
            {
                throw new ArgumentNullException(nameof(routeDataService));
            }

            if (pluginHelperService == null)
            {
                throw new ArgumentNullException(nameof(pluginHelperService));
            }

            if (pluginClassesService == null)
            {
                throw new ArgumentNullException(nameof(pluginClassesService));
            }

            if (pluginTypesService == null)
            {
                throw new ArgumentNullException(nameof(pluginTypesService));
            }

            if (settingsProvider == null)
            {
                throw new ArgumentNullException(nameof(settingsProvider));
            }

            _next   = next;
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (pluginHelperService.PluginLoaded(Constants.PluginNameLocalization, out int _))
            {
                List <IStringLocalizer> stringLocalizers = pluginClassesService.GetPluginClasses <IStringLocalizer>();

                if (stringLocalizers.Count > 0)
                {
                    _stringLocalizer = stringLocalizers[0];
                }
            }

            BreadcrumbSettings settings = settingsProvider.GetSettings <BreadcrumbSettings>(Constants.PluginSettingBreadcrumb);

            _homeBreadCrumb = new BreadcrumbItem(settings.HomeName,
                                                 $"{Constants.ForwardSlash}{settings.HomeController}{Constants.ForwardSlash}{settings.DefaultAction}", false);

            LoadBreadcrumbData(routeProvider, routeDataService, pluginTypesService, settings);

            if (!String.IsNullOrEmpty(settings.StaticFileExtensions))
            {
                _staticFileExtensions = settings.StaticFileExtensions;
            }
        }
Пример #7
0
        public AccountController(ISettingsProvider settingsProvider, IAccountProvider accountProvider,
                                 IDownloadProvider downloadProvider, ICountryProvider countryProvider,
                                 ILicenceProvider licenceProvider, IUserCultureChangeProvider userCultureChanged,
                                 ICultureProvider cultureProvider, IPluginHelperService pluginHelperService)
        {
            _settingsProvider   = settingsProvider ?? throw new ArgumentNullException(nameof(settingsProvider));
            _accountProvider    = accountProvider ?? throw new ArgumentNullException(nameof(accountProvider));
            _downloadProvider   = downloadProvider ?? throw new ArgumentNullException(nameof(downloadProvider));
            _licenceProvider    = licenceProvider ?? throw new ArgumentNullException(nameof(licenceProvider));
            _userCultureChanged = userCultureChanged ?? throw new ArgumentNullException(nameof(userCultureChanged));
            _cultureProvider    = cultureProvider ?? throw new ArgumentNullException(nameof(cultureProvider));

            if (countryProvider == null)
            {
                throw new ArgumentNullException(nameof(countryProvider));
            }

            if (Countries == null)
            {
                Countries = countryProvider.GetVisibleCountries();
            }

            if (LicenceTypes == null)
            {
                LicenceTypes = _licenceProvider.LicenceTypesGet();
            }

            _blogLoaded = pluginHelperService.PluginLoaded("Blog.Plugin.dll", out _);
        }
Пример #8
0
        public void BadEggValidationInvalidRouteProvider()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest  httpRequest  = new TestHttpRequest();
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginClassesService pluginServices       = new pm.PluginServices(_testPluginBadEgg) as IPluginClassesService;
            IPluginHelperService  pluginHelperServices = _testPluginBadEgg.GetRequiredService <IPluginHelperService>();
            IPluginTypesService   pluginTypesService   = _testPluginBadEgg.GetRequiredService <IPluginTypesService>();
            INotificationService  notificationService  = _testPluginBadEgg.GetRequiredService <INotificationService>();
            IIpValidation         iPValidation         = new TestIPValidation();

            TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse);

            httpRequest.SetContext(httpContext);
            MockLoginProvider loginProvider = new MockLoginProvider();

            MockClaimsProvider        claimsProvider        = new MockClaimsProvider(pluginServices);
            TestAuthenticationService authenticationService = new TestAuthenticationService();
            RequestDelegate           requestDelegate       = async(context) => { await Task.Delay(0); };
            RouteDataServices         routeDataServices     = new RouteDataServices();

            BadEggMiddleware badEgg = new BadEggMiddleware(requestDelegate, null,
                                                           routeDataServices, pluginHelperServices, pluginTypesService, iPValidation,
                                                           settingsProvider, notificationService);
        }
Пример #9
0
        public void BadEggValidationInvalidRequestDelegate()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest  httpRequest  = new TestHttpRequest();
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginClassesService pluginServices       = new pm.PluginServices(_testPluginBadEgg) as IPluginClassesService;
            IPluginHelperService  pluginHelperServices = _testPluginBadEgg.GetRequiredService <IPluginHelperService>();
            IPluginTypesService   pluginTypesService   = _testPluginBadEgg.GetRequiredService <IPluginTypesService>();
            INotificationService  notificationService  = _testPluginBadEgg.GetRequiredService <INotificationService>();
            IIpValidation         iPValidation         = new TestIPValidation();

            TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse);

            httpRequest.SetContext(httpContext);
            MockLoginProvider loginProvider = new MockLoginProvider();

            MockClaimsProvider                     claimsProvider                         = new MockClaimsProvider(pluginServices);
            TestAuthenticationService              authenticationService                  = new TestAuthenticationService();
            ActionDescriptorCollection             actionDescriptorCollection             = new ActionDescriptorCollection(new List <ActionDescriptor>(), 1);
            TestActionDescriptorCollectionProvider testActionDescriptorCollectionProvider = new TestActionDescriptorCollectionProvider(actionDescriptorCollection);
            RouteDataServices routeDataServices = new RouteDataServices();

            BadEggMiddleware badEgg = new BadEggMiddleware(null, testActionDescriptorCollectionProvider,
                                                           routeDataServices, pluginHelperServices, pluginTypesService, iPValidation,
                                                           settingsProvider, notificationService);
        }
Пример #10
0
        public async Task Validate_TestStartCalled_ISmokeTestProviderRegistered_Returns_NvpCodecValues()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest httpRequest = new TestHttpRequest();

            httpRequest.Path = "/smokeTest/Start/";
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>();
            IPluginTypesService  pluginTypesService   = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>();
            IServiceCollection   serviceCollection    = new ServiceCollection() as IServiceCollection;
            NVPCodec             codecValues          = new NVPCodec();

            codecValues.Add("username", "admin");
            MockSmokeTestProvider smokeTestProvider = new MockSmokeTestProvider(codecValues);

            serviceCollection.AddSingleton <ISmokeTestProvider>(smokeTestProvider);

            TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse,
                                                              serviceCollection.BuildServiceProvider());
            ILogger         logger             = new Logger();
            bool            nextDelegateCalled = false;
            RequestDelegate requestDelegate    = async(context) => { nextDelegateCalled = true; await Task.Delay(0); };

            using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices,
                                                                           pluginTypesService, settingsProvider, logger))
            {
                List <WebSmokeTestItem> smokeTests = sut.SmokeTests;

                Assert.IsTrue(smokeTests.Count > 1);

                await sut.Invoke(httpContext);

                Assert.IsFalse(nextDelegateCalled);
                Assert.AreEqual(200, httpResponse.StatusCode);
                Assert.IsNull(httpResponse.ContentType);
                Assert.IsTrue(smokeTestProvider.StartCalled);

                byte[] data = new byte[httpResponse.Body.Length];
                httpResponse.Body.Position = 0;
                httpResponse.Body.Read(data, 0, data.Length);
                string test = Decrypt(Encoding.UTF8.GetString(data), EncryptionKey);

                Assert.IsFalse(String.IsNullOrEmpty(test));
                NVPCodec codec = new NVPCodec();
                codec.Decode(test);

                Assert.AreEqual(1, codec.AllKeys.Length);

                Assert.IsTrue(codec.AllKeys.Contains("username"));
                Assert.AreEqual("admin", codec["username"]);
            }
        }
        public BadEggMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider routeProvider,
                                IRouteDataService routeDataService, IPluginHelperService pluginHelperService,
                                IPluginTypesService pluginTypesService, IIpValidation ipValidation,
                                ISettingsProvider settingsProvider, INotificationService notificationService)
        {
            if (routeProvider == null)
            {
                throw new ArgumentNullException(nameof(routeProvider));
            }

            if (routeDataService == null)
            {
                throw new ArgumentNullException(nameof(routeDataService));
            }

            if (pluginHelperService == null)
            {
                throw new ArgumentNullException(nameof(pluginHelperService));
            }

            if (pluginTypesService == null)
            {
                throw new ArgumentNullException(nameof(pluginTypesService));
            }

            if (settingsProvider == null)
            {
                throw new ArgumentNullException(nameof(settingsProvider));
            }

            _next = next;

            _userSessionManagerLoaded = pluginHelperService.PluginLoaded(Constants.PluginNameUserSession, out int version);
            _ipValidation             = ipValidation ?? throw new ArgumentNullException(nameof(ipValidation));
            _notificationService      = notificationService ?? throw new ArgumentNullException(nameof(notificationService));

            _managedRoutes = new List <ManagedRoute>();
            LoadRouteData(routeProvider, routeDataService, pluginTypesService);

            _badEggSettings = settingsProvider.GetSettings <BadEggSettings>("BadEgg.Plugin");

            _validateConnections = new ValidateConnections(
                _badEggSettings.ConnectionTimeOut,
                _badEggSettings.ConnectionsPerMinute);
            _validateConnections.ConnectionAdd      += ValidateConnections_ConnectionAdd;
            _validateConnections.ConnectionRemove   += ValidateConnections_ConnectionRemove;
            _validateConnections.OnReportConnection += ValidateConnections_OnReportConnection;
            _validateConnections.OnBanIPAddress     += ValidateConnections_OnBanIPAddress;

            ThreadManager.ThreadStart(_validateConnections, "Bad Egg Validation", ThreadPriority.Lowest);
        }
        public void TestAddAssembly()
        {
            IPluginHelperService pluginServices = UnitTestHelper.GetPluginServices();

            Assembly current = Assembly.GetExecutingAssembly();

            DynamicLoadResult loadResult = pluginServices.AddAssembly(current);

            Assert.IsTrue(loadResult == DynamicLoadResult.Success);

            pluginServices.PluginLoaded(System.IO.Path.GetFileName(current.Location), out int version);

            Assert.IsTrue(version == 1);
        }
Пример #13
0
        public ProductController(IProductProvider productProvider, ISettingsProvider settingsProvider,
                                 IPluginHelperService pluginHelper, IStockProvider stockProvider)
        {
            if (settingsProvider == null)
            {
                throw new ArgumentNullException(nameof(settingsProvider));
            }

            ProductControllerSettings settings = settingsProvider.GetSettings <ProductControllerSettings>("Products");

            _productProvider = productProvider ?? throw new ArgumentNullException(nameof(productProvider));
            _stockProvider   = stockProvider ?? throw new ArgumentNullException(nameof(stockProvider));
            _productsPerPage = settings.ProductsPerPage;
            _hasShoppingCart = pluginHelper.PluginLoaded(SharedPluginFeatures.Constants.PluginNameShoppingCart, out _);
        }
Пример #14
0
        public void LoadSmokeTests()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>();
            IPluginTypesService  pluginTypesService   = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>();

            ILogger logger = new Logger();

            using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(null, pluginHelperServices,
                                                                           pluginTypesService, settingsProvider, logger))
            {
                List <WebSmokeTestItem> smokeTests = sut.SmokeTests;

                Assert.IsTrue(smokeTests.Count > 1);
            }
        }
Пример #15
0
        public async Task RetrieveUniqueId_ValidRequest_Count_Enabled_Returns200()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest httpRequest = new TestHttpRequest();

            httpRequest.Path = "/smokeTest/Count/";
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>();
            IPluginTypesService  pluginTypesService   = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>();

            TestHttpContext httpContext        = new TestHttpContext(httpRequest, httpResponse);
            ILogger         logger             = new Logger();
            bool            nextDelegateCalled = false;
            RequestDelegate requestDelegate    = async(context) => { nextDelegateCalled = true; await Task.Delay(0); };

            using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices,
                                                                           pluginTypesService, settingsProvider, logger))
            {
                List <WebSmokeTestItem> smokeTests = sut.SmokeTests;

                Assert.IsTrue(smokeTests.Count > 1);
                Assert.IsFalse(nextDelegateCalled);

                await sut.Invoke(httpContext);

                Assert.AreEqual(200, httpResponse.StatusCode);
                byte[] data = new byte[httpResponse.Body.Length];
                httpResponse.Body.Position = 0;
                httpResponse.Body.Read(data, 0, data.Length);
                string count = Decrypt(Encoding.UTF8.GetString(data), EncryptionKey);

                if (Int32.TryParse(count, out int actualCount))
                {
                    Assert.IsTrue(actualCount > 1);
                }
                else
                {
                    throw new InvalidCastException("Failed to convert returned count");
                }
            }
        }
Пример #16
0
        public async Task BadEggValidationIgnoreValidation()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());
            BadEggSettings    badEggSettings   = settingsProvider.GetSettings <BadEggSettings>(SharedPluginFeatures.Constants.BadEggSettingsName);

            TestHttpRequest  httpRequest  = new TestHttpRequest();
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginClassesService pluginServices       = new pm.PluginServices(_testPluginBadEgg) as IPluginClassesService;
            IPluginHelperService  pluginHelperServices = _testPluginBadEgg.GetRequiredService <IPluginHelperService>();
            IPluginTypesService   pluginTypesService   = _testPluginBadEgg.GetRequiredService <IPluginTypesService>();
            INotificationService  notificationService  = _testPluginBadEgg.GetRequiredService <INotificationService>();
            IIpValidation         iPValidation         = new TestIPValidation();
            IIpManagement         ipManagement         = _testPluginBadEgg.GetRequiredService <IIpManagement>();

            TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse);

            httpRequest.SetContext(httpContext);
            MockLoginProvider loginProvider = new MockLoginProvider();

            MockClaimsProvider        claimsProvider                                      = new MockClaimsProvider(pluginServices);
            TestAuthenticationService authenticationService                               = new TestAuthenticationService();
            bool                                   nextDelegateCalled                     = false;
            RequestDelegate                        requestDelegate                        = async(context) => { nextDelegateCalled = true; await Task.Delay(0); };
            ActionDescriptorCollection             actionDescriptorCollection             = new ActionDescriptorCollection(new List <ActionDescriptor>(), 1);
            TestActionDescriptorCollectionProvider testActionDescriptorCollectionProvider = new TestActionDescriptorCollectionProvider(actionDescriptorCollection);
            RouteDataServices                      routeDataServices                      = new RouteDataServices();


            httpRequest.Headers.Add(SharedPluginFeatures.Constants.BadEggValidationIgnoreHeaderName,
                                    badEggSettings.IgnoreValidationHeaderCode);

            BadEggMiddleware badEgg = new BadEggMiddleware(requestDelegate, testActionDescriptorCollectionProvider,
                                                           routeDataServices, pluginHelperServices, pluginTypesService, iPValidation,
                                                           settingsProvider, notificationService);

            await badEgg.Invoke(httpContext);

            Assert.IsTrue(httpContext.Response.Headers.ContainsKey(Constants.BadEggValidationIgnoreHeaderName));
            Assert.AreEqual(httpContext.Response.Headers[Constants.BadEggValidationIgnoreHeaderName], Boolean.TrueString);
            Assert.IsTrue(nextDelegateCalled);
            Assert.AreEqual(200, httpContext.Response.StatusCode);
        }
Пример #17
0
        public async Task Validate_TestStartCalled_ISmokeTestProviderNotRegistered_Returns_EmptyString()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest httpRequest = new TestHttpRequest();

            httpRequest.Path = "/smokeTest/Start/";
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>();
            IPluginTypesService  pluginTypesService   = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>();

            TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse,
                                                              _testPluginSmokeTest.GetServiceProvider());
            ILogger         logger             = new Logger();
            bool            nextDelegateCalled = false;
            RequestDelegate requestDelegate    = async(context) => { nextDelegateCalled = true; await Task.Delay(0); };

            using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices,
                                                                           pluginTypesService, settingsProvider, logger))
            {
                List <WebSmokeTestItem> smokeTests = sut.SmokeTests;

                Assert.IsTrue(smokeTests.Count > 1);

                await sut.Invoke(httpContext);

                Assert.IsFalse(nextDelegateCalled);
                Assert.AreEqual(200, httpResponse.StatusCode);
                Assert.IsNull(httpResponse.ContentType);

                byte[] data = new byte[httpResponse.Body.Length];
                httpResponse.Body.Position = 0;
                httpResponse.Body.Read(data, 0, data.Length);
                string test = Decrypt(Encoding.UTF8.GetString(data), EncryptionKey);

                Assert.IsTrue(String.IsNullOrEmpty(test));
            }
        }
Пример #18
0
        public async Task RetrieveUniqueId_ValidRequest_RetrieveTest_Enabled_Returns200()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest httpRequest = new TestHttpRequest();

            httpRequest.Path = "/smokeTest/Test/1";
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>();
            IPluginTypesService  pluginTypesService   = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>();

            TestHttpContext httpContext        = new TestHttpContext(httpRequest, httpResponse);
            ILogger         logger             = new Logger();
            bool            nextDelegateCalled = false;
            RequestDelegate requestDelegate    = async(context) => { nextDelegateCalled = true; await Task.Delay(0); };

            using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices,
                                                                           pluginTypesService, settingsProvider, logger))
            {
                List <WebSmokeTestItem> smokeTests = sut.SmokeTests;

                Assert.IsTrue(smokeTests.Count > 1);

                await sut.Invoke(httpContext);

                Assert.IsFalse(nextDelegateCalled);
                Assert.AreEqual(200, httpResponse.StatusCode);
                Assert.AreEqual("application/json", httpResponse.ContentType);

                byte[] data = new byte[httpResponse.Body.Length];
                httpResponse.Body.Position = 0;
                httpResponse.Body.Read(data, 0, data.Length);
                string test = Decrypt(Encoding.UTF8.GetString(data), EncryptionKey);

                Assert.IsTrue(test.Contains("Please try again"));
                Assert.IsTrue(test.Contains("Method\":\"POST") || test.Contains("Method\":\"GET"));
            }
        }
Пример #19
0
        public async Task RetrieveUniqueId_ValidRequest_SiteId_Disabled_Returns200()
        {
            ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());

            TestHttpRequest httpRequest = new TestHttpRequest();

            httpRequest.Path = "/smokeTest/SiteId/";
            TestHttpResponse httpResponse = new TestHttpResponse();

            IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>();
            IPluginTypesService  pluginTypesService   = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>();

            TestHttpContext httpContext        = new TestHttpContext(httpRequest, httpResponse);
            ILogger         logger             = new Logger();
            bool            nextDelegateCalled = false;
            RequestDelegate requestDelegate    = async(context) => { nextDelegateCalled = true; await Task.Delay(0); };

            using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices,
                                                                           pluginTypesService, settingsProvider, logger))
            {
                sut.Enabled = false;
                List <WebSmokeTestItem> smokeTests = sut.SmokeTests;

                Assert.IsTrue(smokeTests.Count > 1);

                await sut.Invoke(httpContext);

                Assert.IsTrue(nextDelegateCalled);
                Assert.AreEqual(200, httpResponse.StatusCode);

                byte[] data = new byte[httpResponse.Body.Length];
                httpResponse.Body.Position = 0;
                httpResponse.Body.Read(data, 0, data.Length);
                string id = Encoding.UTF8.GetString(data);

                Assert.AreEqual("", id);
            }
        }
Пример #20
0
        public WebSmokeTestMiddleware(RequestDelegate next,
                                      IPluginHelperService pluginHelperService,
                                      IPluginTypesService pluginTypesService,
                                      ISettingsProvider settingsProvider,
                                      ILogger logger)
        {
            if (pluginHelperService == null)
            {
                throw new ArgumentNullException(nameof(pluginHelperService));
            }

            if (pluginTypesService == null)
            {
                throw new ArgumentNullException(nameof(pluginTypesService));
            }

            if (settingsProvider == null)
            {
                throw new ArgumentNullException(nameof(settingsProvider));
            }

            _testDataStream = new FileStream(_savedData, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
            _next           = next;
            _logger         = logger ?? throw new ArgumentNullException(nameof(logger));

            _settings = settingsProvider.GetSettings <WebSmokeTestSettings>(nameof(WebSmokeTest));

            if (_settings.Enabled)
            {
                LoadSmokeTestData(pluginTypesService);
            }

            if (!String.IsNullOrEmpty(_settings.StaticFileExtensions))
            {
                _staticFileExtensions = _settings.StaticFileExtensions;
            }
        }
Пример #21
0
        public ShoppingCartMiddleware(RequestDelegate next, IShoppingCartService shoppingCartService,
                                      ISettingsProvider settingsProvider, ILogger logger, IPluginHelperService pluginHelperService)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _next = next;
            _shoppingCartService = shoppingCartService ?? throw new ArgumentNullException(nameof(shoppingCartService));

            if (pluginHelperService == null || !pluginHelperService.PluginLoaded(Constants.PluginNameUserSession, out int version))
            {
                logger.AddToLog(LogLevel.Error,
                                new Exception(Constants.UserSessionServiceNotFound),
                                nameof(ShoppingCartMiddleware));
            }

            _cartSettings = settingsProvider.GetSettings <CartSettings>(Constants.ShoppingCart);
        }
 public MockPluginHelperClass(IPluginHelperService pluginHelperService)
 {
     PluginHelperService = pluginHelperService;
 }
 public MockPluginHelperTest(IPluginHelperService pluginHelperService)
     : base(pluginHelperService)
 {
 }