Browse Source

Expose defect in users_in_group, groups_for_user exact filters

List users in a group by name and list groups for user by name throws
HTTP 500 error in case of exact filters because filter_by query used
in case of exact filter is not able to filter using 'name' attribute.
This patch exposes this issue by adding new unit test cases to ensure
list_users_in_group and list_groups_for_user APIs are called with
exact filters.

Note: Added 'from keystone.tests.unit.utils import wip' in
test_backend_ldap.py, because 'wip' is not there in
test_backend_ldap imports in stable-liberty.

Conflicts:
        keystone/tests/unit/test_backend.py

Partial-Bug: 1521772
Change-Id: I5d3c2041551a020341a98554ebb885888ec3cc9d
(cherry picked from commit 545987e1c4)
tags/8.1.0
Ankit Agrawal 3 years ago
parent
commit
be3160d165
2 changed files with 65 additions and 27 deletions
  1. 50
    19
      keystone/tests/unit/test_backend.py
  2. 15
    8
      keystone/tests/unit/test_backend_ldap.py

+ 50
- 19
keystone/tests/unit/test_backend.py View File

@@ -6662,24 +6662,7 @@ class FilterTests(filtering.FilterTests):
6662 6662
 
6663 6663
         self._delete_test_data('user', user_list)
6664 6664
 
6665
-    def test_groups_for_user_filtered(self):
6666
-        """Test use of filtering doesn't break groups_for_user listing.
6667
-
6668
-        Some backends may use filtering to achieve the list of groups for a
6669
-        user, so test that it can combine a second filter.
6670
-
6671
-        Test Plan:
6672
-
6673
-        - Create 10 groups, some with names we can filter on
6674
-        - Create 2 users
6675
-        - Assign 1 of those users to most of the groups, including some of the
6676
-          well known named ones
6677
-        - Assign the other user to other groups as spoilers
6678
-        - Ensure that when we list groups for users with a filter on the group
6679
-          name, both restrictions have been enforced on what is returned.
6680
-
6681
-        """
6682
-
6665
+    def _groups_for_user_data(self):
6683 6666
         number_of_groups = 10
6684 6667
         group_name_data = {
6685 6668
             # entity index: name for entity
@@ -6703,6 +6686,26 @@ class FilterTests(filtering.FilterTests):
6703 6686
                                                 group_list[group]['id'])
6704 6687
 
6705 6688
         hints = driver_hints.Hints()
6689
+        return group_list, user_list, hints
6690
+
6691
+    def test_groups_for_user_inexact_filtered(self):
6692
+        """Test use of filtering doesn't break groups_for_user listing.
6693
+
6694
+        Some backends may use filtering to achieve the list of groups for a
6695
+        user, so test that it can combine a second filter.
6696
+
6697
+        Test Plan:
6698
+
6699
+        - Create 10 groups, some with names we can filter on
6700
+        - Create 2 users
6701
+        - Assign 1 of those users to most of the groups, including some of the
6702
+          well known named ones
6703
+        - Assign the other user to other groups as spoilers
6704
+        - Ensure that when we list groups for users with a filter on the group
6705
+          name, both restrictions have been enforced on what is returned.
6706
+
6707
+        """
6708
+        group_list, user_list, hints = self._groups_for_user_data()
6706 6709
         hints.add_filter('name', 'The', comparator='startswith')
6707 6710
         groups = self.identity_api.list_groups_for_user(
6708 6711
             user_list[0]['id'], hints=hints)
@@ -6714,6 +6717,20 @@ class FilterTests(filtering.FilterTests):
6714 6717
         self._delete_test_data('user', user_list)
6715 6718
         self._delete_test_data('group', group_list)
6716 6719
 
6720
+    @test_utils.wip('Waiting on bug #1521772 to be fixed')
6721
+    def test_groups_for_user_exact_filtered(self):
6722
+        """Test exact filters doesn't break groups_for_user listing."""
6723
+        group_list, user_list, hints = self._groups_for_user_data()
6724
+        hints.add_filter('name', 'The Ministry', comparator='equals')
6725
+        groups = self.identity_api.list_groups_for_user(
6726
+            user_list[0]['id'], hints=hints)
6727
+        # We should only get back 1 out of the 3 groups with name 'The
6728
+        # Ministry' hence showing that both "filters" have been applied.
6729
+        self.assertEqual(1, len(groups))
6730
+        self.assertEqual(group_list[6]['id'], groups[0]['id'])
6731
+        self._delete_test_data('user', user_list)
6732
+        self._delete_test_data('group', group_list)
6733
+
6717 6734
     def _get_user_name_field_size(self):
