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.

Partial-Bug: 1521772
Change-Id: I5d3c2041551a020341a98554ebb885888ec3cc9d
Ankit Agrawal 3 years ago
parent
commit
545987e1c4
2 changed files with 64 additions and 26 deletions
  1. 50
    18
      keystone/tests/unit/test_backend.py
  2. 14
    8
      keystone/tests/unit/test_backend_ldap.py

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

@@ -6457,23 +6457,7 @@ class FilterTests(filtering.FilterTests):
6457 6457
 
6458 6458
         self._delete_test_data('user', user_list)
6459 6459
 
6460
-    def test_groups_for_user_filtered(self):
6461
-        """Test use of filtering doesn't break groups_for_user listing.
6462
-
6463
-        Some backends may use filtering to achieve the list of groups for a
6464
-        user, so test that it can combine a second filter.
6465
-
6466
-        Test Plan:
6467
-
6468
-        - Create 10 groups, some with names we can filter on
6469
-        - Create 2 users
6470
-        - Assign 1 of those users to most of the groups, including some of the
6471
-          well known named ones
6472
-        - Assign the other user to other groups as spoilers
6473
-        - Ensure that when we list groups for users with a filter on the group
6474
-          name, both restrictions have been enforced on what is returned.
6475
-
6476
-        """
6460
+    def _groups_for_user_data(self):
6477 6461
         number_of_groups = 10
6478 6462
         group_name_data = {
6479 6463
             # entity index: name for entity
@@ -6497,6 +6481,26 @@ class FilterTests(filtering.FilterTests):
6497 6481
                                                 group_list[group]['id'])
6498 6482
 
6499 6483
         hints = driver_hints.Hints()
6484
+        return group_list, user_list, hints
6485
+
6486
+    def test_groups_for_user_inexact_filtered(self):
6487
+        """Test use of filtering doesn't break groups_for_user listing.
6488
+
6489
+        Some backends may use filtering to achieve the list of groups for a
6490
+        user, so test that it can combine a second filter.
6491
+
6492
+        Test Plan:
6493
+
6494
+        - Create 10 groups, some with names we can filter on
6495
+        - Create 2 users
6496
+        - Assign 1 of those users to most of the groups, including some of the
6497
+          well known named ones
6498
+        - Assign the other user to other groups as spoilers
6499
+        - Ensure that when we list groups for users with a filter on the group
6500
+          name, both restrictions have been enforced on what is returned.
6501
+
6502
+        """
6503
+        group_list, user_list, hints = self._groups_for_user_data()
6500 6504
         hints.add_filter('name', 'The', comparator='startswith')
6501 6505
         groups = self.identity_api.list_groups_for_user(
6502 6506
             user_list[0]['id'], hints=hints)
@@ -6508,6 +6512,20 @@ class FilterTests(filtering.FilterTests):
6508 6512
         self._delete_test_data('user', user_list)
6509 6513
         self._delete_test_data('group', group_list)
6510 6514
 
6515
+    @test_utils.wip('Waiting on bug #1521772 to be fixed')
6516
+    def test_groups_for_user_exact_filtered(self):
6517
+        """Test exact filters doesn't break groups_for_user listing."""
6518
+        group_list, user_list, hints = self._groups_for_user_data()
6519
+        hints.add_filter('name', 'The Ministry', comparator='equals')
6520
+        groups = self.identity_api.list_groups_for_user(
6521
+            user_list[0]['id'], hints=hints)
6522
+        # We should only get back 1 out of the 3 groups with name 'The
6523
+        # Ministry' hence showing that both "filters" have been applied.
6524
+        self.assertEqual(1, len(groups))
6525
+        self.assertEqual(group_list[6]['id'], groups[0]['id'])
6526
+        self._delete_test_data('user', user_list)
6527
+        self._delete_test_data('group', group_list)
6528
+
6511 6529
     def _get_user_name_field_size(self):
