Language: Python
Label: safe
CWE: CWE-918 \u2014 Server-Side Request Forgery (SSRF)
The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.

Code:
def test_log_artifact_aws_with_headers(
    databricks_artifact_repo, test_file, artifact_path, expected_location
):
    expected_headers = {header.name: header.value for header in MOCK_HEADERS}
    mock_response = Response()
    mock_response.status_code = 200
    mock_response.close = lambda: None
    mock_credential_info = ArtifactCredentialInfo(
        signed_uri=MOCK_AWS_SIGNED_URI,
        type=ArtifactCredentialType.AWS_PRESIGNED_URL,
        headers=MOCK_HEADERS,
    )
    with mock.patch(
        f"{DATABRICKS_ARTIFACT_REPOSITORY}._get_credential_infos",
        return_value=[mock_credential_info],
    ) as get_credential_infos_mock, mock.patch(
        "requests.Session.request", return_value=mock_response
    ) as request_mock:
        databricks_artifact_repo.log_artifact(test_file, artifact_path)
        get_credential_infos_mock.assert_called_with(
            GetCredentialsForWrite, MOCK_RUN_ID, [expected_location]
        )
        request_mock.assert_called_with(
            "put",
            MOCK_AWS_SIGNED_URI,
            allow_redirects=True,
            data=ANY,
            headers=expected_headers,
            timeout=None,
        )