| 1 | package session |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestProjectionPathsRejectInvalidSessionIdentity(t *testing.T) { |
| 10 | root := filepath.Join(t.TempDir(), "session storage #% 会话") |
| 11 | for name, pathFor := range map[string]func(string, string) string{ |
| 12 | "history": historyIndexPath, "search": searchIndexPath, |
| 13 | } { |
| 14 | t.Run(name, func(t *testing.T) { |
| 15 | for _, id := range []string{"", ".", "..", "../other", "nested/id", `nested\id`, "/outside", `C:\outside`, "CON", ".hidden", "id.", "bad\x00id", strings.Repeat("x", 256)} { |
| 16 | if path := pathFor(root, id); path != "" { |
| 17 | t.Errorf("invalid session identity %q acquired projection path %q", id, path) |
| 18 | } |
| 19 | } |
| 20 | for _, id := range []string{"session-123", "turn.1", "会话", "space in id"} { |
| 21 | path := pathFor(root, id) |
| 22 | wantDir := filepath.Join(root, ".query-cache", id) |
| 23 | if path == "" || filepath.Dir(path) != wantDir { |
| 24 | t.Errorf("valid session identity %q: path=%q want directory=%q", id, path, wantDir) |
| 25 | } |
| 26 | } |
| 27 | }) |
| 28 | } |
| 29 | } |
| 30 |