code: def test_access_denied(toppath=None, topurl=None, keyring=None):
      furl = topurl + "file.dat"
  
      def deny_access(*args, **kwargs):
          raise AccessDeniedError(supported_types=["http_basic_auth"])
  
      def deny_anon_access(*args, **kwargs):
          raise AnonymousAccessDeniedError(
              supported_types=["http_basic_auth"]
          )
  
      downloader = HTTPDownloader()
  
      # Test different paths that should lead to a DownloadError.
  
      for denier in deny_access, deny_anon_access:
  
          @with_testsui(responses=["no"])
          def run_refuse_provider_setup():
              with patch.object(downloader, "_download", denier):
                  downloader.download(furl)
  
          assert_raises(DownloadError, run_refuse_provider_setup)
  
      downloader_creds = HTTPDownloader(credential="irrelevant")
  
      @with_testsui(responses=["no"])
      def run_refuse_creds_update():
          with patch.object(downloader_creds, "_download", deny_access):
              downloader_creds.download(furl)
  
      assert_raises(DownloadError, run_refuse_creds_update)
  
      downloader_noauth = HTTPDownloader(
          authenticator=NoneAuthenticator()
      )
  
      def run_noauth():
          with patch.object(
              downloader_noauth, "_download", deny_access
          ):
              downloader_noauth.download(furl)
  
      assert_raises(DownloadError, run_noauth)
  
      # Complete setup for a new provider.
  
      @with_testsui(
          responses=[
              "yes",  # Set up provider?
              # Enter provider details, but then don't save ...
              "newprovider",
              re.escape(furl),
              "http_auth",
              "user_password",
              "no",
              # No provider, try again?
              "yes",
              # Enter same provider detains but save this time.
              "newprovider",
              re.escape(furl),
              "http_auth",
              "user_password",
              "yes",
              # Enter credentials.
              "me",
              "mypass",
          ]
      )
      def run_set_up_provider():
          with patch.object(downloader, "_download", deny_access):
              downloader.download(furl)
  
      # We've forced an AccessDenied error and then set up bogus credentials,
      # leading to a 501 (not implemented) error.
      assert_raises(AccessFailedError, run_set_up_provider)
  
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 6 for calling a global function with example usage: test_access_denied(toppath, topurl, keyring) without return types