MCPcopy Index your code
hub / github.com/cheat/cheat / TestValidate

Function TestValidate

internal/sheet/validate_test.go:9–113  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestValidate(t *testing.T) {
10 tests := []struct {
11 name string
12 input string
13 wantErr bool
14 errMsg string
15 }{
16 // Valid names
17 {
18 name: "simple name",
19 input: "docker",
20 wantErr: false,
21 },
22 {
23 name: "name with slash",
24 input: "docker/compose",
25 wantErr: false,
26 },
27 {
28 name: "name with multiple slashes",
29 input: "lang/go/slice",
30 wantErr: false,
31 },
32 {
33 name: "name with dash and underscore",
34 input: "my-cheat_sheet",
35 wantErr: false,
36 },
37 // Invalid names
38 {
39 name: "empty name",
40 input: "",
41 wantErr: true,
42 errMsg: "empty",
43 },
44 {
45 name: "parent directory traversal",
46 input: "../etc/passwd",
47 wantErr: true,
48 errMsg: "'..'",
49 },
50 {
51 name: "complex traversal",
52 input: "foo/../../etc/passwd",
53 wantErr: true,
54 errMsg: "'..'",
55 },
56 {
57 name: "absolute path unix",
58 input: "/etc/passwd",
59 wantErr: runtime.GOOS != "windows", // /etc/passwd is not absolute on Windows
60 errMsg: "absolute",
61 },
62 {
63 name: "absolute path windows",
64 input: `C:\evil`,
65 wantErr: runtime.GOOS == "windows", // C:\evil is not absolute on Unix
66 errMsg: "absolute",

Callers

nothing calls this directly

Calls 1

ValidateFunction · 0.85

Tested by

no test coverage detected