public void TestBadLogin()
        {
            ISecurityManager securityManager = new SqlSecurityManager(connection);

            securityManager.OpenSession();
            IUserManager userManager = securityManager.UserManager;
            User         user        = userManager.CheckCredentials("Johnny", "English");

            securityManager.Close();
        }
        static void Main(string[] args)
        {
            string connectionString = "Data Source = localhost; Initial Catalog = SecurityComponent; Integrated Security = True";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                Another          component  = new Another();
                ISecurityManager dependency = new SqlSecurityManager(connection);
                component.SecurityManager = dependency;
                component.DoSomething();
            }
        }
        public void TempTest()
        {
            ISecurityManager securityManager = new SqlSecurityManager(connection);

            securityManager.OpenSession();
            IRoleManager roleManager = securityManager.RoleManager;

            Role role = roleManager.SelectRoleByName("demo");

            roleManager.DeleteRole();

            securityManager.Close();
        }
        public void TestGoodLogin()
        {
            ISecurityManager securityManager = new SqlSecurityManager(connection);

            securityManager.OpenSession();
            IUserManager userManager = securityManager.UserManager;
            User         user        = userManager.CheckCredentials("root", "admin");

            securityManager.Close();

            Assert.AreEqual("root", user.Login);
            Assert.IsFalse(user.Disabled);
            Assert.AreEqual(0u, user.ConsecutiveErrors);
        }
Exemplo n.º 5
0
        //TEST:  SQLSECURITYMANAGER_ISADMIN_FAILURETEST
        //Test the functionality of the SqlSecurityManager IsAdmin method when using unintended test data.
        //Uses our newly created user who is not an admin to show that IsAdmin will return false when given a non-admin.
        public void SqlSecurityManager_IsAdmin_FAILURETest()
        {
            SqlSecurityManager manager = new SqlSecurityManager();

            //ARRANGE
            //These parameters refer to the test user that we created in SqlSecurityManager_RegisterUser
            string testUsername = "******";
            bool   result;

            //ACT
            result = manager.IsAdmin(testUsername);
            //ASSERT
            Assert.IsNotNull(result);
            Assert.IsFalse(result);
        }
Exemplo n.º 6
0
        //TEST:  SQLSECURITYMANAGER_ISADMIN_TEST
        //Test the functionality of the SqlSecurityManager IsAdmin method using test data.
        public void SqlSecurityManager_IsAdmin_Test()
        {
            SqlSecurityManager manager = new SqlSecurityManager();

            //ARRANGE
            //The only Admin username in the DB
            string username = "******";
            bool   result;

            //ACT
            result = manager.IsAdmin(username);
            //ASSERT
            Assert.IsNotNull(result);
            Assert.IsTrue(result);
        }
Exemplo n.º 7
0
        //TEST:  USER_DELETE_FAILURETEST
        //Test the functionality of the User Delete method when using unintended test data.
        //Because the User has already been deleted by the previous method, this will result in a value of -1 (signifying a
        // failure to delete a user), rather than the value of 1 that is returned on the successful deletion of a user.
        public void Users_Delete_FAILURETest()
        {
            SqlSecurityManager manager = new SqlSecurityManager();

            //ARRANGE
            UsersController usersController = new UsersController();
            MyDataEntities  db = new MyDataEntities();
            //ACT
            int result = manager.Delete("testRegisterUser");

            //ASSERT
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(int));
            Assert.AreEqual(result, -1);
        }
Exemplo n.º 8
0
        //TEST:  SQLSECURITYMANAGER_LOADUSER_FAILURETEST
        //Test the functionality of the SqlSecurityManager LoadUser method when using unintended test data.
        //Loading a username that is not owned by any User will simply return a null User.
        public void SqlSecurityManager_LoadUser_FAILURETest()
        {
            SqlSecurityManager manager = new SqlSecurityManager();
            MyDataEntities     db      = new MyDataEntities();

            //ARRANGE
            User   test;
            string username = "******";

            //ACT
            test = manager.LoadUser(username);
            //ASSERT
            Assert.AreEqual(0, test.UserID);
            Assert.IsNull(test.UserName);
            Assert.IsNull(test.Password);
        }
