def test_normalize_authority():
    """normalize_authority should return a URI with a scheme and no trailing spaces or forward slashes"""

    localhost = "localhost"
    localhost_tls = "https://" + localhost

    # accept https if specified, default to it when no scheme specified
    for uri in (localhost, localhost_tls):
        assert normalize_authority(uri) == localhost_tls

        # remove trailing characters
        for string in ("/", " ", "/ ", " /"):
            assert normalize_authority(uri + string) == localhost_tls

    # raise for other schemes
    for scheme in ("http", "file"):
        with pytest.raises(ValueError):
            normalize_authority(scheme + "://localhost")
Ejemplo n.º 2
0
    def __init__(self, **kwargs):
        # type: (**Any) -> None
        self._successfull_tenant_id = None

        self.authority = kwargs.pop("authority", None)
        self.authority = normalize_authority(
            self.authority) if self.authority else get_default_authority()

        self.interactive_browser_tenant_id = kwargs.pop(
            "interactive_browser_tenant_id",
            os.environ.get(EnvironmentVariables.AZURE_TENANT_ID))

        self.subscription_id = kwargs.pop("subscription_id",
                                          os.environ.get("SUBSCRIPTION_ID"))
        self.arm_base_url = kwargs.pop("arm_base_url",
                                       "https://management.azure.com/")

        self.managed_identity_client_id = kwargs.pop(
            "managed_identity_client_id",
            os.environ.get(EnvironmentVariables.AZURE_CLIENT_ID))

        self.shared_cache_username = kwargs.pop(
            "shared_cache_username",
            os.environ.get(EnvironmentVariables.AZURE_USERNAME))
        self.shared_cache_tenant_id = kwargs.pop(
            "shared_cache_tenant_id",
            os.environ.get(EnvironmentVariables.AZURE_TENANT_ID))

        self.vscode_tenant_id = kwargs.pop(
            "visual_studio_code_tenant_id",
            os.environ.get(EnvironmentVariables.AZURE_TENANT_ID))

        self.exclude_token_file_credential = kwargs.pop(
            "exclude_token_file_credential", False)
        self.exclude_environment_credential = kwargs.pop(
            "exclude_environment_credential", False)
        self.exclude_managed_identity_credential = kwargs.pop(
            "exclude_managed_identity_credential", False)
        self.exclude_shared_token_cache_credential = kwargs.pop(
            "exclude_shared_token_cache_credential", False)
        self.exclude_visual_studio_code_credential = kwargs.pop(
            "exclude_visual_studio_code_credential", False)
        self.exclude_cli_credential = kwargs.pop("exclude_cli_credential",
                                                 False)
        self.exclude_interactive_browser_credential = kwargs.pop(
            "exclude_interactive_browser_credential", True)
        self.exclude_device_code_credential = kwargs.pop(
            "exclude_device_code_credential", False)
        self.exclude_powershell_credential = kwargs.pop(
            "exclude_powershell_credential", False)

        # credentials will be created lazy on the first call to get_token
        super(_DefaultAzureCredential, self).__init__()