about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-18 00:17:00 +0300
committerVika <vika@fireburn.ru>2024-08-18 00:27:53 +0300
commit1bf23d1c2dd6e85c677392a83a67a581c218cc11 (patch)
tree62884626b8df54e0e150ef2eb563222cf5854f02 /src
parent193d1cd7ba3b8b4226d76045bf5b66ed8daa9524 (diff)
downloadkittybox-1bf23d1c2dd6e85c677392a83a67a581c218cc11.tar.zst
file auth backend: properly handle non-standard relative file:// urls
I use these in development.
Diffstat (limited to 'src')
-rw-r--r--src/indieauth/backend/fs.rs19
1 files changed, 15 insertions, 4 deletions
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<Self> {
+        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<Vec<EnrolledCredential>> {
         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),