Esempio n. 1
0
    def test_basic_operations(self):
        db = DatabaseHandler(db_path="pytests/", dbIsTemp=True)
        credh = CredentialsHandler('basic_username', 'basic_password')

        credh.encrypt_credentials()

        self.assertEqual(credh.does_user_exist(), False)
        self.assertEqual(credh.are_cred_valid(), False)

        credh.create_user()

        self.assertEqual(credh.does_user_exist(), True)
        self.assertEqual(credh.are_cred_valid(), True)
        DatabaseHandler.destroy_database()
Esempio n. 2
0
    def on_confirm_press(self, event):
        """
        Method override for the callback when the button is pressed
        It checkes wether the given login and password by the user is correct
        and either calls 'return_succesful_login' or 'display_error_message'
        """

        username = self._user_box.text()
        password = self._password_box.text()

        if len(username) > 0 and len(password) > 0:
            userpassregex = '([a-z]|[0-9]|\.)*'
            resu = re.match(userpassregex, username)
            resp = re.match(userpassregex, password)
            if resu.span()[1] == len(resu.string) and resp.span()[1] == len(
                    resp.string):
                credHandler = CredentialsHandler(username, password)
                credHandler.encrypt_credentials()
                if credHandler.are_cred_valid():
                    self.return_succesful_login()
                else:
                    self._error_message.setText(
                        "Failed to login, bad credentials")
                    self.display_error_message()
            else:
                self._error_message.setText(
                    "Invalid characters, use only a-z, 0-9 and periods (.)")
                self.display_error_message()
Esempio n. 3
0
    def test_credentials_validation(self):
        db = DatabaseHandler(db_path="pytests/", dbIsTemp=True)
        credh = CredentialsHandler('testusername', b'nonemptytestpassword')

        credh.encrypt_credentials()
        # Until we have no database connected here this will always pass, if it fails
        # rewrite the test in a way it's taking into consideration the database
        self.assertEqual(credh.are_cred_valid(), False)
        DatabaseHandler.destroy_database()