Exemplo n.º 9
0
        //TEST:  SQLSECURITYMANAGER_AUTHENTICATEUSER_TEST
        //Test the functionality of the SqlSecurityManager AuthenticateUser method using test data.
        public void SqlSecurityManager_AuthenticateUser_Test()
        {
            SqlSecurityManager manager = new SqlSecurityManager();

            //ARRANGE
            //These parameters refer to the test user that we created in SqlSecurityManager_RegisterUser
            string username = "******";
            string password = "******";
            bool   result;

            //ACT
            result = manager.AuthenticateUser(username, password);
            //ASSERT
            Assert.IsNotNull(result);
            Assert.IsTrue(result);
        }
Exemplo n.º 10
0
        //TEST:  SQLSECURITYMANAGER_AUTHENTICATEUSER_FAILURETEST
        //Test the functionality of the SqlSecurityManager AuthenticateUser method when using unintended test data.
        //Uses a wrong password to show that if the username and/or password are wrong then AuthenticateUser() will return false
        public void SqlSecurityManager_AuthenticateUser_FAILURETest()
        {
            SqlSecurityManager manager = new SqlSecurityManager();

            //ARRANGE
            //Login parameters
            string username = "******";
            //Wrong Password
            string password = "******";
            bool   result;

            //ACT
            result = manager.AuthenticateUser(username, password);
            //ASSERT
            Assert.IsNotNull(result);
            Assert.IsFalse(result);
        }
Exemplo n.º 11
0
        //TEST:  SQLSECURITYMANAGER_REGISTERUSER_FAILURETEST
        //Test the functionality of the SqlSecurityManager RegisterUser method when using unintended test data.
        //Previous method created this User, therefore the UserName should be reserved, and this method will not be able to use it
        public void SqlSecurityManager_RegisterUser_FAILURETest()
        {
            SqlSecurityManager manager = new SqlSecurityManager();

            //ARRANGE
            //Create a test user with test parameters
            Store.Data.User newUser = new User();
            newUser.UserName        = "******";
            newUser.Password        = "******";
            newUser.ConfirmPassword = "******";
            newUser.EmailAddress    = "*****@*****.**";
            //ACT
            int result = manager.RegisterUser(newUser);

            //ASSERT
            Assert.IsNotNull(result);
            Assert.AreEqual(result, -1);
        }
Exemplo n.º 12
0
        //TEST:  SQLSECURITYMANAGER_DELETEUSER_TEST
        //Test the functionality of the SqlSecurityManager DeleteUser method using test data.
        public void SqlSecurityManager_DeleteUser_Test()
        {
            SqlSecurityManager manager = new SqlSecurityManager();
            MyDataEntities     db      = new MyDataEntities();

            //ARRANGE
            //Grab the test user that we created in SqlSecurityManager_RegisterUser and find their UserID to be used in the Delete method
            var userArray  = db.Users.Where(x => x.UserName == "testSqlUser").ToList();
            int testUserID = 0;

            foreach (var item in userArray)
            {
                testUserID = item.UserID;
            }
            //ACT
            int result = manager.Delete("testSqlUser");

            //ASSERT
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(int));
            Assert.AreEqual(result, 1);
        }
        protected void btnConnect_Click(object sender, EventArgs e)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["WebApp"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    ISecurityManager securityManager = new SqlSecurityManager(connection);
                    securityManager.OpenSession();
                    IUserManager userManager = securityManager.UserManager;

                    string login    = txtLogin.Text;
                    string password = txtPassword.Text;
                    User   user     = userManager.CheckCredentials(login, password);
                    securityManager.Close();
                    lblResult.Text = "Welcome " + txtLogin.Text;
                }
                catch (BadCredentialsException)
                {
                    lblResult.Text = "Téki?";
                }
            }
        }
Exemplo n.º 14
0
        //TEST:  SQLSECURITYMANAGER_LOADUSER_TEST
        //Test the functionality of the SqlSecurityManager LoadUser method using test data.
        public void SqlSecurityManager_LoadUser_Test()
        {
            SqlSecurityManager manager = new SqlSecurityManager();
            MyDataEntities     db      = new MyDataEntities();

            //ARRANGE
            //Grab the test user that we created in SqlSecurityManager_RegisterUser and find their UserID
            var userArray  = db.Users.Where(x => x.UserName == "testSqlUser").ToList();
            int testUserID = 0;

            foreach (var item in userArray)
            {
                testUserID = item.UserID;
            }

            //These parameters refer to the test user that we created in SqlSecurityManager_RegisterUser
            User   test;
            string username = "******";

            //ACT
            test = manager.LoadUser(username);
            //ASSERT
            Assert.AreEqual(testUserID, test.UserID);
        }