#50437 Issue: 48851 - investigate and port TET matching rules filter tests(bug772777)
Closed 3 years ago by spichugi. Opened 4 years ago by aborah.
aborah/389-ds-base bug77  into  master

@@ -0,0 +1,163 @@ 

+ # --- BEGIN COPYRIGHT BLOCK ---

+ # Copyright (C) 2019 Red Hat, Inc.

+ # All rights reserved.

+ #

+ # License: GPL (version 3 or any later version).

+ # See LICENSE for details.

+ # --- END COPYRIGHT BLOCK ----

+ 

+ 

+ """

+ verify and testing  Filter from a search

+ """

+ 

+ import os

+ import pytest

+ 

+ from lib389._constants import PW_DM

+ from lib389.topologies import topology_st as topo

+ from lib389.idm.user import UserAccounts, UserAccount

+ from lib389.idm.account import Accounts

+ from lib389.backend import Backends

+ from lib389.idm.domain import Domain

+ 

+ SUFFIX = 'dc=anuj,dc=com'

+ 

+ pytestmark = pytest.mark.tier1

+ 

+ 

+ @pytest.fixture(scope="module")

+ def _create_entries(request, topo):

+     """

+     Will create necessary users for this script.

+     """

+     # Creating Backend

+     backends = Backends(topo.standalone)

+     backend = backends.create(properties={'nsslapd-suffix': SUFFIX, 'cn': 'AnujRoot'})

+     # Creating suffix

+     suffix = Domain(topo.standalone, SUFFIX).create(properties={'dc': 'anuj'})

+     # Add ACI

+     domain = Domain(topo.standalone, SUFFIX)

+     domain.add("aci", f'(targetattr!="userPassword")(version 3.0; acl '

+                       f'"Enable anonymous access";allow (read, search, compare) userdn="ldap:///anyone";)')

+     # Creating Users

+     users = UserAccounts(topo.standalone, suffix.dn, rdn=None)

+ 

+     for user in ['scarter',

+                  'dmiller',

+                  'jwallace',

+                  'rdaugherty',

+                  'tmason',

+                  'bjablons',

+                  'bhal2',

+                  'lulrich',

+                  'fmcdonnagh',

+                  'prigden',

+                  'mlott',

+                  'tpierce',

+                  'brentz',

+                  'ekohler',

+                  'tschneid',

+                  'falbers',

+                  'jburrell',

+                  'calexand',

+                  'phunt',

+                  'rulrich',

+                  'awhite',

+                  'jjensen',

+                  'dward',

+                  'plorig',

+                  'mreuter',

+                  'dswain',

+                  'jvedder',

+                  'jlutz',

+                  'tcouzens',

+                  'kcope',

+                  'mvaughan',

+                  'dcope',

+                  'ttully',

+                  'drose',

+                  'jvaughan',

+                  'brigden',

+                  'rjense2',

+                  'bparker',

+                  'cnewport']:

+         users.create(properties={

+             'mail': f'{user}@redhat.com',

+             'uid': user,

+             'givenName': user.title(),

+             'cn': f'bit {user}',

+             'sn': user.title(),

+             'manager': f'uid={user},{SUFFIX}',

+             'userpassword': PW_DM,

+             'homeDirectory': '/home/' + user,

+             'uidNumber': '1000',

+             'gidNumber': '2000',

+         })

+ 

+     def fin():

+         """

+         Deletes entries after the test.

+         """

+         for user in users.list():

+             user.delete()

+ 

+         suffix.delete()

+         backend.delete()

+ 

+     request.addfinalizer(fin)

+ 

+ 

+ FILTERS = ['(&(objectClass=person)(|(manager=uid=fmcdonnagh,dc=anuj,dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_0,dc=anuj,dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_1,dc=anuj,dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_2,dc=anuj,dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_3,dc=anuj,dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_4,dc=anuj,dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_5,dc=anuj,dc=com)'

+            '(manager=uid=jvedder,  dc=anuj, dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_6,dc=anuj,dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_7,dc=anuj,dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_8,dc=anuj,dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_9,dc=anuj,dc=com)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_10,dc=anuj,dc=com)'

+            '(manager=uid=cnewport,  dc=anuj, dc=com)))',

+            '(&(objectClass=person)(|(manager=uid=fmcdonnagh *)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_0,*)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_1,*)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_2,*)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_3,*)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_4,*)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_5,*)'

+            '(manager=uid=jvedder,*)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_6,*)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_7,*)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_8,*)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_9,*)'

+            '(manager=cn=no_such_entry_with_a_really_long_dn_component_to_stress_the_filter_handling_code_10,*)'

+            '(manager=uid=cnewport,*)))']

