File: debian_test.go

package info (click to toggle)
goval-dictionary 0.2.0-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 424 kB
  • sloc: makefile: 2
file content (135 lines) | stat: -rw-r--r-- 4,603 bytes parent folder | download | duplicates (3)
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
128
129
130
131
132
133
134
135
package models

import (
	"encoding/xml"
	"reflect"
	"testing"

	"github.com/k0kubun/pp"
	"github.com/ymomoi/goval-parser/oval"
)

func TestWalkDebian(t *testing.T) {
	var tests = []struct {
		oval     string
		expected []distroPackage
	}{
		{
			oval: `
<?xml version="1.0" ?>
<oval_definitions>
	<generator>
		<oval:product_name>Debian</oval:product_name>
		<oval:schema_version>5.3</oval:schema_version>
		<oval:timestamp>2017-04-07T03:47:55.188-04:00</oval:timestamp>
	</generator>
	<definitions>
		<definition class="vulnerability" id="oval:org.debian:def:20140001" version="1">
			<metadata>
				<title>CVE-2014-0001</title>
				<affected family="unix">
					<platform>Debian GNU/Linux 7.0</platform>
					<platform>Debian GNU/Linux 8.2</platform>
					<platform>Debian GNU/Linux 9.0</platform>
					<product>mysql-5.5</product>
				</affected>
				<reference ref_id="CVE-2014-0001" ref_url="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-0001" source="CVE"/>
				<description>Buffer overflow in client/mysql.cc in Oracle MySQL and MariaDB before 5.5.35 allows remote database servers to cause a denial of service (crash) and possibly execute arbitrary code via a long server version string.</description>
				<debian>
					<date>2014-05-03</date>
					<moreinfo>
DSA-2919
Several issues have been discovered in the MySQL database server. The
vulnerabilities are addressed by upgrading MySQL to the new upstream
version 5.5.37. Please see the MySQL 5.5 Release Notes and Oracle's
Critical Patch Update advisory for further details:
</moreinfo>
				</debian>
			</metadata>
			<criteria comment="Platform section" operator="OR">
				<criteria comment="Release section" operator="AND">
					<criterion comment="Debian 7.0 is installed" test_ref="oval:org.debian.oval:tst:1"/>
					<criteria comment="Architecture section" operator="OR">
						<criteria comment="Architecture independent section" operator="AND">
							<criterion comment="all architecture" test_ref="oval:org.debian.oval:tst:2"/>
							<criterion comment="mysql-5.5 DPKG is earlier than 5.5.37-0+wheezy1" test_ref="oval:org.debian.oval:tst:3"/>
						</criteria>
					</criteria>
				</criteria>
				<criteria comment="Release section" operator="AND">
					<criterion comment="Debian 8.2 is installed" test_ref="oval:org.debian.oval:tst:4"/>
					<criteria comment="Architecture section" operator="OR">
						<criteria comment="Architecture independent section" operator="AND">
							<criterion comment="all architecture" test_ref="oval:org.debian.oval:tst:2"/>
							<criterion comment="mysql-5.5 DPKG is earlier than 5.5.37-1" test_ref="oval:org.debian.oval:tst:5"/>
						</criteria>
					</criteria>
				</criteria>
				<criteria comment="Release section" operator="AND">
					<criterion comment="Debian 9.0 is installed" test_ref="oval:org.debian.oval:tst:6"/>
					<criteria comment="Architecture section" operator="OR">
						<criteria comment="Architecture independent section" operator="AND">
							<criterion comment="all architecture" test_ref="oval:org.debian.oval:tst:2"/>
							<criterion comment="mysql-5.5 DPKG is earlier than 5.5.37-1" test_ref="oval:org.debian.oval:tst:7"/>
						</criteria>
					</criteria>
					<criteria comment="Architecture section" operator="OR">
						<criteria comment="Architecture independent section" operator="AND">
							<criterion comment="all architecture" test_ref="oval:org.debian.oval:tst:2"/>
							<criterion comment="mysql-5.6 DPKG is earlier than 5.6.37-1" test_ref="oval:org.debian.oval:tst:7"/>
						</criteria>
					</criteria>
				</criteria>
			</criteria>
		</definition>
	</definitions>
</oval_definitions>
			`,
			expected: []distroPackage{
				{
					osVer: "7.0",
					pack: Package{
						Name:    "mysql-5.5",
						Version: "5.5.37-0+wheezy1",
					},
				},
				{
					osVer: "8.2",
					pack: Package{
						Name:    "mysql-5.5",
						Version: "5.5.37-1",
					},
				},
				{
					osVer: "9.0",
					pack: Package{
						Name:    "mysql-5.5",
						Version: "5.5.37-1",
					},
				},
				{
					osVer: "9.0",
					pack: Package{
						Name:    "mysql-5.6",
						Version: "5.6.37-1",
					},
				},
			},
		},
	}

	for i, tt := range tests {
		var root *oval.Root
		if err := xml.Unmarshal([]byte(tt.oval), &root); err != nil {
			t.Errorf("[%d] marshall error", i)
		}
		c := root.Definitions.Definitions[0].Criteria
		actual := collectDebianPacks(c)

		if !reflect.DeepEqual(tt.expected, actual) {
			e := pp.Sprintf("%v", tt.expected)
			a := pp.Sprintf("%v", actual)
			t.Errorf("[%d]: expected: %s\n, actual: %s\n", i, e, a)
		}
	}
}