#49872 Test basic anonymous search operations
Closed 3 years ago by spichugi. Opened 5 years ago by amsharma.
amsharma/389-ds-base basic  into  master

@@ -12,13 +12,13 @@ 

  """

  

  from subprocess import check_output, Popen

- 

+ from lib389.idm.user import UserAccounts

  import pytest

  from lib389.tasks import *

  from lib389.utils import *

  from lib389.topologies import topology_st

  from lib389.dbgen import dbgen

- 

+ from lib389.idm.organizationalunit import OrganizationalUnits

  from lib389._constants import DN_DM, PASSWORD, PW_DM

  from lib389.topologies import topology_st

  
@@ -887,6 +887,135 @@ 

          log.fatal('Search failed, error: ' + e.message['desc'])

          assert False

  

+ 

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

+ def test_users(topology_st):

+     """Add users to the default suffix

+     """

+ 

+     users = UserAccounts(topology_st.standalone, DEFAULT_SUFFIX)

+     user_names = ["Directory", "Server", "389", "lib389", "pytest"]

+ 

+     log.info('Adding 5 test users')

+     for name in user_names:

+         user = users.create(properties={

+             'uid': name,

+             'sn': name,

+             'cn': name,

+             'uidNumber': '1000',

+             'gidNumber': '1000',

+             'homeDirectory': '/home/%s' % name,

+             'mail': '%s@example.com' % name,

+             'userpassword': 'pass%s' % name,

+         })

+ 

+ 

+ def test_basic_anonymous_search(topology_st, test_users):

+     """Tests basic anonymous search operations

+ 

+     :id: c7831e04-f458-4e50-83c7-b6f77109f639

+     :setup: Standalone instance

+             Add 5 test users with different user names

+     :steps:

+          1. Execute anonymous search with different filters

+     :expectedresults:

+          1. Search should be successful

+     """

+ 

+     filters = ["uid=Directory", "(|(uid=S*)(uid=3*))", "(&(uid=l*)(mail=l*))", "(&(!(uid=D*))(ou=People))"]

+     log.info("Execute anonymous search with different filters")

+     for filtr in filters:

+         entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, filtr)

+         assert len(entries) != 0

+ 

+ 

+ @pytest.mark.ds604

+ @pytest.mark.bz915801

+ def test_search_original_type(topology_st, test_users):

+     """Test ldapsearch returning original attributes

+         using nsslapd-search-return-original-type-switch

+ 

+     :id: d7831d04-f558-4e50-93c7-b6f77109f640

+     :setup: Standalone instance

+             Add some test entries

+     :steps:

+          1. Set nsslapd-search-return-original-type-switch to ON

+          2. Check that ldapsearch *does* return unknown attributes

+          3. Turn off nsslapd-search-return-original-type-switch

+          4. Check that ldapsearch doesn't return any unknown attributes

+     :expectedresults:

+          1. nsslapd-search-return-original-type-switch should be set to ON

+          2. ldapsearch should return unknown attributes

+          3. nsslapd-search-return-original-type-switch should be OFF

+          4. ldapsearch should not return any unknown attributes

+     """

+ 

+     log.info("Set nsslapd-search-return-original-type-switch to ON")

+     topology_st.standalone.config.set('nsslapd-search-return-original-type-switch', 'on')

+ 

+     log.info("Check that ldapsearch *does* return unknown attributes")

+     entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'uid=Directory',

+                                               ['objectclass overflow', 'unknown'])

+     assert "objectclass overflow" in entries[0].getAttrs()

+ 

+     log.info("Set nsslapd-search-return-original-type-switch to Off")

+     topology_st.standalone.config.set('nsslapd-search-return-original-type-switch', 'off')

+     log.info("Check that ldapsearch *does not* return unknown attributes")

+     entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'uid=Directory',

+                                               ['objectclass overflow', 'unknown'])

+     assert "objectclass overflow" not in entries[0].getAttrs()

+ 

+ 

+ @pytest.mark.bz192901

+ def test_search_ou(topology_st):

+     """Test that DS should not return an entry that does not match the filter

+ 

+     :id: d7831d05-f117-4e89-93c7-b6f77109f640

+     :setup: Standalone instance

+     :steps:

