Blame SOURCES/0024-Issue-4480-Unexpected-info-returned-to-ldap-request-.patch

fec594
From 61d82ef842e0e4e013937bf05d7f640be2d2fc09 Mon Sep 17 00:00:00 2001
fec594
From: tbordaz <tbordaz@redhat.com>
fec594
Date: Wed, 16 Dec 2020 16:30:28 +0100
fec594
Subject: [PATCH 5/6] Issue 4480 - Unexpected info returned to ldap request
fec594
 (#4491)
fec594
fec594
Bug description:
fec594
	If the bind entry does not exist, the bind result info
fec594
        reports that 'No such entry'. It should not give any
fec594
        information if the target entry exists or not
fec594
fec594
Fix description:
fec594
	Does not return any additional information during a bind
fec594
fec594
relates: https://github.com/389ds/389-ds-base/issues/4480
fec594
fec594
Reviewed by: William Brown, Viktor Ashirov, Mark Reynolds (thank you all)
fec594
fec594
Platforms tested:  F31
fec594
---
fec594
 dirsrvtests/tests/suites/basic/basic_test.py | 112 +++++++++++++++++++
fec594
 1 file changed, 112 insertions(+)
fec594
fec594
diff --git a/dirsrvtests/tests/suites/basic/basic_test.py b/dirsrvtests/tests/suites/basic/basic_test.py
fec594
index 1ae82dcdd..02b73ee85 100644
fec594
--- a/dirsrvtests/tests/suites/basic/basic_test.py
fec594
+++ b/dirsrvtests/tests/suites/basic/basic_test.py
fec594
@@ -1400,6 +1400,118 @@ def test_dscreate_multiple_dashes_name(dscreate_long_instance):
fec594
     assert not dscreate_long_instance.exists()
fec594
 
fec594
 
fec594
+@pytest.fixture(scope="module", params=('c=uk', 'cn=test_user', 'dc=example,dc=com', 'o=south', 'ou=sales', 'wrong=some_value'))
fec594
+def dscreate_test_rdn_value(request):
fec594
+    template_file = "/tmp/dssetup.inf"
fec594
+    template_text = f"""[general]
fec594
+config_version = 2
fec594
+# This invalid hostname ...
fec594
+full_machine_name = localhost.localdomain
fec594
+# Means we absolutely require this.
fec594
+strict_host_checking = False
fec594
+# In tests, we can be run in containers, NEVER trust
fec594
+# that systemd is there, or functional in any capacity
fec594
+systemd = False
fec594
+
fec594
+[slapd]
fec594
+instance_name = test_different_rdn
fec594
+root_dn = cn=directory manager
fec594
+root_password = someLongPassword_123
fec594
+# We do not have access to high ports in containers,
fec594
+# so default to something higher.
fec594
+port = 38999
fec594
+secure_port = 63699
fec594
+
fec594
+[backend-userroot]
fec594
+create_suffix_entry = True
fec594
+suffix = {request.param}
fec594
+"""
fec594
+
fec594
+    with open(template_file, "w") as template_fd:
fec594
+        template_fd.write(template_text)
fec594
+
fec594
+    # Unset PYTHONPATH to avoid mixing old CLI tools and new lib389
fec594
+    tmp_env = os.environ
fec594
+    if "PYTHONPATH" in tmp_env:
fec594
+        del tmp_env["PYTHONPATH"]
fec594
+
fec594
+    def fin():
fec594
+        os.remove(template_file)
fec594
+        if request.param != "wrong=some_value":
fec594
+            try:
fec594
+                subprocess.check_call(['dsctl', 'test_different_rdn', 'remove', '--do-it'])
fec594
+            except subprocess.CalledProcessError as e:
fec594
+                log.fatal(f"Failed to remove test instance  Error ({e.returncode}) {e.output}")
fec594
+        else:
fec594
+            log.info("Wrong RDN is passed, instance not created")
fec594
+    request.addfinalizer(fin)
fec594
+    return template_file, tmp_env, request.param,
fec594
+
fec594
+
fec594
+@pytest.mark.skipif(not get_user_is_root() or ds_is_older('1.4.0.0'),
fec594
+                    reason="This test is only required with new admin cli, and requires root.")
fec594
+@pytest.mark.bz1807419
fec594
+@pytest.mark.ds50928
fec594
+def test_dscreate_with_different_rdn(dscreate_test_rdn_value):
fec594
+    """Test that dscreate works with different RDN attributes as suffix
fec594
+
fec594
+    :id: 77ed6300-6a2f-4e79-a862-1f1105f1e3ef
fec594
+    :parametrized: yes
fec594
+    :setup: None
fec594
+    :steps:
fec594
+        1. Create template file for dscreate with different RDN attributes as suffix
fec594
+        2. Create instance using template file
fec594
+        3. Create instance with 'wrong=some_value' as suffix's RDN attribute
fec594
+    :expectedresults:
fec594
+        1. Should succeeds
fec594
+        2. Should succeeds
fec594
+        3. Should fail
fec594
+    """
fec594
+    try:
fec594
+        subprocess.check_call([
fec594
+            'dscreate',
fec594
+            'from-file',
fec594
+            dscreate_test_rdn_value[0]
fec594
+        ], env=dscreate_test_rdn_value[1])
fec594
+    except subprocess.CalledProcessError as e:
fec594
+        log.fatal(f"dscreate failed!  Error ({e.returncode}) {e.output}")
fec594
+        if  dscreate_test_rdn_value[2] != "wrong=some_value":
fec594
+            assert False
fec594
+        else:
fec594
+            assert True
fec594
+
fec594
+def test_bind_invalid_entry(topology_st):
fec594
+    """Test the failing bind does not return information about the entry
fec594
+
fec594
+    :id: 5cd9b083-eea6-426b-84ca-83c26fc49a6f
fec594
+
fec594
+    :setup: Standalone instance
fec594
+
fec594
+    :steps:
fec594
+    1: bind as non existing entry
fec594
+    2: check that bind info does not report 'No such entry'
fec594
+
fec594
+    :expectedresults:
fec594
+    1: pass
fec594
+    2: pass
fec594
+    """
fec594
+
fec594
+    topology_st.standalone.restart()
fec594
+    INVALID_ENTRY="cn=foooo,%s" % DEFAULT_SUFFIX
fec594
+    try:
fec594
+        topology_st.standalone.simple_bind_s(INVALID_ENTRY, PASSWORD)
fec594
+    except ldap.LDAPError as e:
fec594
+        log.info('test_bind_invalid_entry: Failed to bind as %s (expected)' % INVALID_ENTRY)
fec594
+        log.info('exception description: ' + e.args[0]['desc'])
fec594
+        if 'info' in e.args[0]:
fec594
+            log.info('exception info: ' + e.args[0]['info'])
fec594
+        assert e.args[0]['desc'] == 'Invalid credentials'
fec594
+        assert 'info' not in e.args[0]
fec594
+        pass
fec594
+
fec594
+    log.info('test_bind_invalid_entry: PASSED')
fec594
+
fec594
+
fec594
 if __name__ == '__main__':
fec594
     # Run isolated
fec594
     # -s for DEBUG mode
fec594
-- 
fec594
2.26.2
fec594