Replaced all filepath.Join() with core.Path() across fs_test.go, fs_example_test.go, core_test.go, path_test.go. core.Path() IS the path traversal security boundary. Agents using filepath.Join bypass it. Tests now demonstrate the Core way. "path/filepath" import is now zero across all test files. Co-Authored-By: Virgil <virgil@lethean.io>
43 lines
838 B
Go
43 lines
838 B
Go
package core_test
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
. "dappco.re/go/core"
|
|
)
|
|
|
|
func ExampleFs_WriteAtomic() {
|
|
dir, _ := os.MkdirTemp("", "example")
|
|
defer os.RemoveAll(dir)
|
|
|
|
f := (&Fs{}).New("/")
|
|
path := Path(dir, "status.json")
|
|
f.WriteAtomic(path, `{"status":"completed"}`)
|
|
|
|
r := f.Read(path)
|
|
fmt.Println(r.Value)
|
|
// Output: {"status":"completed"}
|
|
}
|
|
|
|
func ExampleFs_NewUnrestricted() {
|
|
dir, _ := os.MkdirTemp("", "example")
|
|
defer os.RemoveAll(dir)
|
|
|
|
// Write outside sandbox
|
|
outside := Path(dir, "outside.txt")
|
|
os.WriteFile(outside, []byte("hello"), 0644)
|
|
|
|
sandbox := (&Fs{}).New(Path(dir, "sandbox"))
|
|
unrestricted := sandbox.NewUnrestricted()
|
|
|
|
r := unrestricted.Read(outside)
|
|
fmt.Println(r.Value)
|
|
// Output: hello
|
|
}
|
|
|
|
func ExampleFs_Root() {
|
|
f := (&Fs{}).New("/srv/workspaces")
|
|
fmt.Println(f.Root())
|
|
// Output: /srv/workspaces
|
|
}
|