-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateClientHintWindowsPlatformVersion_test.go
More file actions
94 lines (90 loc) · 2.22 KB
/
Copy pathvalidateClientHintWindowsPlatformVersion_test.go
File metadata and controls
94 lines (90 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package CaddyHeaderVerification
import (
"testing"
)
func TestValidateClientHintWindowsPlatformVersion(t *testing.T) {
tests := []struct {
name string
platform string
platformVersion string
want bool
}{
{
name: "Windows with correct version 19.0.0",
platform: `"\"Windows\""`,
platformVersion: `"19.0.0"`,
want: true,
},
{
name: "Windows with incorrect version 18.0.0",
platform: `"\"Windows\""`,
platformVersion: `"18.0.0"`,
want: false,
},
{
name: "Windows with missing version header",
platform: `"\"Windows\""`,
platformVersion: "",
want: false,
},
{
name: "Windows with empty version value",
platform: `"\"Windows\""`,
platformVersion: "",
want: false,
},
{
name: "Windows without quotes but correct version",
platform: "Windows",
platformVersion: "19.0.0",
want: false,
},
{
name: "Non-Windows platform (macOS) with any version → allowed",
platform: `"macOS"`,
platformVersion: `"14.0.0"`,
want: true,
},
{
name: "Non-Windows platform (Android) without version → allowed",
platform: `"Android"`,
platformVersion: "",
want: true,
},
{
name: "No platform at all → treated as non-Windows",
platform: "",
platformVersion: "",
want: false,
},
{
name: "Windows with extra spaces and quotes, correct version",
platform: ` "Windows" `,
platformVersion: ` "19.0.0" `,
want: false,
},
{
name: "Windows with extra spaces, wrong version",
platform: ` "Windows" `,
platformVersion: ` "20.0.0" `,
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ValidateClientHintWindowsPlatformVersion(
tt.platform,
tt.platformVersion,
)
if got != tt.want {
t.Errorf(
"ValidateClientHintWindowsPlatformVersion(%q, %q) = %v, want %v",
tt.platform,
tt.platformVersion,
got,
tt.want,
)
}
})
}
}