|
1 | 1 | (ns eca.features.tools.filesystem-test |
2 | 2 | (:require |
3 | 3 | [babashka.fs :as fs] |
4 | | - [clojure.string :as string] |
5 | 4 | [clojure.test :refer [deftest is testing]] |
6 | 5 | [eca.features.tools.filesystem :as f.tools.filesystem] |
7 | 6 | [eca.test-helper :as h] |
|
18 | 17 | {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "baz"}]})))) |
19 | 18 |
|
20 | 19 | (deftest list-directory-test |
21 | | - (testing "unallowed dir" |
| 20 | + (testing "Invalid path" |
22 | 21 | (is (match? |
23 | 22 | {:contents [{:type :text |
24 | 23 | :error false |
25 | | - :content "Access denied - path outside workspace root, call list_allowed_dirs first"}]} |
26 | | - (with-redefs [fs/canonicalize (constantly (h/file-path "/foo/qux"))] |
| 24 | + :content "/foo/qux is not a valid path"}]} |
| 25 | + (with-redefs [fs/canonicalize (constantly (h/file-path "/foo/qux")) |
| 26 | + fs/regular-file? (constantly false)] |
| 27 | + ((get-in f.tools.filesystem/definitions ["list_directory" :handler]) |
| 28 | + {"path" (h/file-path "/foo/qux")} |
| 29 | + {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "baz"}]}))))) |
| 30 | + (testing "Unallowed dir" |
| 31 | + (is (match? |
| 32 | + {:contents [{:type :text |
| 33 | + :error false |
| 34 | + :content "Access denied - path /foo/qux outside allowed directories"}]} |
| 35 | + (with-redefs [fs/canonicalize (constantly (h/file-path "/foo/qux")) |
| 36 | + fs/regular-file? (constantly true)] |
27 | 37 | ((get-in f.tools.filesystem/definitions ["list_directory" :handler]) |
28 | 38 | {"path" (h/file-path "/foo/qux")} |
29 | 39 | {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "baz"}]}))))) |
|
35 | 45 | "[DIR] %s\n") |
36 | 46 | (h/file-path "/foo/bar/baz/some.clj") |
37 | 47 | (h/file-path "/foo/bar/baz/qux"))}]} |
38 | | - (with-redefs [fs/starts-with? (constantly true) |
| 48 | + (with-redefs [fs/regular-file? (constantly true) |
| 49 | + fs/starts-with? (constantly true) |
39 | 50 | fs/list-dir (constantly [(fs/path (h/file-path "/foo/bar/baz/some.clj")) |
40 | 51 | (fs/path (h/file-path "/foo/bar/baz/qux"))]) |
41 | 52 | fs/directory? (fn [path] (not (string/ends-with? (str path) ".clj"))) |
|
0 commit comments