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

            ISettingsProvider         settingsProvider      = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());
            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(null, authenticationService);
        }
        public async void LoginNullAuthenticationValueOnInvoke()
        {
            TestRequestCookieCollection cookies = new TestRequestCookieCollection();

            cookies.AddCookie("RememberMe", "1");

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

            IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService;
            TestHttpContext       httpContext    = new TestHttpContext(httpRequest, httpResponse);
            MockLoginProvider     loginProvider  = new MockLoginProvider();

            ISettingsProvider  settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory());
            MockClaimsProvider claimsProvider   = new MockClaimsProvider(pluginServices);
            RequestDelegate    requestDelegate  = async(context) => { await Task.Delay(0); };

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

            await login.Invoke(httpContext, null);
        }