Skip to content

Commit

Permalink
Fix retrieval of credentials for URLs from cache (#6452)
Browse files Browse the repository at this point in the history
While working on #6389 I discovered
we never checked `cache.get_url` here, which is wrong — though I don't
think it had much effect in practice since the realm would typically
match first. The main problem is that when we call `get_url` later we
hard-code the username to `None` because we assume we checked up here
with the username if present.
  • Loading branch information
zanieb committed Aug 23, 2024
1 parent a535d3b commit 34dd840
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/uv-auth/src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Credentials {
password: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash, Default)]
pub(crate) struct Username(Option<String>);

impl Username {
Expand Down
7 changes: 7 additions & 0 deletions crates/uv-auth/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ impl Middleware for AuthMiddleware {
request = credentials.authenticate(request);
// Do not insert already-cached credentials
None
} else if let Some(credentials) = self
.cache()
.get_url(request.url(), &credentials.to_username())
{
request = credentials.authenticate(request);
// Do not insert already-cached credentials
None
} else if let Some(credentials) = self
.fetch_credentials(Some(&credentials), request.url())
.await
Expand Down

0 comments on commit 34dd840

Please sign in to comment.