File: cpe_name_binder_test.go

package info (click to toggle)
golang-github-knqyf263-go-cpe 0.0~git20180327.659663f6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, experimental, forky, sid, trixie
  • size: 18,036 kB
  • sloc: sh: 11; makefile: 4
file content (127 lines) | stat: -rw-r--r-- 2,882 bytes parent folder | download | duplicates (2)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package naming

import (
	"testing"

	"github.com/knqyf263/go-cpe/common"
)

var (
	any, _ = common.NewLogicalValue("ANY")
	na, _  = common.NewLogicalValue("NA")
)

func TestBindToURI(t *testing.T) {
	vectors := []struct {
		w        common.WellFormedName
		expected string
	}{{
		w: common.WellFormedName{
			"part": "a",
		},
		expected: "cpe:/a",
	}, {
		w: common.WellFormedName{
			"part":     "a",
			"vendor":   "microsoft",
			"product":  "internet_explorer",
			"version":  "8\\.0\\.6001",
			"update":   "beta",
			"edition":  any,
			"language": "sp2",
		},
		expected: "cpe:/a:microsoft:internet_explorer:8.0.6001:beta::sp2",
	}, {
		w: common.WellFormedName{
			"part":       "a",
			"vendor":     "foo\\$bar",
			"product":    "insight",
			"version":    "7\\.4\\.0\\.1570",
			"update":     na,
			"sw_edition": "online",
			"target_sw":  "win2003",
			"target_hw":  "x64",
		},
		expected: "cpe:/a:foo%24bar:insight:7.4.0.1570:-:~~online~win2003~x64~",
	}, {
		w: common.WellFormedName{
			"part":   "a",
			"vendor": 1,
		},
		expected: "cpe:/a",
	}, {
		w: common.WellFormedName{
			"part":     "a",
			"vendor":   "micro??",
			"product":  "internet*",
			"version":  `\!\"\#\$\%\&\'\(\)\*\+\,`,
			"update":   `beta\-\.`,
			"language": `online\/\:\;\<\=\>\?\@\[\\\]\^`,
		},
		expected: "cpe:/a:micro%01%01:internet%02:%21%22%23%24%25%26%27%28%29%2a%2b%2c:beta-.::online%2f%3a%3b%3c%3d%3e%3f%40%5b%5c%5d%5e",
	}, {
		w: common.WellFormedName{
			"part":    "a",
			"vendor":  "\\`",
			"product": `\{\|\}\~\a`,
		},
		expected: "cpe:/a:%60:%7b%7c%7d%7ea",
	},
	}

	for i, v := range vectors {
		actual := BindToURI(v.w)
		if actual != v.expected {
			t.Errorf("test %d, Result: got %v, want %v", i, actual, v.expected)
		}
	}
}

func TestBindToFS(t *testing.T) {
	vectors := []struct {
		w        common.WellFormedName
		expected string
	}{{
		w: common.WellFormedName{
			"part": "a",
		},
		expected: "cpe:2.3:a:*:*:*:*:*:*:*:*:*:*",
	}, {
		w: common.WellFormedName{
			"part":     "a",
			"vendor":   "microsoft",
			"product":  "internet_explorer",
			"version":  "8\\.0\\.6001",
			"update":   "beta",
			"edition":  any,
			"language": "sp2",
		},
		expected: "cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:sp2:*:*:*:*",
	}, {
		w: common.WellFormedName{
			"part":       "a",
			"vendor":     "foo\\$bar",
			"product":    "insight",
			"version":    "7\\.4\\.0\\.1570",
			"update":     na,
			"sw_edition": "online",
			"target_sw":  "win2003",
			"target_hw":  "x64",
		},
		expected: "cpe:2.3:a:foo\\$bar:insight:7.4.0.1570:-:*:*:online:win2003:x64:*",
	}, {
		w: common.WellFormedName{
			"part":   "a",
			"vendor": 1,
		},
		expected: "cpe:2.3:a::*:*:*:*:*:*:*:*:*",
	},
	}

	for i, v := range vectors {
		actual := BindToFS(v.w)
		if actual != v.expected {
			t.Errorf("test %d, Result: got %v, want %v", i, actual, v.expected)
		}
	}
}