+ 

+ 

+ @pytest.mark.bz772777

+ @pytest.mark.parametrize("real_value", FILTERS)

+ def test_large_filter(topo, _create_entries, real_value):

+     """Exercise large eq filter with dn syntax attributes

+         :id: abe3e6de-9ecc-11e8-adf0-8c16451d917b

+         :setup: Standalone

+         :steps:

+             1. Try to pass filter rules as per the condition.

+             2. Bind with any user.

+             3. Try to pass filter rules with new binding.

+         :expected results:

+             1. Pass

+             2. Pass

+             3. Pass

+     """

+     assert len(Accounts(topo.standalone, SUFFIX).filter(real_value)) == 3

+     conn = UserAccount(topo.standalone, f'uid=drose,{SUFFIX}').bind(PW_DM)

+     assert len(Accounts(conn, SUFFIX).filter(real_value)) == 3

+ 

+ 

+ if __name__ == '__main__':

+     CURRENT_FILE = os.path.realpath(__file__)

+     pytest.main("-s -v %s" % CURRENT_FILE)

Investigate and port TET matching rules filter tests(bug772777)

Relates: https://pagure.io/389-ds-base/issue/48851

Author: aborah

Reviewed by: ???

There's no need for this function. Just put the people.create(...) call into the fixture below directly.

Please, don't split the very long strings like this. In tests, it is better to have an easily followable content rather than strictly following 80-chars-per-line rule. It took me quite some time even to find out how many elements this list has. Just make the filters a single string, it will get much more readable.

1 new commit added

  • Fixing Matus Honek's comments
4 years ago

2 new commits added

  • Fixing Matus Honek's comments
  • Issue: 48851 - investigate and port TET matching rules filter tests(bug772777)
4 years ago

@mhonek changes are done as per your suggestion

2 new commits added

  • Fixing Matus Honek's comments
  • Issue: 48851 - investigate and port TET matching rules filter tests(bug772777)
4 years ago

I think you don't need it here at all. It is not used by the test case in any way. It can be hardcoded.

Okay, I see what Matus was telling about. I think we can improve it even better because now it is not readable.
You can chop down the string in (manager=) parts. Or you can use join function and generate the string out of the list

== 3 is true now but can be changed in the future.
It will be cleaner if you'll create a fresh suffix for the test case.

1 new commit added

  • Fixing Simon's comments
4 years ago

3 new commits added

  • Fixing Simon's comments
  • Fixing Matus Honek's comments
  • Issue: 48851 - investigate and port TET matching rules filter tests(bug772777)
4 years ago

@spichugi changes are done as per your suggestion

3 new commits added

  • Fixing Simon's comments
  • Fixing Matus Honek's comments
  • Issue: 48851 - investigate and port TET matching rules filter tests(bug772777)
4 years ago

3 new commits added

  • Fixing Simon's comments
  • Fixing Matus Honek's comments
  • Issue: 48851 - investigate and port TET matching rules filter tests(bug772777)
4 years ago

It is really inconsistent...
Sometimes you have = in the end, sometimes in the begining, sometimes the whole (manager=uid=cnewport, dc=anuj, dc=com) is in the line, sometimes not.

Why did you remove the previous steps with the user bind? I think it makes sense to test

Why did you remove the previous steps with the user bind? I think it makes sense to test

I need to set ACI there to give permission as its a new backend .

I see no reason why not to do this.

1 new commit added

  • Fixing Simon's Comments 2
4 years ago

@spichugi changes are done as per your suggestion

Don't forget to run pylint. You have a trailing whitespace here.

Still, it should e more steps here according to your actual code...

You already have the pytest mark.
I see no reason to name the test module dirsrvtests/tests/suites/filter/filter_bug772777_test.py.
I think you can make it a part of basic filter test suite or name it according to the actual content.

1 new commit added

  • Fixning Simon's commnets 3
4 years ago

@spichugi changes are done as per your suggestion

rebased onto 195ccf209984aa6a0aacbf1c706b01b65ed3fdd1

4 years ago

rebased onto 5fb5537d3ba446b35e0291fc43087db7e2cc0cf9

4 years ago

rebased onto d2566580a8ab847d5e5190faabe252feadb79978

4 years ago

rebased onto 22bc4bf73a6986e8747e2ae21901dddf982d84af

4 years ago

rebased onto 86077ec

4 years ago

Pull-Request has been merged by spichugi

4 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/3495

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago
Metadata