auth = BasicAuth(username=username, password=password)
return auth(request)
- if trust_env:
+ if trust_env and "Authorization" not in request.headers:
credentials = self.netrc.get_credentials(request.url.authority)
if credentials is not None:
auth = BasicAuth(username=credentials[0], password=credentials[1])
}
+@pytest.mark.asyncio
+async def test_auth_header_has_priority_over_netrc():
+ os.environ["NETRC"] = "tests/.netrc"
+ url = "http://netrcexample.org"
+
+ client = Client(dispatch=MockDispatch())
+ response = await client.get(url, headers={"Authorization": "Override"})
+
+ assert response.status_code == 200
+ assert response.json() == {"auth": "Override"}
+
+
@pytest.mark.asyncio
async def test_trust_env_auth():
os.environ["NETRC"] = "tests/.netrc"