+          1. Create an OU entry without sub entries

+          2. Search from the OU with the filter that does not match the OU

+     :expectedresults:

+          1. Creation of OU should be successful

+          2. Search should not return any results

+     """

+ 

+     log.info("Create a test OU without sub entries")

+     ou = OrganizationalUnits(topology_st.standalone, DEFAULT_SUFFIX)

+     ou.create(properties={

+         'ou': 'test_ou',

+     })

+ 

+     search_base = ("ou=test_ou,%s" % DEFAULT_SUFFIX)

+     log.info("Search from the OU with the filter that does not match the OU, it should not return anything")

+     entries = topology_st.standalone.search_s(search_base, ldap.SCOPE_SUBTREE, 'uid=*', ['dn'])

+     assert len(entries) == 0

+ 

+ 

+ @pytest.mark.bz1044135

+ @pytest.mark.ds47319

+ def test_connection_buffer_size(topology_st):

+     """Test connection buffer size adjustable with different values(valid values and invalid)

+ 

+     :id: e7831d05-f117-4ec9-1203-b6f77109f117

+     :setup: Standalone instance

+     :steps:

+          1. Set nsslapd-connection-buffer to some valid values (2, 0 , 1)

+          2. Set nsslapd-connection-buffer to some invalid values (-1, a)

+     :expectedresults:

+          1. This should pass

+          2. This should fail

+     """

+ 

+     valid_values = ['2', '0', '1']

+     for value in valid_values:

+         topology_st.standalone.config.replace('nsslapd-connection-buffer', value)

+ 

+     invalid_values = ['-1', 'a']

+     for value in invalid_values:

+         with pytest.raises(ldap.OPERATIONS_ERROR):

+             topology_st.standalone.config.replace('nsslapd-connection-buffer', value)

+ 

  if __name__ == '__main__':

      # Run isolated

      # -s for DEBUG mode

@@ -20,6 +20,8 @@ 

  ENTRY_NAME = 'test_entry'

  

  

+ @pytest.mark.bz918686

+ @pytest.mark.ds497

  def test_filter_escaped(topology_st):

      """Test we can search for an '*' in a attribute value.

  

@@ -19,6 +19,8 @@ 

  log = logging.getLogger(__name__)

  

  

+ @pytest.mark.bz918684

+ @pytest.mark.ds394

  def test_password_delete_specific_password(topology_st):

      """Delete a specific userPassword, and make sure

      it is actually deleted from the entry

Description: Added a test for basic anonymous search operations with
various filters

https://pagure.io/389-ds-base/issue/48056

Reviewed by: Simon

You can add it as a fixture -
def test_basic_anonymous_search(topology_st, test_users):

@pytest.fixture
def test_users(topology_st):

rebased onto 3cd3b7f5ba8f54475501b7a550af8d14d5209625

5 years ago

Fixed and added one more test case. Please review. Thanks.

LGTM, but probably best to wait for @spichugi

Fixed and added one more test case. Please review. Thanks.

I think we can remove 'Verify bug 915801 - ' part because we already mentioned ds604

I am happy with the code. But we will add more test cases as Amita said.

rebased onto 4d7fc46624b5194741329785a6af4ab4fa1d082f

5 years ago

Added one more test case to verify bug 192901, did not find its trac ticket number. Please review.

Please use format 'bz123456', as existing test cases, not 'bug123456'.

Let's move this number to pytest.mark.bz

rebased onto 722df504116b57d378863e0df56c020869e46ae7

5 years ago

@vashirov @spichugi Thanks for the review. Modified the code and added more test cases. Please check. Thanks.

rebased onto 2b6ea6b47d7b5660f473b9c961562f3ca94a781d

5 years ago

Okay, tests pass and the code looks good.

So please, make a rebase and also change the first commit line...
It should be something like this

Issue 48056 - Add more test cases to the basic suite

instead of this

Test basic LDAP operations

The commit message should always follow the same structure. Use the imperative mood in the subject line.
A hint, it should sounds like '(This commit will) Add more test cases to the basic suite'

rebased onto b14c836

5 years ago

Thanks @spichugi for the review.
Please check the latest commit.

Pull-Request has been merged by spichugi

5 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/2931

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