示例#1
0
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]
示例#2
0
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)