public async Task LoginAutoLoginFromHeadersInvalidEncoding()
        {
            ISettingsProvider       settingsProvider        = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());
            LoginControllerSettings loginControllerSettings = settingsProvider.GetSettings <LoginControllerSettings>(nameof(LoginPlugin));

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

            IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService;
            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); };

            httpRequest.Headers.Add(SharedPluginFeatures.Constants.HeaderAuthorizationName, "Basic blahblahblah");

            LoginMiddleware login = new LoginMiddleware(requestDelegate, loginProvider, settingsProvider,
                                                        claimsProvider);

            await login.Invoke(httpContext, authenticationService);

            Assert.AreEqual(400, httpContext.Response.StatusCode);
            Assert.IsFalse(authenticationService.SignInAsyncCalled);
        }
        public async Task LoginFromCookieValueCookieValidLoginUserFound()
        {
            ISettingsProvider           settingsProvider        = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());
            LoginControllerSettings     loginControllerSettings = settingsProvider.GetSettings <LoginControllerSettings>(nameof(LoginPlugin));
            TestRequestCookieCollection cookies = new TestRequestCookieCollection();

            cookies.AddCookie("RememberMe", Shared.Utilities.Encrypt("123", loginControllerSettings.EncryptionKey));

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

            IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService;
            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); };

            LoginMiddleware login = new LoginMiddleware(requestDelegate, loginProvider, settingsProvider,
                                                        claimsProvider);

            await login.Invoke(httpContext, authenticationService);

            TestResponseCookies responseCookies = httpResponse.Cookies as TestResponseCookies;

            Assert.IsNotNull(responseCookies);
            Assert.IsTrue(authenticationService.SignInAsyncCalled);
        }
        public async Task LoginAutoLoginFromHeadersInvalidUsernameAndPassword()
        {
            ISettingsProvider       settingsProvider        = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());
            LoginControllerSettings loginControllerSettings = settingsProvider.GetSettings <LoginControllerSettings>(nameof(LoginPlugin));

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

            IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService;
            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); };

            string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes("Miley:Cyrus"));

            httpRequest.Headers.Add(SharedPluginFeatures.Constants.HeaderAuthorizationName, "Basic " + encoded);

            LoginMiddleware login = new LoginMiddleware(requestDelegate, loginProvider, settingsProvider,
                                                        claimsProvider);

            await login.Invoke(httpContext, authenticationService);

            Assert.IsFalse(authenticationService.SignInAsyncCalled);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
        public void LoginNullRequestDelegateValue()
        {
            IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService;
            MockLoginProvider     loginProvider  = new MockLoginProvider();

            ISettingsProvider  settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());
            MockClaimsProvider claimsProvider   = new MockClaimsProvider(pluginServices);

            LoginMiddleware login = new LoginMiddleware(null, loginProvider, settingsProvider,
                                                        claimsProvider);
        }
Exemple #8
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);
        }