code: def test_HTTPBearerTokenAuthenticator(d=None):
      fpath = opj(d, "crap.txt")
  
      def request_get_callback(request, uri, headers):
          # We can't assert inside the callback, or running the
          # test give "Connection aborted" errors instead of telling
          # us that the assertion failed. So instead, we make
          # the request object available outside of the callback
          # and do the assertions in the main test, not the callback
          request_get_callback.req = request
          return (200, headers, "correct body")
  
      httpretty.register_uri(
          httpretty.GET, url, body=request_get_callback
      )
  
      credential = FakeCredential3(name="test", url=None)
      authenticator = HTTPBearerTokenAuthenticator()
      downloader = HTTPDownloader(
          credential=credential, authenticator=authenticator
      )
      downloader.download(url, path=d)
  
      # Perform assertions. See note above.
      r = request_get_callback.req
      assert_equal(r.body, b"")
      assert_in("Authorization", r.headers)
      assert_equal(r.headers["Authorization"], "Bearer testtoken")
  
      content = read_file(fpath)
      assert_equal(content, "correct body")
  
imports: import builtins
  import os
  import re
  import time
  from calendar import timegm
  from os.path import join
  from datalad.downloaders.tests.utils import get_test_providers
  from datalad.support.network import download_url, get_url_straight_filename
  from datalad.utils import ensure_unicode
  from ...support.exceptions import AccessFailedError
  from ..base import BaseDownloader, DownloadError, IncompleteDownloadError, NoneAuthenticator
  from ..credentials import LORIS_Token, Token, UserPassword
  from ..http import HTMLFormAuthenticator, HTTPBaseAuthenticator, HTTPBearerTokenAuthenticator, HTTPDownloader, process_www_authenticate
  from unittest.mock import patch
  from ...support.exceptions import AccessDeniedError, AnonymousAccessDeniedError
  from ...support.network import get_url_disposition_filename
  from ...support.status import FileStatus
  from ...tests.utils_pytest import SkipTest, assert_equal, assert_false, assert_greater, assert_in, assert_not_in, assert_raises, known_failure_githubci_win, ok_file_has_content, serve_path_via_http, skip_if, skip_if_no_network, swallow_logs, swallow_outputs, use_cassette, with_fake_cookies_db, with_memory_keyring, with_tempfile, with_testsui, with_tree, without_http_proxy
  from ...utils import read_file
label_desc: Use image node_id 22 for calling a global function with example usage: test_HTTPBearerTokenAuthenticator(d) and returns: int,  headers,  str