34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package paths
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidate(t *testing.T) {
|
|
for _, good := range []string{".claude/skills/a/SKILL.md", "opencode.json", ".opencode/agents/x.md", ".github/x", "a/.gitkeep"} {
|
|
if err := Validate(good); err != nil {
|
|
t.Errorf("%s: %v", good, err)
|
|
}
|
|
}
|
|
for _, bad := range []string{"", "/etc/passwd", "../x", "a/../b", "a//b", "./a", `a\b`, "c:/x", "a/b.",
|
|
"a /b", "a/b ", "...", "a/<b>", "a|b", "a?b", "a\x01b", ".git/hooks/pre-commit", ".GIT/config", ".git"} {
|
|
if err := Validate(bad); err == nil {
|
|
t.Errorf("%q sollte abgelehnt werden", bad)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestInRepoWithoutSymlinks(t *testing.T) {
|
|
repo, outside := t.TempDir(), t.TempDir()
|
|
if err := os.Symlink(outside, filepath.Join(repo, ".claude")); err != nil {
|
|
t.Skip(err)
|
|
}
|
|
if _, err := InRepo(repo, ".claude/skills/a/SKILL.md"); err == nil {
|
|
t.Error("Symlink im Pfad muss abgelehnt werden")
|
|
}
|
|
if p, err := InRepo(repo, ".opencode/agents/a.md"); err != nil || p != filepath.Join(repo, ".opencode", "agents", "a.md") {
|
|
t.Errorf("%s, %v", p, err)
|
|
}
|
|
}
|