Ejemplo n.º 1
0
        public void LoginWithLandingPageAfterLogin()
        {
            var expectedSettings = new AuthenticationSettings {
                UserAuthentication = false
            };

            LandingPageMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new LandingPageSettings {
                BeforeLogin = false, Enabled = true
            });
            AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);

            Bootstrapper.WithSession(new Dictionary <string, object>());

            var browser = new Browser(Bootstrapper);
            var result  = browser.Post("/userlogin", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Username", "abc");
            });

            Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
            Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));

            Assert.That(result.Headers.Contains(new KeyValuePair <string, string>("Location", "http://www.landingpage.com/"))); // Redirect header
            AuthMock.Verify(x => x.GetSettingsAsync(), Times.Once);
            PlexMock.Verify(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Never);
        }
Ejemplo n.º 2
0
        public void LoginWithoutAuthenticationWithEmptyUsername()
        {
            var expectedSettings = new AuthenticationSettings {
                UserAuthentication = false
            };

            AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);


            Bootstrapper.WithSession(new Dictionary <string, object>());

            var browser = new Browser(Bootstrapper);
            var result  = browser.Post("/userlogin", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Username", string.Empty);
            });

            Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));


            Assert.That(result.Headers.Contains(new KeyValuePair <string, string>("Location", "http://www.userloginindex.com/"))); // Redirect header
            AuthMock.Verify(x => x.GetSettingsAsync(), Times.Never);
            PlexMock.Verify(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Never);
        }
        public void LoginWithUsernameAndPasswordSuccessfully()
        {
            var expectedSettings = new AuthenticationSettings {
                UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc"
            };
            var plexFriends = new PlexFriends
            {
                User = new[]
                {
                    new UserFriends
                    {
                        Username = "******",
                    }
                }
            };
            var plexAuth = new PlexAuthentication
            {
                user = new User
                {
                    authentication_token = "abc"
                }
            };

            AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
            PlexMock.Setup(x => x.GetUsers(It.IsAny <string>())).Returns(plexFriends);
            PlexMock.Setup(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>())).Returns(plexAuth);
            PlexMock.Setup(x => x.GetAccount(It.IsAny <string>())).Returns(new PlexAccount());

            var bootstrapper = new ConfigurableBootstrapper(with =>
            {
                with.Module <UserLoginModule>();
                with.Dependency(AuthMock.Object);
                with.Dependency(PlexMock.Object);
                with.RootPathProvider <TestRootPathProvider>();
            });

            bootstrapper.WithSession(new Dictionary <string, object>());

            var browser = new Browser(bootstrapper);
            var result  = browser.Post("/userlogin", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Username", "abc");
                with.FormValue("Password", "abc");
            });


            Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
            Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.EqualTo("abc"));

            var body = JsonConvert.DeserializeObject <JsonResponseModel>(result.Body.AsString());

            Assert.That(body.Result, Is.EqualTo(true));
            AuthMock.Verify(x => x.GetSettings(), Times.Once);
            PlexMock.Verify(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Once);
        }
Ejemplo n.º 4
0
        public void LoginWithUsernameAndPasswordUnSuccessfully()
        {
            var expectedSettings = new AuthenticationSettings {
                UserAuthentication = true, UsePassword = true, PlexAuthToken = "abc"
            };
            var plexFriends = new PlexFriends
            {
                User = new[]
                {
                    new UserFriends
                    {
                        Username = "******",
                    },
                }
            };
            var plexAuth = new PlexAuthentication
            {
                user = null
            };

            AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);
            PlexMock.Setup(x => x.GetUsers(It.IsAny <string>())).Returns(plexFriends);
            PlexMock.Setup(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>())).Returns(plexAuth);


            Bootstrapper.WithSession(new Dictionary <string, object>());

            var browser = new Browser(Bootstrapper);
            var result  = browser.Post("/userlogin", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Username", "abc");
                with.FormValue("Password", "abc");
            });


            Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
            Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);

            var body = JsonConvert.DeserializeObject <JsonResponseModel>(result.Body.AsString());

            Assert.That(body.Result, Is.EqualTo(false));
            Assert.That(body.Message, Is.Not.Empty);
            AuthMock.Verify(x => x.GetSettings(), Times.Once);
            PlexMock.Verify(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Never);
        }
