def test_request_url(): authority = "localhost" tenant = "expected_tenant" def validate_url(url): scheme, netloc, path, _, _, _ = urlparse(url) assert scheme == "https" assert netloc == authority assert path.startswith("/" + tenant) def mock_send(request, **kwargs): validate_url(request.url) return mock_response(json_payload={ "token_type": "Bearer", "expires_in": 42, "access_token": "***" }) client = AuthnClient(tenant=tenant, transport=Mock(send=mock_send), authority=authority) client.request_token(("scope", )) request = client.get_refresh_token_grant_request({"secret": "***"}, "scope") validate_url(request.url) # authority can be configured via environment variable with patch.dict("os.environ", {EnvironmentVariables.AZURE_AUTHORITY_HOST: authority}, clear=True): client = AuthnClient(tenant=tenant, transport=Mock(send=mock_send)) client.request_token(("scope", )) request = client.get_refresh_token_grant_request({"secret": "***"}, "scope") validate_url(request.url)
def test_request_url(): authority = "authority.com" tenant = "expected_tenant" def validate_url(url): scheme, netloc, path, _, _, _ = urlparse(url) assert scheme == "https" assert netloc == authority assert path.startswith("/" + tenant) def mock_send(request, **kwargs): validate_url(request.url) return mock_response(json_payload={ "token_type": "Bearer", "expires_in": 42, "access_token": "***" }) client = AuthnClient(tenant=tenant, transport=Mock(send=mock_send), authority=authority) client.request_token(("scope", )) request = client.get_refresh_token_grant_request({"secret": "***"}, "scope") validate_url(request.url)