Exemplo n.º 1
0
def step_impl(context, aip_description, second_aip_description, event_type):
    aip_ptr_attr = utils.aip_descr_to_ptr_attr(aip_description)
    pointer_path = getattr(context.scenario, aip_ptr_attr)
    second_aip_attr = utils.aip_descr_to_attr(second_aip_description)
    second_aip_uuid = getattr(context.scenario, second_aip_attr)
    event_uuid_attr = utils.get_event_attr(event_type)
    event_uuid = getattr(context.scenario, event_uuid_attr)
    with open(pointer_path) as filei:
        doc = etree.parse(filei)
        premis_object_el = doc.find(
            './/mets:mdWrap[@MDTYPE="PREMIS:OBJECT"]', context.am_user.mets.mets_nsmap
        )
        premis_relationship = premis_object_el.find(
            "mets:xmlData/premis:object/premis:relationship",
            context.am_user.mets.mets_nsmap,
        )
        premis_relationship_type = premis_relationship.find(
            "premis:relationshipType", context.am_user.mets.mets_nsmap
        ).text.strip()
        assert premis_relationship_type == "derivation"
        premis_related_object_uuid = premis_relationship.find(
            "premis:relatedObjectIdentifier/premis:relatedObjectIdentifierValue",
            context.am_user.mets.mets_nsmap,
        ).text.strip()
        assert second_aip_uuid == premis_related_object_uuid
        premis_related_event_uuid = premis_relationship.find(
            "premis:relatedEventIdentifier/premis:relatedEventIdentifierValue",
            context.am_user.mets.mets_nsmap,
        ).text.strip()
        assert event_uuid == premis_related_event_uuid
Exemplo n.º 2
0
def step_impl(context, aip_description, event_type):
    aip_ptr_attr = utils.aip_descr_to_ptr_attr(aip_description)
    pointer_path = getattr(context.scenario, aip_ptr_attr)
    event_uuid = assert_pointer_premis_event(context=context,
                                             pointer_path=pointer_path,
                                             event_type=event_type,
                                             in_evt_out=['success'])
    event_uuid_attr = utils.get_event_attr(event_type)
    setattr(context.scenario, event_uuid_attr, event_uuid)
Exemplo n.º 3
0
def step_impl(context, aip_description):
    aip_attr = utils.aip_descr_to_attr(aip_description)
    aip_ptr_attr = utils.aip_descr_to_ptr_attr(aip_description)
    aip_uuid = getattr(context.scenario, aip_attr)
    time.sleep(context.am_user.pessimistic_wait)
    setattr(
        context.scenario, aip_ptr_attr,
        context.am_user.api.download_aip_pointer_file(
            aip_uuid, context.am_user.browser.ss_api_key))
    logger.info('downloaded AIP pointer file for %s AIP %s to %s',
                aip_description, aip_uuid,
                getattr(context.scenario, aip_ptr_attr))
Exemplo n.º 4
0
def get_aip_is_encrypted(context, aip_description):
    aip_description = aip_description.strip()
    if aip_description:
        aip_ptr_attr = utils.aip_descr_to_ptr_attr(aip_description + "_aip")
        pointer_path = getattr(context.scenario, aip_ptr_attr)
    else:
        pointer_path = context.scenario.aip_pointer_path
    ns = context.am_user.mets.mets_nsmap
    with open(pointer_path) as filei:
        doc = etree.parse(filei)
        file_el = doc.find("mets:fileSec/mets:fileGrp/mets:file", ns)
        flocat_el = file_el.find("mets:FLocat", ns)
        xlink_href = flocat_el.get("{" + ns["xlink"] + "}href")
        # Copy the AIP on the server to a local directory.
        if getattr(context.am_user.docker, "docker_compose_path", None):
            aip_local_path = context.am_user.docker.cp_server_file_to_local(xlink_href)
        elif context.am_user.ssh_accessible:
            aip_local_path = context.am_user.ssh.scp_server_file_to_local(xlink_href)
        else:
            aip_local_path = context.am_user.localfs.read_server_file(xlink_href)
        if aip_local_path is None:
            logger.warning(
                "Unable to copy file %s from the server to the local file"
                " system. Server is not accessible via SSH. Abandoning"
                " attempt to assert that the AIP on disk is"
                " encrypted.",
                xlink_href,
            )
            return
        elif aip_local_path is False:
            logger.warning(
                "Unable to copy file %s from the server to the local file"
                " system. Attempt to scp the file failed. Abandoning attempt"
                " to assert that the AIP on disk is"
                " encrypted.",
                xlink_href,
            )
            return
    aip_local_path = context.am_user.decompress_package(aip_local_path)
    # ``decompress_package`` will attempt to decompress the package with 7z and
    # we expect it to fail because the AIP file is encrypted with GPG.
    aip_is_encrypted = aip_local_path is None
    return aip_is_encrypted
Exemplo n.º 5
0
def step_impl(context, aip_description):
    """Makes the following assertions about the first (and presumably only)
    <mets:file> element in the AIP's pointer file:
    1. the xlink:href attribute's value of <mets:FLocat> is a path with
       extension .gpg
    2. the decompression-type <mets:transformFile> has TRANSFORMORDER 2
    3. there is a new <mets:transformFile> element for the decryption event
       needed to get at this AIP.
    4. <premis:compositionLevel> incremented
    5. <premis:inhibitors> added
    """
    aip_description = aip_description.strip()
    if aip_description:
        aip_ptr_attr = utils.aip_descr_to_ptr_attr(aip_description)
        pointer_path = getattr(context.scenario, aip_ptr_attr)
    else:
        pointer_path = context.scenario.aip_pointer_path
    ns = context.am_user.mets.mets_nsmap
    assert_pointer_transform_file_encryption(pointer_path, ns)
Exemplo n.º 6
0
def get_aip_is_encrypted(context, aip_description):
    aip_description = aip_description.strip()
    if aip_description:
        aip_ptr_attr = utils.aip_descr_to_ptr_attr(aip_description + '_aip')
        pointer_path = getattr(context.scenario, aip_ptr_attr)
    else:
        pointer_path = context.scenario.aip_pointer_path
    ns = context.am_user.mets.mets_nsmap
    with open(pointer_path) as filei:
        doc = etree.parse(filei)
        file_el = doc.find('mets:fileSec/mets:fileGrp/mets:file', ns)
        flocat_el = file_el.find('mets:FLocat', ns)
        xlink_href = flocat_el.get('{' + ns['xlink'] + '}href')
        # Use `scp` or `docker cp` to copy the AIP on the server to a local
        # directory.
        if getattr(context.am_user.docker, 'docker_compose_path', None):
            aip_local_path = context.am_user.docker.cp_server_file_to_local(
                xlink_href)
        else:
            aip_local_path = context.am_user.ssh.scp_server_file_to_local(
                xlink_href)
        if aip_local_path is None:
            logger.warning(
                'Unable to copy file %s from the server to the local file'
                ' system. Server is not accessible via SSH. Abandoning'
                ' attempt to assert that the AIP on disk is'
                ' encrypted.', xlink_href)
            return
        elif aip_local_path is False:
            logger.warning(
                'Unable to copy file %s from the server to the local file'
                ' system. Attempt to scp the file failed. Abandoning attempt'
                ' to assert that the AIP on disk is'
                ' encrypted.', xlink_href)
            return
    aip_local_path = context.am_user.decompress_package(aip_local_path)
    # ``decompress_package`` will attempt to decompress the package with 7z and
    # we expect it to fail because the AIP file is encrypted with GPG.
    aip_is_encrypted = aip_local_path is None
    return aip_is_encrypted