Commit 8e25954c authored by Nick Mathewson's avatar Nick Mathewson 🦞
Browse files

fs-mistrust: clarify and test behavior for ".." past the fs root.

parent c9e17c5a
Loading
Loading
Loading
Loading
+31 −1
Original line number Original line Diff line number Diff line
@@ -230,7 +230,8 @@ impl Iterator for ResolvePath {
                // Do nothing.
                // Do nothing.
            } else if next_part == ".." {
            } else if next_part == ".." {
                // We can safely remove the last part of our path: We know it is
                // We can safely remove the last part of our path: We know it is
                // canonical, so ".." will not give surprising results.
                // canonical, so ".." will not give surprising results.  (If we
                // are already at the root, "PathBuf::pop" will do nothing.)
                self.resolved.pop();
                self.resolved.pop();
            } else {
            } else {
                // We extend our path.  This may _temporarily_ make `resolved`
                // We extend our path.  This may _temporarily_ make `resolved`
@@ -598,4 +599,33 @@ mod test {


        assert!(r.next().is_none());
        assert!(r.next().is_none());
    }
    }

    #[test]
    fn past_root() {
        let d = testing::Dir::new();
        let root = d.canonical_root();
        d.dir("a/b");
        d.chmod("a", 0o700);
        d.chmod("a/b", 0o700);

        let root_as_relative: PathBuf = root
            .components()
            .filter(|c| matches!(c, std::path::Component::Normal(_)))
            .collect();
        let n = root.components().count();
        // Start with our the "root" directory of our Dir...
        let mut inspect_path = root.to_path_buf();
        // Then go way past the root of the filesystem
        for _ in 0..n * 2 {
            inspect_path.push("..");
        }
        // Then back down to the "root" directory of the dir..
        inspect_path.push(root_as_relative);
        // Then to a/b.
        inspect_path.push("a/b");

        let r = ResolvePath::new(inspect_path.clone()).unwrap();
        let final_path = r.last().unwrap().unwrap().0;
        assert_eq!(final_path, inspect_path.canonicalize().unwrap());
    }
}
}