Ejemplo n.º 5
0
        public void LoginWithOwnerUsernameAndPasswordSuccessfully()
        {
            var expectedSettings = new AuthenticationSettings {
                UserAuthentication = true, UsePassword = true
            };
            var plexFriends = new PlexFriends
            {
                User = new[]
                {
                    new UserFriends()
                }
            };
            var plexAuth = new PlexAuthentication
            {
                user = new User
                {
                    authentication_token = "abc",
                    username             = "******"
                }
            };

            var account = new PlexAccount {
                Username = "******"
            };

            AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
            PlexMock.Setup(x => x.GetUsers(It.IsAny <string>())).Returns(plexFriends);
            PlexMock.Setup(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>())).Returns(plexAuth);
            PlexMock.Setup(x => x.GetAccount(It.IsAny <string>())).Returns(account);

            Bootstrapper.WithSession(new Dictionary <string, object>());

            var browser = new Browser(Bootstrapper);
            var result  = browser.Post("/userlogin", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Username", "jamie");
                with.FormValue("Password", "abc");
            });

            Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
            Assert.That(result.Headers.Contains(new KeyValuePair <string, string>("Location", "http://www.searchindex.com/"))); // Redirect header
            AuthMock.Verify(x => x.GetSettingsAsync(), Times.Once);
            PlexMock.Verify(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Never);
        }
Ejemplo n.º 6
0
        public void RequestAuthTokenTestExistingSettings()
        {
            AuthMock.Setup(x => x.GetSettings()).Returns(() => null);
            var browser = new Browser(Bootstrapper);

            var result = browser.Post("/admin/requestauth", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("username", "Username1");
                with.FormValue("password", "Password1");
            });

            Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));

            var body = JsonConvert.DeserializeObject <JsonResponseModel>(result.Body.AsString());

            Assert.That(body.Result, Is.EqualTo(true));

            PlexMock.Verify(x => x.SignIn("Username1", "Password1"), Times.Once);
        }
Ejemplo n.º 7
0
        public void LoginWithUsernameUnSuccessfully()
        {
            var expectedSettings = new AuthenticationSettings {
                UserAuthentication = true
            };
            var plexFriends = new PlexFriends
            {
                User = new[]
                {
                    new UserFriends
                    {
                        Username = "******",
                    },
                }
            };

            AuthMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(expectedSettings);
            PlexMock.Setup(x => x.GetUsers(It.IsAny <string>())).Returns(plexFriends);
            PlexMock.Setup(x => x.GetAccount(It.IsAny <string>())).Returns(new PlexAccount());

            Bootstrapper.WithSession(new Dictionary <string, object>());

            var browser = new Browser(Bootstrapper);

            var result = browser.Post("/userlogin", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Username", "abc");
            });


            Assert.That(HttpStatusCode.SeeOther, Is.EqualTo(result.StatusCode));
            Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);

            Assert.That(result.Headers.Contains(new KeyValuePair <string, string>("Location", "http://www.userloginindex.com/"))); // Redirect header
            AuthMock.Verify(x => x.GetSettingsAsync(), Times.Once);
            PlexMock.Verify(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Once);
        }
        public void GetUsersTokenIsNull()
        {
            AuthMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings());
            var browser = new Browser(Bootstrapper);

            var result = browser.Get("/admin/getusers", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("username", "Username1");
                with.FormValue("password", "Password1");
            });

            Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));

            var body = JsonConvert.DeserializeObject <string>(result.Body.AsString());

            Assert.That(body, Is.Not.Null);
            Assert.That(string.IsNullOrWhiteSpace(body), Is.True);

            PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Never);
            AuthMock.Verify(x => x.GetSettings(), Times.Once);
        }
        public void AttemptToLoginAsDeniedUser()
        {
            var expectedSettings = new AuthenticationSettings {
                UserAuthentication = false, DeniedUsers = "abc", PlexAuthToken = "abc"
            };

            AuthMock.Setup(x => x.GetSettings()).Returns(expectedSettings);

            var bootstrapper = new ConfigurableBootstrapper(with =>
            {
                with.Module <UserLoginModule>();
                with.Dependency(AuthMock.Object);
                with.Dependency(PlexMock.Object);
                with.RootPathProvider <TestRootPathProvider>();
            });

            bootstrapper.WithSession(new Dictionary <string, object>());

            var browser = new Browser(bootstrapper);
            var result  = browser.Post("/userlogin", with =>
            {
                with.HttpRequest();
                with.Header("Accept", "application/json");
                with.FormValue("Username", "abc");
            });

            Assert.That(HttpStatusCode.OK, Is.EqualTo(result.StatusCode));
            Assert.That(result.Context.Request.Session[SessionKeys.UsernameKey], Is.Null);

            var body = JsonConvert.DeserializeObject <JsonResponseModel>(result.Body.AsString());

            Assert.That(body.Result, Is.EqualTo(false));
            Assert.That(body.Message, Is.Not.Empty);
            AuthMock.Verify(x => x.GetSettings(), Times.Once);
            PlexMock.Verify(x => x.SignIn(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
            PlexMock.Verify(x => x.GetUsers(It.IsAny <string>()), Times.Never);
        }