Пример #1
0
    def test_should_reject_number_password(self):
        """Should fail to enroll a user with a weak (numbers only) password
        """

        with patch("sys.stdout", new=StringIO()) as out:
            username = "******"
            password = "******"

            with Database(self.db_name) as db:
                enroller = Enroll(db)
                with self.assertRaises(SystemExit) as sys_exit:
                    enroller.enroll(username, password)
                    self.assertEqual(sys_exit.exception.code, constants.STATUS_ERR)
                    self.assertEqual(out.getvalue().strip(), constants.ENROLL_ERR)
Пример #2
0
    def test_should_reject_dictionary_password_surrounded_by_nums(self):
        """Should fail to enroll a user with a weak password - dictionary word surrounded by numbers
        """

        with patch("sys.stdout", new=StringIO()) as out:
            username = "******"
            password = "******"

            with Database(self.db_name) as db:
                enroller = Enroll(db)
                with self.assertRaises(SystemExit) as sys_exit:
                    enroller.enroll(username, password)
                    self.assertEqual(sys_exit.exception.code, constants.STATUS_ERR)
                    self.assertEqual(out.getvalue().strip(), constants.ENROLL_ERR)
Пример #3
0
    def test_should_create_a_new_user(self):
        """Should successfully enroll a new user with secure password
        """

        with patch("sys.stdout", new=StringIO()) as out:
            username = "******"
            password = "******"

            with Database(self.db_name) as db:
                enroller = Enroll(db)
                with self.assertRaises(SystemExit) as sys_exit:
                    enroller.enroll(username, password)

                self.assertEqual(sys_exit.exception.code, constants.STATUS_OK)
                self.assertEqual(out.getvalue().strip(), constants.ENROLL_OK)
                db.remove(username)
Пример #4
0
    def test_should_create_user_with_same_password_but_different_hash(self):
        """Should successfully enroll a new user with the same password and their hashes should not equal
        """

        with patch("sys.stdout", new=StringIO()) as out:
            username1 = "john doe1"
            username2 = "john doe2"
            password = "******"

            with Database(self.db_name) as db:
                enroller = Enroll(db)
                with self.assertRaises(SystemExit) as sys_exit:
                    enroller.enroll(username1, password)
                    self.assertEqual(sys_exit.exception.code, constants.STATUS_OK)
                    self.assertEqual(out.getvalue().strip(), constants.ENROLL_OK)

                with self.assertRaises(SystemExit) as sys_exit:
                    enroller.enroll(username2, password)
                    self.assertEqual(sys_exit.exception.code, constants.STATUS_OK)
                    self.assertEqual(out.getvalue().strip(), constants.ENROLL_OK)

                user1 = db.get_user(username1)
                user2 = db.get_user(username2)

                self.assertNotEqual(user1[0], user2[0])
                self.assertNotEqual(user1[1], user2[1])

                db.remove(username1)
                db.remove(username2)
Пример #5
0
    def test_should_create_new_user_and_throw_when_enrolling_again(self):
        """Should enroll a new user and then should fail to enroll it again
        """

        with patch("sys.stdout", new=StringIO()) as out:
            username = "******"
            password = "******"

            with Database(self.db_name) as db:
                enroller = Enroll(db)
                with self.assertRaises(SystemExit) as sys_exit_succ:
                    enroller.enroll(username, password)
                    self.assertEqual(sys_exit_succ.exception.code, constants.STATUS_OK)
                    self.assertEqual(out.getvalue().strip(), constants.ENROLL_OK)

                with self.assertRaises(SystemExit) as sys_exit_fail:
                    enroller.enroll(username, password)
                    self.assertEqual(sys_exit_fail.exception.code, constants.STATUS_ERR)
                    self.assertEqual(out.getvalue().strip(), constants.ENROLL_ERR)

                db.remove(username)