From 1bf23d1c2dd6e85c677392a83a67a581c218cc11 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 18 Aug 2024 00:17:00 +0300 Subject: file auth backend: properly handle non-standard relative file:// urls I use these in development. --- src/indieauth/backend/fs.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/indieauth/backend/fs.rs b/src/indieauth/backend/fs.rs index 5e97ae5..ce519da 100644 --- a/src/indieauth/backend/fs.rs +++ b/src/indieauth/backend/fs.rs @@ -123,6 +123,7 @@ impl FileBackend { } #[inline] + #[tracing::instrument] fn url_to_dir(url: &url::Url) -> String { let host = url.host_str().unwrap(); let port = url.port() @@ -188,6 +189,14 @@ impl FileBackend { #[async_trait] impl AuthBackend for FileBackend { async fn new(path: &'_ url::Url) -> Result { + let orig_path = path; + let mut path = orig_path.clone(); + if path.host_str() == Some(".") { + let base = url::Url::from_directory_path(std::env::current_dir()?).unwrap(); + + path = base.join(&format!(".{}", path.path())).unwrap(); + } + tracing::debug!("Initializing File auth backend: {} -> {}", orig_path, path.path()); Ok(Self { path: std::path::PathBuf::from(path.path()) }) @@ -396,12 +405,14 @@ impl AuthBackend for FileBackend { todo!() } + #[tracing::instrument(skip(self))] async fn list_user_credential_types(&self, website: &url::Url) -> Result> { let mut creds = vec![]; - - match tokio::fs::metadata(self.path - .join(FileBackend::url_to_dir(website)) - .join("password")) + let password_file = self.path + .join(FileBackend::url_to_dir(website)) + .join("password"); + tracing::debug!("Password file for {}: {}", website, password_file.display()); + match tokio::fs::metadata(password_file) .await { Ok(_) => creds.push(EnrolledCredential::Password), -- cgit 1.4.1