def test_plugin_cli(topology): args = FakeArgs() plugin_list(topology.standalone, None, topology.logcap.log, None) for p in plugins: assert(topology.logcap.contains(p)) topology.logcap.flush() # print(topology.logcap.outputs) # Need to delete something, then re-add it. args.selector = 'USN' plugin_get(topology.standalone, None, topology.logcap.log, args) assert(topology.logcap.contains('USN')) topology.logcap.flush() args.dn = 'cn=USN,cn=plugins,cn=config' plugin_get_dn(topology.standalone, None, topology.logcap.log, args) assert(topology.logcap.contains('USN')) topology.logcap.flush() plugin_disable(topology.standalone, None, topology.logcap.log, args, warn=False) assert(topology.logcap.contains('Disabled')) topology.logcap.flush() plugin_enable(topology.standalone, None, topology.logcap.log, args) assert(topology.logcap.contains('Enabled')) topology.logcap.flush()
def test_backend_cli(topology): # args = FakeArgs() backend_list(topology.standalone, None, topology.logcap.log, None) # Assert none. assert(topology.logcap.contains("No objects to display")) topology.logcap.flush() # Add a backend # We need to fake the args args.extra = ['dc=example,dc=com', 'userRoot'] backend_create(topology.standalone, None, topology.logcap.log, args) # Assert one. backend_list(topology.standalone, None, topology.logcap.log, None) # Assert none. assert(topology.logcap.contains("userRoot")) topology.logcap.flush() # Assert we can get by name, suffix, dn args.selector = 'userRoot' backend_get(topology.standalone, None, topology.logcap.log, args) # Assert none. assert(topology.logcap.contains("userRoot")) topology.logcap.flush() # Assert we can get by name, suffix, dn args.dn = 'cn=userRoot,cn=ldbm database,cn=plugins,cn=config' backend_get_dn(topology.standalone, None, topology.logcap.log, args) # Assert none. assert(topology.logcap.contains("userRoot")) topology.logcap.flush() # delete it backend_delete(topology.standalone, None, topology.logcap.log, args, warn=False) backend_list(topology.standalone, None, topology.logcap.log, None) # Assert none. assert(topology.logcap.contains("No objects to display")) topology.logcap.flush()
def test_dsidm_organizational_unit_delete(topology_st, create_test_ou): """ Test dsidm organizationalunit delete :id: 5d35a5ee-85c2-4b83-9101-938ba7732ccd :customerscenario: True :setup: Standalone instance :steps: 1. Run dsidm organizationalunit delete 2. Check the ou is deleted :expectedresults: 1. Success 2. Entry is deleted """ standalone = topology_st.standalone ous = OrganizationalUnits(standalone, DEFAULT_SUFFIX) test_ou = ous.get('toDelete') delete_value = 'Successfully deleted {}'.format(test_ou.dn) args = FakeArgs() args.dn = test_ou.dn log.info('Test dsidm organizationalunit delete') delete(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False) check_value_in_log_and_reset(topology_st, check_value=delete_value) log.info('Check the entry is deleted') assert not test_ou.exists()
def test_dsidm_user_delete(topology_st, create_test_user): """ Test dsidm user delete option :id: 3704dc3a-9787-4f74-aaa8-45f38e4a6a52 :setup: Standalone instance :steps: 1. Run dsidm user delete on created user 2. Check that a message is provided on deletion 3. Check that user does not exist :expectedresults: 1. Success 2. Success 3. Success """ standalone = topology_st.standalone users = nsUserAccounts(standalone, DEFAULT_SUFFIX) test_user = users.get('test_user_1000') output = 'Successfully deleted {}'.format(test_user.dn) args = FakeArgs() args.dn = test_user.dn log.info('Test dsidm user delete') delete(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False) check_value_in_log_and_reset(topology_st, check_value=output) log.info('Check that user does not exist') assert not test_user.exists()
def test_dsidm_service_delete(topology_st, create_test_service): """ Test dsidm service delete option :id: 3b382a96-51e1-11ec-a1c2-3497f624ea11 :setup: Standalone instance :steps: 1. Run dsidm service delete on created service 2. Check that a message is provided on deletion 3. Check that service does not exist :expectedresults: 1. Success 2. Success 3. Success """ standalone = topology_st.standalone services = ServiceAccounts(standalone, DEFAULT_SUFFIX) test_service = services.get('test_service') output = f'Successfully deleted {test_service.dn}' args = FakeArgs() args.dn = test_service.dn log.info('Test dsidm service delete') delete(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args, warn=False) check_value_in_log_and_reset(topology_st, check_value=output) log.info('Check that service does not exist') assert not test_service.exists()
def test_backend_cli(topology): # args = FakeArgs() backend_list(topology.standalone, None, topology.logcap.log, None) # Assert none. assert (topology.logcap.contains("No objects to display")) topology.logcap.flush() # Add a backend # We need to fake the args args.cn = 'userRoot' args.nsslapd_suffix = 'dc=example,dc=com' backend_create(topology.standalone, None, topology.logcap.log, args) # Assert one. backend_list(topology.standalone, None, topology.logcap.log, None) # Assert none. assert (topology.logcap.contains("userRoot")) topology.logcap.flush() # Assert we can get by name, suffix, dn args.selector = 'userRoot' backend_get(topology.standalone, None, topology.logcap.log, args) # Assert none. assert (topology.logcap.contains("userRoot")) topology.logcap.flush() # Assert we can get by name, suffix, dn args.dn = 'cn=userRoot,cn=ldbm database,cn=plugins,cn=config' backend_get_dn(topology.standalone, None, topology.logcap.log, args) # Assert none. assert (topology.logcap.contains("userRoot")) topology.logcap.flush() # delete it backend_delete(topology.standalone, None, topology.logcap.log, args, warn=False) backend_list(topology.standalone, None, topology.logcap.log, None) # Assert none. assert (topology.logcap.contains("No objects to display")) topology.logcap.flush()
def test_dsidm_user_get_dn(topology_st, create_test_user): """ Test dsidm user get_dn option :id: 787bf278-87c3-402e-936e-6161799d098d :setup: Standalone instance :steps: 1. Run dsidm user get_dn for created user 2. Check the output content is correct :expectedresults: 1. Success 2. Success """ standalone = topology_st.standalone users = nsUserAccounts(standalone, DEFAULT_SUFFIX) test_user = users.get('test_user_1000') args = FakeArgs() args.dn = test_user.dn log.info('Empty the log file to prevent false data to check about user') topology_st.logcap.flush() log.info('Test dsidm user get_dn without json') get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
def test_dsidm_service_get_dn(topology_st, create_test_service): """ Test dsidm service get_dn option :id: 2e4c8f98-51e1-11ec-b472-3497f624ea11 :setup: Standalone instance :steps: 1. Run dsidm service get_dn for created service 2. Check the output content is correct :expectedresults: 1. Success 2. Success """ standalone = topology_st.standalone services = ServiceAccounts(standalone, DEFAULT_SUFFIX) test_service = services.get('test_service') args = FakeArgs() args.dn = test_service.dn log.info('Empty the log file to prevent false data to check about service') topology_st.logcap.flush() log.info('Test dsidm service get_dn without json') get_dn(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args)
def test_group_tasks(topology): # First check that our test group isn't there: topology.logcap.flush() g_args = FakeArgs() g_args.selector = 'testgroup' with pytest.raises(ldap.NO_SUCH_OBJECT): get(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, g_args) # Create a group topology.logcap.flush() g_args.cn = 'testgroup' create(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, g_args) assert (topology.logcap.contains("Sucessfully created testgroup")) # Assert it exists topology.logcap.flush() g_args = FakeArgs() g_args.selector = 'testgroup' get(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, g_args) assert (topology.logcap.contains( "dn: cn=testgroup,ou=groups,dc=example,dc=com")) # Add a user topology.logcap.flush() u_args = FakeArgs() u_args.uid = 'testuser' u_args.cn = 'Test User' u_args.displayName = 'Test User' u_args.homeDirectory = '/home/testuser' u_args.uidNumber = '5000' u_args.gidNumber = '5000' create_user(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, u_args) assert (topology.logcap.contains("Sucessfully created testuser")) # Add them to the group as a member topology.logcap.flush() g_args.cn = "testgroup" g_args.dn = "uid=testuser,ou=people,dc=example,dc=com" add_member(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, g_args) assert (topology.logcap.contains("added member")) # Check they are a member topology.logcap.flush() g_args.cn = "testgroup" members(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, g_args) assert ( topology.logcap.contains("uid=testuser,ou=people,dc=example,dc=com")) # Remove them from the group topology.logcap.flush() g_args.cn = "testgroup" g_args.dn = "uid=testuser,ou=people,dc=example,dc=com" remove_member(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, g_args) assert (topology.logcap.contains("removed member")) # Check they are not a member topology.logcap.flush() g_args.cn = "testgroup" members(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, g_args) assert (topology.logcap.contains("No members to display")) # Delete the group topology.logcap.flush() g_args.dn = "cn=testgroup,ou=groups,dc=example,dc=com" delete(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, g_args, warn=False) assert (topology.logcap.contains( "Sucessfully deleted cn=testgroup,ou=groups,dc=example,dc=com"))
def test_dsidm_account_entry_status_with_lock(topology_st, create_test_user): """ Test dsidm account entry-status option with account lock/unlock :id: d911bbf2-3a65-42a4-ad76-df1114caa396 :setup: Standalone instance :steps: 1. Create user account 2. Run dsidm account entry status 3. Run dsidm account lock 4. Run dsidm account entry status 5. Run dsidm account unlock 6. Run dsidm account entry status :expectedresults: 1. Success 2. The state message should be Entry State: activated 3. Success 4. The state message should be Entry State: directly locked through nsAccountLock 5. Success 6. The state message should be Entry State: activated """ standalone = topology_st.standalone users = nsUserAccounts(standalone, DEFAULT_SUFFIX) test_user = users.get('test_user_1000') entry_list = [ 'Entry DN: {}'.format(test_user.dn), 'Entry Creation Date', 'Entry Modification Date' ] state_lock = 'Entry State: directly locked through nsAccountLock' state_unlock = 'Entry State: activated' lock_msg = 'Entry {} is locked'.format(test_user.dn) unlock_msg = 'Entry {} is unlocked'.format(test_user.dn) args = FakeArgs() args.dn = test_user.dn args.json = False log.info('Test dsidm account entry-status') entry_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) check_value_in_log_and_reset(topology_st, content_list=entry_list, check_value=state_unlock) log.info('Test dsidm account lock') lock(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) check_value_in_log_and_reset(topology_st, check_value=lock_msg) log.info('Test dsidm account entry-status with locked account') entry_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) check_value_in_log_and_reset(topology_st, content_list=entry_list, check_value=state_lock) log.info('Test dsidm account unlock') unlock(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) check_value_in_log_and_reset(topology_st, check_value=unlock_msg) log.info('Test dsidm account entry-status with unlocked account') entry_status(standalone, DEFAULT_SUFFIX, topology_st.logcap.log, args) check_value_in_log_and_reset(topology_st, content_list=entry_list, check_value=state_unlock)
def test_backend_cli(topology_st, create_backend): """Test creating, listing, getting, and deleting a backend (and subsuffix) :id: 800f432a-52ab-4661-ac66-a2bdd9b984d7 :setup: Standalone instance :steps: 1. List backends 2. Get backend by suffix 3. Get backend by DN 4. Add subsuffix 5. Verify subsuffix 6. Modify subsuffix 7. Delete subsuffix 8. Verify subsuffix is removed 9. Modify backend 10. Verify modify worked 11. Test monitor works :expectedresults: 1. Success 2. Success 3. Success 4. Success 5. Success 6. Success 7. Success 8. Success 9. Success 10. Success 11. Success """ topology_st.logcap = LogCapture() sys.stdout = io.StringIO() args = FakeArgs() args.cn = BE_NAME args.be_name = BE_NAME args.suffix = False args.nsslapd_suffix = SUFFIX args.skip_subsuffixes = False args.json = False args.parent_suffix = False args.create_entries = True # List backend backend_list(topology_st.standalone, None, topology_st.logcap.log, args) check_output(SUFFIX) # Get backend by by name args.selector = BE_NAME backend_get(topology_st.standalone, None, topology_st.logcap.log, args) check_output(BE_NAME) # Get backend by DN args.dn = 'cn=backendRoot,cn=ldbm database,cn=plugins,cn=config' backend_get_dn(topology_st.standalone, None, topology_st.logcap.log, args) check_output(BE_NAME) # Add subsuffix args.parent_suffix = SUFFIX args.suffix = SUB_SUFFIX args.be_name = SUB_BE_NAME backend_create(topology_st.standalone, None, topology_st.logcap.log, args) check_output("The database was successfully created") # Verify subsuffix args.suffix = False backend_list(topology_st.standalone, None, topology_st.logcap.log, args) check_output(SUB_SUFFIX) # Modify subsuffix args.enable = False args.disable = False args.add_referral = False args.del_referral = False args.cache_size = False args.cache_memsize = False args.dncache_memsize = False args.enable_readonly = True # Setting nsslapd-readonly to "on" args.disable_readonly = False backend_set(topology_st.standalone, None, topology_st.logcap.log, args) check_output("successfully updated") # Verify modified worked args.selector = SUB_BE_NAME backend_get(topology_st.standalone, None, topology_st.logcap.log, args) check_output("nsslapd-readonly: on") # Delete subsuffix args.suffix = SUB_SUFFIX backend_delete(topology_st.standalone, None, topology_st.logcap.log, args, warn=False) check_output("successfully deleted") # Verify it is deleted args.suffix = False backend_list(topology_st.standalone, None, topology_st.logcap.log, args) check_output(SUB_BE_NAME, missing=True) # Modify backend (use same args from subsuffix modify) args.be_name = BE_NAME backend_set(topology_st.standalone, None, topology_st.logcap.log, args) check_output("successfully updated") # Verify modified worked args.selector = BE_NAME backend_get(topology_st.standalone, None, topology_st.logcap.log, args) check_output("nsslapd-readonly: on") # Run database monitor args.suffix = SUFFIX get_monitor(topology_st.standalone, None, topology_st.logcap.log, args) check_output("entrycachetries")
def test_user_tasks(topology): be_args = FakeArgs() be_args.cn = 'userRoot' be_args.nsslapd_suffix = DEFAULT_SUFFIX backend_create(topology.standalone, None, topology.logcap.log, be_args) # And add the skeleton objects. init_args = FakeArgs() init_args.version = INSTALL_LATEST_CONFIG initialise(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, init_args) # First check that our test user isn't there: topology.logcap.flush() u_args = FakeArgs() u_args.selector = 'testuser' with pytest.raises(ldap.NO_SUCH_OBJECT): get(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, u_args) # Create the user topology.logcap.flush() u_args.uid = 'testuser' # u_args.sn = 'testuser' u_args.cn = 'Test User' u_args.displayName = 'Test User' u_args.homeDirectory = '/home/testuser' u_args.uidNumber = '5000' u_args.gidNumber = '5000' create(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, u_args) assert(topology.logcap.contains("Sucessfully created testuser")) # Assert they exist topology.logcap.flush() get(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, u_args) assert(topology.logcap.contains('dn: uid=testuser,ou=people,dc=example,dc=com')) # Reset the password # Lock the account, check status topology.logcap.flush() lock(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, u_args) assert(topology.logcap.contains('locked')) topology.logcap.flush() status(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, u_args) assert(topology.logcap.contains('locked: True')) # Unlock check status topology.logcap.flush() unlock(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, u_args) assert(topology.logcap.contains('unlocked')) topology.logcap.flush() status(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, u_args) assert(topology.logcap.contains('locked: False')) # Enroll a dummy cert # Enroll a dummy sshkey # Delete it topology.logcap.flush() u_args.dn = 'uid=testuser,ou=people,dc=example,dc=com' delete(topology.standalone, DEFAULT_SUFFIX, topology.logcap.log, u_args, warn=False) assert(topology.logcap.contains('Sucessfully deleted uid=testuser,ou=people,dc=example,dc=com'))