Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }