Exemplo n.º 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]
Exemplo n.º 2
0
def test_update(shared_client, cleanup, scan_host, src_type):
    """Create a {network, vcenter} source and then update it.

    :id: 900dda70-6208-44f5-b64d-f6ca4db7dfa4
    :description: Create {network, vcenter} source of single host and
        credential
    :steps:
        1) Create host credential
        2) Send POST with data to create {network, vcenter} source using the
           host credential to the source endpoint.
        3) Add a host and a new credential and send and PUT to the server with
           the data
    :expectedresults: The source entry is created and updated.
    """
    cred = Credential(cred_type=src_type, client=shared_client, password=uuid4())
    cred.create()
    cleanup.append(cred)
    src = Source(
        source_type=src_type,
        client=shared_client,
        hosts=[scan_host],
        credential_ids=[cred._id],
    )
    src.create()
    cleanup.append(src)
    assert_matches_server(src)
    src.hosts = ["example.com"]
    cred2 = Credential(cred_type=src_type, password=uuid4())
    cred2.create()
    cleanup.append(cred2)
    src.credentials = [cred2._id]
    src.update()
    assert_matches_server(src)
Exemplo n.º 3
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)