annotate tests/testCPE.py @ 40:1d9b2b06067e

Add a CPE parser (and tests)
author Benoît Allard <benoit.allard@greenbone.net>
date Mon, 29 Dec 2014 14:30:39 +0100
parents
children bb1dd2a55643
rev   line source
40
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
1 import unittest
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
2
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
3 from farolluz.parsers.cpe import CPE, CPEAttribute
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
4
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
5 class testbindToURI(unittest.TestCase):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
6
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
7 def test_example1(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
8 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute('microsoft'), product=CPEAttribute('internet_explorer'), version=CPEAttribute(r'8\.0\.6001'), update=CPEAttribute('beta'), edition=CPEAttribute(any=True))
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
9
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
10 self.assertEqual(cpe.bind_to_URI(), 'cpe:/a:microsoft:internet_explorer:8.0.6001:beta')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
11
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
12 def test_example2(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
13 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute('microsoft'), product=CPEAttribute('internet_explorer'), version=CPEAttribute(r'8\.*'), update=CPEAttribute('sp?'))
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
14
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
15 self.assertEqual(cpe.bind_to_URI(), 'cpe:/a:microsoft:internet_explorer:8.%02:sp%01')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
16
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
17 def test_example3(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
18 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute('hp'), product=CPEAttribute('insight_diagnostics'), version=CPEAttribute(r'7\.4\.0\.1570'), update=CPEAttribute(na=True), sw_edition=CPEAttribute('online'), target_sw=CPEAttribute('win2003'), target_hw=CPEAttribute("x64"))
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
19
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
20 self.assertEqual(cpe.bind_to_URI(), 'cpe:/a:hp:insight_diagnostics:7.4.0.1570:-:~~online~win2003~x64~')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
21
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
22 def test_example4(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
23 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute('hp'), product=CPEAttribute('openview_network_manager'), version=CPEAttribute(r'7\.51'), target_sw=CPEAttribute('linux'))
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
24
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
25 self.assertEqual(cpe.bind_to_URI(), 'cpe:/a:hp:openview_network_manager:7.51::~~~linux~~')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
26
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
27 def test_example5(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
28 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute(r'foo\\bar'), product=CPEAttribute(r'big\$money_manager_2010'), sw_edition=CPEAttribute('special'), target_sw=CPEAttribute('ipod_touch'), target_hw=CPEAttribute("80gb"))
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
29
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
30 self.assertEqual(cpe.bind_to_URI(), 'cpe:/a:foo%5cbar:big%24money_manager_2010:::~~special~ipod_touch~80gb~')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
31
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
32 class testunbindURI(unittest.TestCase):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
33
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
34 def test_example1(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
35 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
36 cpe.unbind_URI('cpe:/a:microsoft:internet_explorer:8.0.6001:beta')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
37 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
38 self.assertEqual(cpe.vendor.value, 'microsoft')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
39 self.assertEqual(cpe.product.value, 'internet_explorer')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
40 self.assertEqual(cpe.version.value, r'8\.0\.6001')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
41 self.assertEqual(cpe.update.value, 'beta')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
42 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
43 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
44
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
45 def test_example2(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
46 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
47 cpe.unbind_URI('cpe:/a:microsoft:internet_explorer:8.%2a:sp%3f')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
48 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
49 self.assertEqual(cpe.vendor.value, 'microsoft')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
50 self.assertEqual(cpe.product.value, 'internet_explorer')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
51 self.assertEqual(cpe.version.value, r'8\.\*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
52 self.assertEqual(cpe.update.value, 'sp\?')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
53 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
54 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
55
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
56 def test_example3(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
57 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
58 cpe.unbind_URI('cpe:/a:microsoft:internet_explorer:8.%02:sp%01')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
59 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
60 self.assertEqual(cpe.vendor.value, 'microsoft')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
61 self.assertEqual(cpe.product.value, 'internet_explorer')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
62 self.assertEqual(cpe.version.value, r'8\.*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
63 self.assertEqual(cpe.update.value, 'sp?')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
64 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
65 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
66
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
67 def test_example4(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
68 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
69 cpe.unbind_URI('cpe:/a:hp:insight_diagnostics:7.4.0.1570::~~online~win2003~x64~')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
70 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
71 self.assertEqual(cpe.vendor.value, 'hp')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
72 self.assertEqual(cpe.product.value, 'insight_diagnostics')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
73 self.assertEqual(cpe.version.value, '7\.4\.0\.1570')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
74 self.assertTrue(cpe.update.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
75 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
76 self.assertEqual(cpe.sw_edition.value, 'online')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
77 self.assertEqual(cpe.target_sw.value, 'win2003')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
78 self.assertEqual(cpe.target_hw.value, 'x64')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
79 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
80 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
81
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
82 def test_example5(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
83 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
84 cpe.unbind_URI('cpe:/a:hp:openview_network_manager:7.51:-:~~~linux~~')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
85 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
86 self.assertEqual(cpe.vendor.value, 'hp')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
87 self.assertEqual(cpe.product.value, 'openview_network_manager')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
88 self.assertEqual(cpe.version.value, '7\.51')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
89 self.assertTrue(cpe.update.na)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
90 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
91 self.assertTrue(cpe.sw_edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
92 self.assertEqual(cpe.target_sw.value, 'linux')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
93 self.assertTrue(cpe.target_hw.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
94 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
95 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
96
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
97
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
98 def test_example6(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
99 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
100 self.assertRaises(KeyError, cpe.unbind_URI, 'cpe:/a:foo%5cbar:big%24money_2010%07:::~~special~ipod_touch~80gb~')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
101
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
102
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
103 def test_example7(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
104 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
105 cpe.unbind_URI('cpe:/a:foo~bar:big%7emoney_2010')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
106 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
107 self.assertEqual(cpe.vendor.value, 'foo\~bar')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
108 self.assertEqual(cpe.product.value, 'big\~money_2010')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
109 self.assertTrue(cpe.version.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
110 self.assertTrue(cpe.update.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
111 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
112 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
113
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
114 def test_example8(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
115 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
116 self.assertRaises(ValueError, cpe.unbind_URI, 'cpe:/a:foo:bar:12.%02.1234')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
117
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
118 class testbindFS(unittest.TestCase):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
119
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
120 def test_example1(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
121 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute('microsoft'), product=CPEAttribute('internet_explorer'), version=CPEAttribute(r'8\.0\.6001'), update=CPEAttribute('beta'), edition=CPEAttribute(any=True))
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
122
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
123 self.assertEqual(cpe.bind_to_fs(), 'cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
124
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
125 def test_example2(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
126 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute('microsoft'), product=CPEAttribute('internet_explorer'), version=CPEAttribute(r'8\.*'), update=CPEAttribute('sp?'), edition=CPEAttribute(any=True))
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
127
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
128 self.assertEqual(cpe.bind_to_fs(), 'cpe:2.3:a:microsoft:internet_explorer:8.*:sp?:*:*:*:*:*:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
129
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
130 cpe.version = CPEAttribute(r'8\.\*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
131
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
132 self.assertEqual(cpe.bind_to_fs(), 'cpe:2.3:a:microsoft:internet_explorer:8.\*:sp?:*:*:*:*:*:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
133
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
134 def test_example3(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
135 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute('hp'), product=CPEAttribute('insight'), version=CPEAttribute(r'7\.4\.0\.1570'), update=CPEAttribute(na=True), sw_edition=CPEAttribute("online"), target_sw=CPEAttribute("win2003"), target_hw=CPEAttribute("x64"))
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
136
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
137 self.assertEqual(cpe.bind_to_fs(), 'cpe:2.3:a:hp:insight:7.4.0.1570:-:*:*:online:win2003:x64:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
138
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
139 def test_example4(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
140 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute('hp'), product=CPEAttribute('openview_network_manager'), version=CPEAttribute(r'7\.51'), target_sw=CPEAttribute('linux'))
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
141
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
142 self.assertEqual(cpe.bind_to_fs(), 'cpe:2.3:a:hp:openview_network_manager:7.51:*:*:*:*:linux:*:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
143
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
144 def test_example5(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
145 cpe = CPE(part=CPEAttribute('a'), vendor=CPEAttribute(r'foo\\bar'), product=CPEAttribute(r'big\$money_2010'), sw_edition=CPEAttribute('special'), target_sw=CPEAttribute('ipod_touch'), target_hw=CPEAttribute("80gb"))
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
146
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
147 self.assertEqual(cpe.bind_to_fs(), r'cpe:2.3:a:foo\\bar:big\$money_2010:*:*:*:*:special:ipod_touch:80gb:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
148
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
149 class testunbind_fs(unittest.TestCase):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
150
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
151 def test_example1(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
152 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
153 cpe.unbind_fs('cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
154 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
155 self.assertEqual(cpe.vendor.value, 'microsoft')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
156 self.assertEqual(cpe.product.value, 'internet_explorer')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
157 self.assertEqual(cpe.version.value, '8\.0\.6001')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
158 self.assertEqual(cpe.update.value, "beta")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
159 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
160 self.assertTrue(cpe.sw_edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
161 self.assertTrue(cpe.target_sw.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
162 self.assertTrue(cpe.target_hw.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
163 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
164 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
165
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
166 def test_example2(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
167 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
168 cpe.unbind_fs('cpe:2.3:a:microsoft:internet_explorer:8.*:sp?:*:*:*:*:*:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
169 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
170 self.assertEqual(cpe.vendor.value, 'microsoft')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
171 self.assertEqual(cpe.product.value, 'internet_explorer')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
172 self.assertEqual(cpe.version.value, '8\.*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
173 self.assertEqual(cpe.update.value, "sp?")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
174 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
175 self.assertTrue(cpe.sw_edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
176 self.assertTrue(cpe.target_sw.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
177 self.assertTrue(cpe.target_hw.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
178 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
179 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
180
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
181 def test_example3(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
182 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
183 cpe.unbind_fs('cpe:2.3:a:hp:insight_diagnostics:7.4.0.1570:-:*:*:online:win2003:x64:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
184 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
185 self.assertEqual(cpe.vendor.value, 'hp')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
186 self.assertEqual(cpe.product.value, 'insight_diagnostics')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
187 self.assertEqual(cpe.version.value, '7\.4\.0\.1570')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
188 self.assertTrue(cpe.update.na)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
189 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
190 self.assertEqual(cpe.sw_edition.value, "online")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
191 self.assertEqual(cpe.target_sw.value, "win2003")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
192 self.assertEqual(cpe.target_hw.value, "x64")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
193 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
194 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
195
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
196 self.assertRaises(ValueError, cpe.unbind_fs, 'cpe:2.3:a:hp:insight_diagnostics:7.4.*.1570:*:*:*:*:*:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
197
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
198
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
199 def test_example4(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
200 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
201 cpe.unbind_fs(r'cpe:2.3:a:foo\\bar:big\$money:2010:*:*:*:special:ipod_touch:80gb:*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
202 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
203 self.assertEqual(cpe.vendor.value, r'foo\\bar')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
204 self.assertEqual(cpe.product.value, 'big\$money')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
205 self.assertEqual(cpe.version.value, '2010')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
206 self.assertTrue(cpe.update.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
207 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
208 self.assertEqual(cpe.sw_edition.value, "special")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
209 self.assertEqual(cpe.target_sw.value, "ipod_touch")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
210 self.assertEqual(cpe.target_hw.value, "80gb")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
211 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
212 self.assertTrue(cpe.language.any)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)