Exemplo n.º 1
0
def test_internal_get_signed_url_no_location_match(
        app, supported_action, supported_protocol,
        indexd_client_accepting_record):
    """
    Test fence.blueprints.data.indexd.IndexedFile call to _get_signed_url with location not found
    """
    indexd_record_with_non_public_authz_and_public_acl_populated = {
        "urls": [f"{supported_protocol}://some/location"],
        "authz": ["/programs/DEV/projects/test"],
        "acl": ["*"],
    }
    indexd_client_accepting_record(
        indexd_record_with_non_public_authz_and_public_acl_populated)

    with patch("fence.blueprints.data.indexd.flask.current_app",
               return_value=app):
        indexed_file = IndexedFile(file_id="some id")
        with patch(
                "fence.blueprints.data.indexd.IndexedFile.indexed_file_locations",
                return_value=[],
        ):
            with pytest.raises(NotFound):
                indexed_file._get_signed_url(
                    protocol=supported_protocol,
                    action=supported_action,
                    expires_in=10,
                    force_signed_url=True,
                    r_pays_project=None,
                    file_name="some file",
                )
Exemplo n.º 2
0
def test_internal_get_signed_url_no_protocol_index_error(
        app, supported_action, supported_protocol,
        indexd_client_accepting_record):
    """
    Test fence.blueprints.data.indexd.IndexedFile call to get_signed_url
    without a protocol gives NotFound error
    """
    indexd_record_with_non_public_authz_and_public_acl_populated = {
        "urls": [f"{supported_protocol}://some/location"],
        "authz": ["/programs/DEV/projects/test"],
        "acl": ["*"],
    }
    indexd_client_accepting_record(
        indexd_record_with_non_public_authz_and_public_acl_populated)

    with patch("fence.blueprints.data.indexd.flask.current_app",
               return_value=app):
        indexed_file = IndexedFile(file_id="some id")
        with patch(
                "fence.blueprints.data.indexd.IndexedFileLocation.get_signed_url",
                side_effect=IndexError(),
        ):
            with patch(
                    "fence.blueprints.data.indexd.S3IndexedFileLocation.get_signed_url",
                    side_effect=IndexError(),
            ):
                with patch(
                        "fence.blueprints.data.indexd.GoogleStorageIndexedFileLocation.get_signed_url",
                        side_effect=IndexError(),
                ):
                    with patch(
                            "fence.blueprints.data.indexd.AzureBlobStorageIndexedFileLocation.get_signed_url",
                            side_effect=IndexError(),
                    ):
                        with pytest.raises(NotFound):
                            indexed_file._get_signed_url(
                                protocol=None,
                                action=supported_action,
                                expires_in=10,
                                force_signed_url=True,
                                r_pays_project=None,
                                file_name="some file",
                            )