Exemplo n.º 1
0
    def test_reset_user_password_no_user(self):
        """
        Reset password for a non-existant user.
        """

        setup_identity_cache()

        task = Task.objects.create(ip_address="0.0.0.0",
                                   keystone_user={
                                       'roles': ['admin', 'project_mod'],
                                       'project_id': 'test_project_id',
                                       'project_domain_id': 'default',
                                   })

        data = {
            'domain_name': 'Default',
            'email': '*****@*****.**',
        }

        action = ResetUserPasswordAction(data, task=task, order=1)

        action.pre_approve()
        self.assertEqual(action.valid, False)

        action.post_approve()
        self.assertEqual(action.valid, False)

        token_data = {}
        action.submit(token_data)
        self.assertEqual(action.valid, False)
Exemplo n.º 2
0
    def test_reset_user_password_no_user(self):
        """
        Reset password for a non-existant user.
        """

        setup_identity_cache()

        task = Task.objects.create(
            keystone_user={
                "roles": ["admin", "project_mod"],
                "project_id": "test_project_id",
                "project_domain_id": "default",
            }
        )

        data = {
            "domain_name": "Default",
            "email": "*****@*****.**",
        }

        action = ResetUserPasswordAction(data, task=task, order=1)

        action.prepare()
        self.assertEqual(action.valid, False)

        action.approve()
        self.assertEqual(action.valid, False)

        token_data = {}
        action.submit(token_data)
        self.assertEqual(action.valid, False)
Exemplo n.º 3
0
    def test_reset_user_email_not_username(self):
        """
        Base case, existing user.
        Username not email address
        """

        user = mock.Mock()
        user.id = 'user_id'
        user.name = "test_user"
        user.email = "*****@*****.**"
        user.domain = 'default'
        user.password = "******"

        setup_temp_cache({}, {user.id: user})

        task = Task.objects.create(ip_address="0.0.0.0",
                                   keystone_user={
                                       'roles': ['project_mod'],
                                       'project_id': 'test_project_id',
                                       'project_domain_id': 'default',
                                   })

        data = {
            'username': "******",
            'domain_name': 'Default',
            'email': '*****@*****.**',
            'project_name': 'test_project',
        }

        action = ResetUserPasswordAction(data, task=task, order=1)

        action.pre_approve()
        self.assertEquals(action.valid, True)

        action.post_approve()
        self.assertEquals(action.valid, True)

        token_data = {'password': '******'}
        action.submit(token_data)
        self.assertEquals(action.valid, True)

        self.assertEquals(tests.temp_cache['users'][user.id].password,
                          '123456')
        self.assertEquals(tests.temp_cache['users'][user.id].name, 'test_user')
        self.assertEquals(tests.temp_cache['users'][user.id].email,
                          '*****@*****.**')
Exemplo n.º 4
0
    def test_reset_user_email_not_username(self):
        """
        Base case, existing user.
        Username not email address
        """
        user = fake_clients.FakeUser(
            name="test_user", password="******", email="*****@*****.**"
        )

        setup_identity_cache(users=[user])

        task = Task.objects.create(
            keystone_user={
                "roles": ["project_mod"],
                "project_id": "test_project_id",
                "project_domain_id": "default",
            }
        )

        data = {
            "username": "******",
            "domain_name": "Default",
            "email": "*****@*****.**",
        }

        action = ResetUserPasswordAction(data, task=task, order=1)

        action.prepare()
        self.assertEqual(action.valid, True)

        action.approve()
        self.assertEqual(action.valid, True)

        token_data = {"password": "******"}
        action.submit(token_data)
        self.assertEqual(action.valid, True)

        fake_client = fake_clients.FakeManager()

        user = fake_client.find_user(name="test_user", domain="default")

        self.assertEqual(user.email, "*****@*****.**")
        self.assertEqual(user.password, "123456")
Exemplo n.º 5
0
    def test_reset_user_email_not_username(self):
        """
        Base case, existing user.
        Username not email address
        """
        user = fake_clients.FakeUser(name="test_user",
                                     password="******",
                                     email="*****@*****.**")

        setup_identity_cache(users=[user])

        task = Task.objects.create(ip_address="0.0.0.0",
                                   keystone_user={
                                       'roles': ['project_mod'],
                                       'project_id': 'test_project_id',
                                       'project_domain_id': 'default',
                                   })

        data = {
            'username': "******",
            'domain_name': 'Default',
            'email': '*****@*****.**',
        }

        action = ResetUserPasswordAction(data, task=task, order=1)

        action.pre_approve()
        self.assertEqual(action.valid, True)

        action.post_approve()
        self.assertEqual(action.valid, True)

        token_data = {'password': '******'}
        action.submit(token_data)
        self.assertEqual(action.valid, True)

        fake_client = fake_clients.FakeManager()

        user = fake_client.find_user(name="test_user", domain="default")

        self.assertEqual(user.email, '*****@*****.**')
        self.assertEqual(user.password, '123456')
Exemplo n.º 6
0
    def test_reset_user_password_case_insensitive(self):
        """
        Existing user, ensure action is case insensitive.

        USERNAME_IS_EMAIL=True
        """

        user = fake_clients.FakeUser(
            name="*****@*****.**", password="******", email="*****@*****.**"
        )

        setup_identity_cache(users=[user])

        task = Task.objects.create(
            keystone_user={
                "roles": ["admin", "project_mod"],
                "project_id": "test_project_id",
                "project_domain_id": "default",
            }
        )

        data = {
            "domain_name": "Default",
            "email": "*****@*****.**",
        }

        action = ResetUserPasswordAction(data, task=task, order=1)

        action.prepare()
        self.assertEqual(action.valid, True)

        action.approve()
        self.assertEqual(action.valid, True)

        token_data = {"password": "******"}
        action.submit(token_data)
        self.assertEqual(action.valid, True)

        self.assertEqual(
            fake_clients.identity_cache["users"][user.id].password, "123456"
        )
Exemplo n.º 7
0
    def test_reset_user_password_case_insensitive(self):
        """
        Existing user, ensure action is case insensitive.

        USERNAME_IS_EMAIL=True
        """

        user = fake_clients.FakeUser(name="*****@*****.**",
                                     password="******",
                                     email="*****@*****.**")

        setup_identity_cache(users=[user])

        task = Task.objects.create(ip_address="0.0.0.0",
                                   keystone_user={
                                       'roles': ['admin', 'project_mod'],
                                       'project_id': 'test_project_id',
                                       'project_domain_id': 'default',
                                   })

        data = {
            'domain_name': 'Default',
            'email': '*****@*****.**',
        }

        action = ResetUserPasswordAction(data, task=task, order=1)

        action.pre_approve()
        self.assertEqual(action.valid, True)

        action.post_approve()
        self.assertEqual(action.valid, True)

        token_data = {'password': '******'}
        action.submit(token_data)
        self.assertEqual(action.valid, True)

        self.assertEqual(
            fake_clients.identity_cache['users'][user.id].password, '123456')