def test_update_with_invalid_src_type(src_type, scan_host, cleanup): """Attempt to update exclude_hosts with a non-network source type. :id: 66467eb5-79ab-4430-9957-b49fca4cd9ef :description: Create valid non-network source, and then attempt to update it with an excluded hostname option. :steps: 1) Create valid credential and source that isn't a network type 2) Update the source with an excluded host :expectedresults: Error codes are returned and the source is not updated. """ src = gen_valid_source(cleanup, src_type, scan_host) original_data = copy.deepcopy(src.fields()) src.exclude_hosts = ["10.10.10.10"] assert_source_update_fails(original_data, src)
def test_negative_update_invalid(src_type, shared_client, cleanup, scan_host, invalid_host): """Create a host manager source and then update it with invalid data. :id: d57d8481-54e3-4d9a-b330-80edc9364f37 :description: Create host manager source of single host and credential, then attempt to update it with multiple {hosts, credentials} :steps: 1) Create a valid host manager credential and source 2) Attempt to update with multiple {hosts, credentials} :expectedresults: An error is thrown and no new host is created. """ # initialize & create original credential & source pwd_cred = Credential(cred_type=src_type, client=shared_client, password=uuid4()) pwd_cred.create() src = Source( source_type=src_type, client=shared_client, hosts=scan_host, credential_ids=[pwd_cred._id], ) src.create() # Create extra credential for update cred2 = Credential(cred_type="network", client=shared_client, password=uuid4()) cred2.create() # add the ids to the lists to destroy after the test is done cleanup.extend([pwd_cred, src, cred2]) original_data = copy.deepcopy(src.fields()) src.client = api.Client(api.echo_handler) # Try to update with multiple credentials src.credentials = [pwd_cred._id, cred2._id] assert_source_update_fails(original_data, src) # Try to update with multiple hosts src.hosts = invalid_host assert_source_update_fails(original_data, src) # Try to update with multiple hosts & creds src.hosts = invalid_host src.credentials = [pwd_cred._id, cred2._id]
def test_update_with_bad_exclude_host(src_type, scan_host, cleanup): """Attempt to update valid source with an invalid excluded host. :id: 62cc08ad-1149-4c2b-a4ad-0e4c07d10ff6 :description: Create valid {network, vcenter} source, and then attempt to update it with an invalid excluded hostname option. :steps: 1) Create valid credential and source 2) Update the source with an invalid excluded host :expectedresults: Error codes are returned and the source is not updated. """ src = gen_valid_source(cleanup, src_type, scan_host) original_data = src.fields() # Test updating source with bad excluded host src.exclude_hosts = ["*invalid!!host&*"] assert_source_update_fails(original_data, src)
def test_update_with_bad_host(src_type, scan_host, cleanup): """Attempt to update valid source with an invalid host. :id: 26176135-b147-46bc-b0b5-57d5bc515b72 :description: Create valid {network, vcenter} source, and then attempt to update it with invalid hostname. :steps: 1) Create valid credential and source 2) Update the source with an invalid host :expectedresults: Error codes are returned and the source is not updated. """ src = gen_valid_source(cleanup, src_type, scan_host) original_data = copy.deepcopy(src.fields()) # Test updating source with bad host src.hosts = ["*invalid!!host&*"] assert_source_update_fails(original_data, src)
def test_update_remove_field(src_type, cleanup, field): """Attempt to update valid source with either no hosts or no credentials. :id: 49feb858-319f-4f77-b330-65426dfd1734 :description: Create valid {network, vcenter} source, and then attempt to update it to have either no credentials or no hosts. :steps: 1) Create valid credential and source 2) Update the source with no credentials or no hosts :expectedresults: Error codes are returned and the source is not updated. """ src = gen_valid_source(cleanup, src_type, "localhost") # we have to use deep copy because these are nested dictionaries original_data = copy.deepcopy(src.fields()) setattr(src, field, []) assert_source_update_fails(original_data, src)
def test_negative_update_invalid( shared_client, cleanup, isolated_filesystem, scan_host ): """Create a network source and then update it with invalid data. :id: e0d72f2b-2490-445e-b646-f06ceb4ad23f :description: Create network source of single host and credential, then attempt to update it with multiple invalid {hosts, credentials} :steps: 1) Create a valid network credential and source 2) Attempt to update with multiple invalid {hosts, credentials} :expectedresults: An error is thrown and no new host is created. """ sshkeyfile_name = utils.uuid4() tmp_dir = os.path.basename(os.getcwd()) sshkeyfile = Path(sshkeyfile_name) sshkeyfile.touch() net_cred = Credential( cred_type=NETWORK_TYPE, client=shared_client, ssh_keyfile=f"/sshkeys/{tmp_dir}/{sshkeyfile_name}", ) net_cred.create() sat_cred = Credential(cred_type="satellite", client=shared_client, password=uuid4()) sat_cred.create() src = Source( source_type=NETWORK_TYPE, client=shared_client, hosts=[scan_host], credential_ids=[net_cred._id], ) src.create() # add the ids to the lists to destroy after the test is done cleanup.extend([net_cred, sat_cred, src]) original_data = copy.deepcopy(src.fields()) src.client = api.Client(api.echo_handler) # Try to update with invalid credential type src.credentials = [sat_cred._id] assert_source_update_fails(original_data, src) src.hosts = ["1**2@33^"] assert_source_update_fails(original_data, src)
def test_update_bad_credential(src_type, scan_host, cleanup): """Attempt to update valid source with invalid data. :id: 79954c63-608c-46b3-81eb-e2a1e984473e :description: Create valid {network, vcenter} source, and then attempt to update it with an invalid credential. :steps: 1) Create valid credential and source 2) Update the source with invalid credentials :expectedresults: Error codes are returned and the source is not updated. """ src = gen_valid_source(cleanup, src_type, scan_host) original_data = copy.deepcopy(src.fields()) # Case "a" add credential that doesnt exist # The server never assigns negative values src.credentials = [-1] assert_source_update_fails(original_data, src)