Skip to content

Commit

Permalink
Fix retrieval of credentials for URLs from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Aug 22, 2024
1 parent fa34466 commit 6beba98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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
9 changes: 8 additions & 1 deletion crates/uv-auth/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use http::{Extensions, StatusCode};
use url::Url;

use crate::{
credentials::{Credentials, Username},
credentials::{self, Credentials, Username},
realm::Realm,
CredentialsCache, KeyringProvider, CREDENTIALS_CACHE,
};
Expand Down 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 6beba98

Please sign in to comment.