|
|
f92ce9 |
From b10d004f6461a8dd5d5d2766cf95e92c5d94927e Mon Sep 17 00:00:00 2001
|
|
|
f92ce9 |
From: Mark Reynolds <mreynolds@redhat.com>
|
|
|
f92ce9 |
Date: Thu, 4 Dec 2014 15:57:40 -0500
|
|
|
f92ce9 |
Subject: [PATCH 43/53] Ticket 47970 - add lib389 testcase
|
|
|
f92ce9 |
|
|
|
f92ce9 |
https://fedorahosted.org/389/ticket/47970
|
|
|
f92ce9 |
|
|
|
f92ce9 |
Reviewed by: nhosoi(Thanks!)
|
|
|
f92ce9 |
|
|
|
f92ce9 |
(cherry picked from commit f6929c9b7c24a43b019e966b1fc37d33b21274a1)
|
|
|
f92ce9 |
(cherry picked from commit b6cd13f49713fecf6b2c94a31e25cd726e216c65)
|
|
|
f92ce9 |
---
|
|
|
f92ce9 |
dirsrvtests/tickets/ticket47970_test.py | 206 ++++++++++++++++++++++++++++++++
|
|
|
f92ce9 |
1 file changed, 206 insertions(+)
|
|
|
f92ce9 |
create mode 100644 dirsrvtests/tickets/ticket47970_test.py
|
|
|
f92ce9 |
|
|
|
f92ce9 |
diff --git a/dirsrvtests/tickets/ticket47970_test.py b/dirsrvtests/tickets/ticket47970_test.py
|
|
|
f92ce9 |
new file mode 100644
|
|
|
f92ce9 |
index 0000000..49d505a
|
|
|
f92ce9 |
--- /dev/null
|
|
|
f92ce9 |
+++ b/dirsrvtests/tickets/ticket47970_test.py
|
|
|
f92ce9 |
@@ -0,0 +1,206 @@
|
|
|
f92ce9 |
+import os
|
|
|
f92ce9 |
+import sys
|
|
|
f92ce9 |
+import time
|
|
|
f92ce9 |
+import ldap
|
|
|
f92ce9 |
+import ldap.sasl
|
|
|
f92ce9 |
+import logging
|
|
|
f92ce9 |
+import socket
|
|
|
f92ce9 |
+import pytest
|
|
|
f92ce9 |
+from lib389 import DirSrv, Entry, tools, tasks
|
|
|
f92ce9 |
+from lib389.tools import DirSrvTools
|
|
|
f92ce9 |
+from lib389._constants import *
|
|
|
f92ce9 |
+from lib389.properties import *
|
|
|
f92ce9 |
+from lib389.tasks import *
|
|
|
f92ce9 |
+from constants import *
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+log = logging.getLogger(__name__)
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+installation_prefix = None
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+USER1_DN = "uid=user1,%s" % DEFAULT_SUFFIX
|
|
|
f92ce9 |
+USER2_DN = "uid=user2,%s" % DEFAULT_SUFFIX
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+class TopologyStandalone(object):
|
|
|
f92ce9 |
+ def __init__(self, standalone):
|
|
|
f92ce9 |
+ standalone.open()
|
|
|
f92ce9 |
+ self.standalone = standalone
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+@pytest.fixture(scope="module")
|
|
|
f92ce9 |
+def topology(request):
|
|
|
f92ce9 |
+ '''
|
|
|
f92ce9 |
+ This fixture is used to standalone topology for the 'module'.
|
|
|
f92ce9 |
+ At the beginning, It may exists a standalone instance.
|
|
|
f92ce9 |
+ It may also exists a backup for the standalone instance.
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ Principle:
|
|
|
f92ce9 |
+ If standalone instance exists:
|
|
|
f92ce9 |
+ restart it
|
|
|
f92ce9 |
+ If backup of standalone exists:
|
|
|
f92ce9 |
+ create/rebind to standalone
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ restore standalone instance from backup
|
|
|
f92ce9 |
+ else:
|
|
|
f92ce9 |
+ Cleanup everything
|
|
|
f92ce9 |
+ remove instance
|
|
|
f92ce9 |
+ remove backup
|
|
|
f92ce9 |
+ Create instance
|
|
|
f92ce9 |
+ Create backup
|
|
|
f92ce9 |
+ '''
|
|
|
f92ce9 |
+ global installation_prefix
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ if installation_prefix:
|
|
|
f92ce9 |
+ args_instance[SER_DEPLOYED_DIR] = installation_prefix
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ standalone = DirSrv(verbose=False)
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # Args for the standalone instance
|
|
|
f92ce9 |
+ args_instance[SER_HOST] = HOST_STANDALONE
|
|
|
f92ce9 |
+ args_instance[SER_PORT] = PORT_STANDALONE
|
|
|
f92ce9 |
+ args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
|
|
|
f92ce9 |
+ args_standalone = args_instance.copy()
|
|
|
f92ce9 |
+ standalone.allocate(args_standalone)
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # Get the status of the backups
|
|
|
f92ce9 |
+ backup_standalone = standalone.checkBackupFS()
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # Get the status of the instance and restart it if it exists
|
|
|
f92ce9 |
+ instance_standalone = standalone.exists()
|
|
|
f92ce9 |
+ if instance_standalone:
|
|
|
f92ce9 |
+ # assuming the instance is already stopped, just wait 5 sec max
|
|
|
f92ce9 |
+ standalone.stop(timeout=5)
|
|
|
f92ce9 |
+ standalone.start(timeout=10)
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ if backup_standalone:
|
|
|
f92ce9 |
+ # The backup exist, assuming it is correct
|
|
|
f92ce9 |
+ # we just re-init the instance with it
|
|
|
f92ce9 |
+ if not instance_standalone:
|
|
|
f92ce9 |
+ standalone.create()
|
|
|
f92ce9 |
+ # Used to retrieve configuration information (dbdir, confdir...)
|
|
|
f92ce9 |
+ standalone.open()
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # restore standalone instance from backup
|
|
|
f92ce9 |
+ standalone.stop(timeout=10)
|
|
|
f92ce9 |
+ standalone.restoreFS(backup_standalone)
|
|
|
f92ce9 |
+ standalone.start(timeout=10)
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ else:
|
|
|
f92ce9 |
+ # We should be here only in two conditions
|
|
|
f92ce9 |
+ # - This is the first time a test involve standalone instance
|
|
|
f92ce9 |
+ # - Something weird happened (instance/backup destroyed)
|
|
|
f92ce9 |
+ # so we discard everything and recreate all
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # Remove the backup. So even if we have a specific backup file
|
|
|
f92ce9 |
+ # (e.g backup_standalone) we clear backup that an instance may have created
|
|
|
f92ce9 |
+ if backup_standalone:
|
|
|
f92ce9 |
+ standalone.clearBackupFS()
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # Remove the instance
|
|
|
f92ce9 |
+ if instance_standalone:
|
|
|
f92ce9 |
+ standalone.delete()
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # Create the instance
|
|
|
f92ce9 |
+ standalone.create()
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # Used to retrieve configuration information (dbdir, confdir...)
|
|
|
f92ce9 |
+ standalone.open()
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # Time to create the backups
|
|
|
f92ce9 |
+ standalone.stop(timeout=10)
|
|
|
f92ce9 |
+ standalone.backupfile = standalone.backupFS()
|
|
|
f92ce9 |
+ standalone.start(timeout=10)
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # clear the tmp directory
|
|
|
f92ce9 |
+ standalone.clearTmpDir(__file__)
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ #
|
|
|
f92ce9 |
+ # Here we have standalone instance up and running
|
|
|
f92ce9 |
+ # Either coming from a backup recovery
|
|
|
f92ce9 |
+ # or from a fresh (re)init
|
|
|
f92ce9 |
+ # Time to return the topology
|
|
|
f92ce9 |
+ return TopologyStandalone(standalone)
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+def test_ticket47970(topology):
|
|
|
f92ce9 |
+ """
|
|
|
f92ce9 |
+ Testing that a failed SASL bind does not trigger account lockout -
|
|
|
f92ce9 |
+ which would attempt to update the passwordRetryCount on the root dse entry
|
|
|
f92ce9 |
+ """
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ log.info('Testing Ticket 47970 - Testing that a failed SASL bind does not trigger account lockout')
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ #
|
|
|
f92ce9 |
+ # Enable account lockout
|
|
|
f92ce9 |
+ #
|
|
|
f92ce9 |
+ try:
|
|
|
f92ce9 |
+ topology.standalone.modify_s("cn=config", [(ldap.MOD_REPLACE, 'passwordLockout', 'on')])
|
|
|
f92ce9 |
+ log.info('account lockout enabled.')
|
|
|
f92ce9 |
+ except ldap.LDAPError, e:
|
|
|
f92ce9 |
+ log.error('Failed to enable account lockout: ' + e.message['desc'])
|
|
|
f92ce9 |
+ assert False
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ try:
|
|
|
f92ce9 |
+ topology.standalone.modify_s("cn=config", [(ldap.MOD_REPLACE, 'passwordMaxFailure', '5')])
|
|
|
f92ce9 |
+ log.info('passwordMaxFailure set.')
|
|
|
f92ce9 |
+ except ldap.LDAPError, e:
|
|
|
f92ce9 |
+ log.error('Failed to to set passwordMaxFailure: ' + e.message['desc'])
|
|
|
f92ce9 |
+ assert False
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ #
|
|
|
f92ce9 |
+ # Perform SASL bind that should fail
|
|
|
f92ce9 |
+ #
|
|
|
f92ce9 |
+ failed_as_expected = False
|
|
|
f92ce9 |
+ try:
|
|
|
f92ce9 |
+ user_name = "mark"
|
|
|
f92ce9 |
+ pw = "secret"
|
|
|
f92ce9 |
+ auth_tokens = ldap.sasl.digest_md5(user_name, pw)
|
|
|
f92ce9 |
+ topology.standalone.sasl_interactive_bind_s("", auth_tokens)
|
|
|
f92ce9 |
+ except ldap.INVALID_CREDENTIALS, e:
|
|
|
f92ce9 |
+ log.info("SASL Bind failed as expected")
|
|
|
f92ce9 |
+ failed_as_expected = True
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ if not failed_as_expected:
|
|
|
f92ce9 |
+ log.error("SASL bind unexpectedly succeeded!")
|
|
|
f92ce9 |
+ assert False
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ #
|
|
|
f92ce9 |
+ # Check that passwordRetryCount was not set on the root dse entry
|
|
|
f92ce9 |
+ #
|
|
|
f92ce9 |
+ try:
|
|
|
f92ce9 |
+ entry = topology.standalone.search_s("", ldap.SCOPE_BASE,
|
|
|
f92ce9 |
+ "passwordRetryCount=*",
|
|
|
f92ce9 |
+ ['passwordRetryCount'])
|
|
|
f92ce9 |
+ except ldap.LDAPError, e:
|
|
|
f92ce9 |
+ log.error('Failed to search Root DSE entry: ' + e.message['desc'])
|
|
|
f92ce9 |
+ assert False
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ if entry:
|
|
|
f92ce9 |
+ log.error('Root DSE was incorrectly updated')
|
|
|
f92ce9 |
+ assert False
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ # We passed
|
|
|
f92ce9 |
+ log.info('Root DSE was correctly not updated')
|
|
|
f92ce9 |
+ log.info("Test Passed.")
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+def test_ticket47970_final(topology):
|
|
|
f92ce9 |
+ topology.standalone.stop(timeout=10)
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+def run_isolated():
|
|
|
f92ce9 |
+ '''
|
|
|
f92ce9 |
+ run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
|
|
|
f92ce9 |
+ To run isolated without py.test, you need to
|
|
|
f92ce9 |
+ - edit this file and comment '@pytest.fixture' line before 'topology' function.
|
|
|
f92ce9 |
+ - set the installation prefix
|
|
|
f92ce9 |
+ - run this program
|
|
|
f92ce9 |
+ '''
|
|
|
f92ce9 |
+ global installation_prefix
|
|
|
f92ce9 |
+ installation_prefix = None
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+ topo = topology(True)
|
|
|
f92ce9 |
+ test_ticket47970(topo)
|
|
|
f92ce9 |
+
|
|
|
f92ce9 |
+if __name__ == '__main__':
|
|
|
f92ce9 |
+ run_isolated()
|
|
|
f92ce9 |
\ No newline at end of file
|
|
|
f92ce9 |
--
|
|
|
f92ce9 |
1.9.3
|
|
|
f92ce9 |
|