6512 6530
         """Return the size of the user name field for the backend.
6513 6531
 
@@ -6542,7 +6560,7 @@ class FilterTests(filtering.FilterTests):
6542 6560
         users = self.identity_api.list_users(hints=hints)
6543 6561
         self.assertEqual([], users)
6544 6562
 
6545
-    def test_list_users_in_group_filtered(self):
6563
+    def _list_users_in_group_data(self):
6546 6564
         number_of_users = 10
6547 6565
         user_name_data = {
6548 6566
             1: 'Arthur Conan Doyle',
@@ -6559,6 +6577,10 @@ class FilterTests(filtering.FilterTests):
6559 6577
                                                 group['id'])
6560 6578
 
6561 6579
         hints = driver_hints.Hints()
6580
+        return user_list, group, hints
6581
+
6582
+    def test_list_users_in_group_inexact_filtered(self):
6583
+        user_list, group, hints = self._list_users_in_group_data()
6562 6584
         hints.add_filter('name', 'Arthur', comparator='startswith')
6563 6585
         users = self.identity_api.list_users_in_group(group['id'], hints=hints)
6564 6586
         self.assertThat(len(users), matchers.Equals(2))
@@ -6567,6 +6589,16 @@ class FilterTests(filtering.FilterTests):
6567 6589
         self._delete_test_data('user', user_list)
6568 6590
         self._delete_entity('group')(group['id'])
6569 6591
 
6592
+    @test_utils.wip('Waiting on bug #1521772 to be fixed')
6593
+    def test_list_users_in_group_exact_filtered(self):
6594
+        user_list, group, hints = self._list_users_in_group_data()
6595
+        hints.add_filter('name', 'Arthur Rimbaud', comparator='equals')
6596
+        users = self.identity_api.list_users_in_group(group['id'], hints=hints)
6597
+        self.assertEqual(1, len(users))
6598
+        self.assertEqual(user_list[3]['id'], users[0]['id'])
6599
+        self._delete_test_data('user', user_list)
6600
+        self._delete_entity('group')(group['id'])
6601
+
6570 6602
 
6571 6603
 class LimitTests(filtering.FilterTests):
6572 6604
     ENTITIES = ['user', 'group', 'project']

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

@@ -3286,13 +3286,19 @@ class LdapFilterTests(test_backend.FilterTests, unit.TestCase):
3286 3286
         config_files.append(unit.dirs.tests_conf('backend_ldap.conf'))
3287 3287
         return config_files
3288 3288
 
3289
-    def test_list_users_in_group_filtered(self):
3289
+    @wip('Not supported by LDAP identity driver')
3290
+    def test_list_users_in_group_inexact_filtered(self):
3290 3291
         # The LDAP identity driver currently does not support filtering on the
3291 3292
         # listing users for a given group, so will fail this test.
3292
-        try:
3293
-            super(LdapFilterTests, self).test_list_users_in_group_filtered()
3294
-        except matchers.MismatchError:
3295
-            return
3296
-        # We shouldn't get here...if we do, it means someone has implemented
3297
-        # filtering, so we can remove this test override.
3298
-        self.assertTrue(False)
3293
+        super(LdapFilterTests,
3294
+              self).test_list_users_in_group_inexact_filtered()
3295
+
3296
+    @wip('Not supported by LDAP identity driver')
3297
+    def test_list_users_in_group_exact_filtered(self):
3298
+        # The LDAP identity driver currently does not support filtering on the
3299
+        # listing users for a given group, so will fail this test.
3300
+        super(LdapFilterTests, self).test_list_users_in_group_exact_filtered()
3301
+
3302
+    @wip('Waiting on bug #1521772 to be fixed')
3303
+    def test_groups_for_user_exact_filtered(self):
3304
+        super(LdapFilterTests, self).test_groups_for_user_exact_filtered()

Loading…
Cancel
Save