Ejemplo n.º 1
0
    def test_authentication(self):
        "Confirm Account authentication method is authenticating/denying users."
        # Valid credentials
        obj, errors = DefaultAccount.authenticate(self.account.name, self.password)
        self.assertTrue(obj, 'Account did not authenticate given valid credentials.')

        # Invalid credentials
        obj, errors = DefaultAccount.authenticate(self.account.name, 'xyzzy')
        self.assertFalse(obj, 'Account authenticated using invalid credentials.')
Ejemplo n.º 2
0
    def test_create(self):
        "Confirm Account creation is working as expected."
        # Create a normal account
        account, errors = DefaultAccount.create(username='******', password='******')
        self.assertTrue(account, 'New account should have been created.')

        # Try creating a duplicate account
        account2, errors = DefaultAccount.create(username='******', password='******')
        self.assertFalse(account2, 'Duplicate account name should not have been allowed.')
        account.delete()
Ejemplo n.º 3
0
    def test_throttle(self):
        "Confirm throttle activates on too many failures."
        for x in range(20):
            obj, errors = DefaultAccount.authenticate(self.account.name, 'xyzzy', ip='12.24.36.48')
            self.assertFalse(obj, 'Authentication was provided a bogus password; this should NOT have returned an account!')

        self.assertTrue('too many login failures' in errors[-1].lower(), 'Failed logins should have been throttled.')
Ejemplo n.º 4
0
    def test_puppet_object_no_session(self):
        "Check puppet_object method called with no session param"

        try:
            DefaultAccount().puppet_object(None, Mock())
            self.fail("Expected error: 'Session not found'")
        except RuntimeError as re:
            self.assertEqual("Session not found", re.message)
Ejemplo n.º 5
0
    def test_puppet_object_no_object(self):
        "Check puppet_object method called with no object param"

        try:
            DefaultAccount().puppet_object(self.s1, None)
            self.fail("Expected error: 'Object not found'")
        except RuntimeError as re:
            self.assertEqual("Object not found", re.message)
Ejemplo n.º 6
0
    def test_username_validation(self):
        "Check username validators deny relevant usernames"
        # Should not accept Unicode by default, lest users pick names like this

        if not uses_database("mysql"):
            # TODO As of Mar 2019, mysql does not pass this test due to collation problems
            # that has not been possible to resolve
            result, error = DefaultAccount.validate_username('¯\_(ツ)_/¯')
            self.assertFalse(result, "Validator allowed kanji in username.")

        # Should not allow duplicate username
        result, error = DefaultAccount.validate_username(self.account.name)
        self.assertFalse(result, "Duplicate username should not have passed validation.")

        # Should not allow username too short
        result, error = DefaultAccount.validate_username('xx')
        self.assertFalse(result, "2-character username passed validation.")