6718 6735
         """Return the size of the user name field for the backend.
6719 6736
 
@@ -6748,7 +6765,7 @@ class FilterTests(filtering.FilterTests):
6748 6765
         users = self.identity_api.list_users(hints=hints)
6749 6766
         self.assertEqual([], users)
6750 6767
 
6751
-    def test_list_users_in_group_filtered(self):
6768
+    def _list_users_in_group_data(self):
6752 6769
         number_of_users = 10
6753 6770
         user_name_data = {
6754 6771
             1: 'Arthur Conan Doyle',
@@ -6765,6 +6782,10 @@ class FilterTests(filtering.FilterTests):
6765 6782
                                                 group['id'])
6766 6783
 
6767 6784
         hints = driver_hints.Hints()
6785
+        return user_list, group, hints
6786
+
6787
+    def test_list_users_in_group_inexact_filtered(self):
6788
+        user_list, group, hints = self._list_users_in_group_data()
6768 6789
         hints.add_filter('name', 'Arthur', comparator='startswith')
6769 6790
         users = self.identity_api.list_users_in_group(group['id'], hints=hints)
6770 6791
         self.assertThat(len(users), matchers.Equals(2))
@@ -6773,6 +6794,16 @@ class FilterTests(filtering.FilterTests):
6773 6794
         self._delete_test_data('user', user_list)
6774 6795
         self._delete_entity('group')(group['id'])
6775 6796
 
6797
+    @test_utils.wip('Waiting on bug #1521772 to be fixed')
6798
+    def test_list_users_in_group_exact_filtered(self):
6799
+        user_list, group, hints = self._list_users_in_group_data()
6800
+        hints.add_filter('name', 'Arthur Rimbaud', comparator='equals')
6801
+        users = self.identity_api.list_users_in_group(group['id'], hints=hints)
6802
+        self.assertEqual(1, len(users))
6803
+        self.assertEqual(user_list[3]['id'], users[0]['id'])
6804
+        self._delete_test_data('user', user_list)
6805
+        self._delete_entity('group')(group['id'])
6806
+
6776 6807
 
6777 6808
 class LimitTests(filtering.FilterTests):
6778 6809
     ENTITIES = ['user', 'group', 'project']

+ 15
- 8
keystone/tests/unit/test_backend_ldap.py View File

@@ -37,6 +37,7 @@ from keystone.tests.unit import identity_mapping as mapping_sql
37 37
 from keystone.tests.unit.ksfixtures import database
38 38
 from keystone.tests.unit.ksfixtures import ldapdb
39 39
 from keystone.tests.unit import test_backend
40
+from keystone.tests.unit.utils import wip
40 41
 
41 42
 
42 43
 CONF = cfg.CONF
@@ -3344,13 +3345,19 @@ class LdapFilterTests(test_backend.FilterTests, unit.TestCase):
3344 3345
         config_files.append(unit.dirs.tests_conf('backend_ldap.conf'))
3345 3346
         return config_files
3346 3347
 
3347
-    def test_list_users_in_group_filtered(self):
3348
+    @wip('Not supported by LDAP identity driver')
3349
+    def test_list_users_in_group_inexact_filtered(self):
3348 3350
         # The LDAP identity driver currently does not support filtering on the
3349 3351
         # listing users for a given group, so will fail this test.
3350
-        try:
3351
-            super(LdapFilterTests, self).test_list_users_in_group_filtered()
3352
-        except matchers.MismatchError:
3353
-            return
3354
-        # We shouldn't get here...if we do, it means someone has implemented
3355
-        # filtering, so we can remove this test override.
3356
-        self.assertTrue(False)
3352
+        super(LdapFilterTests,
3353
+              self).test_list_users_in_group_inexact_filtered()
3354
+
3355
+    @wip('Not supported by LDAP identity driver')
3356
+    def test_list_users_in_group_exact_filtered(self):
3357
+        # The LDAP identity driver currently does not support filtering on the
3358
+        # listing users for a given group, so will fail this test.
3359
+        super(LdapFilterTests, self).test_list_users_in_group_exact_filtered()
3360
+
3361
+    @wip('Waiting on bug #1521772 to be fixed')
3362
+    def test_groups_for_user_exact_filtered(self):
3363
+        super(LdapFilterTests, self).test_groups_for_user_exact_filtered()

Loading…
Cancel
Save