annotate tests/testCPE.py @ 55:7653ffbec88b tip

Update setup.py
author Benoît Allard <benoit.allard@greenbone.net>
date Wed, 07 Jan 2015 12:02:23 +0100
parents bb1dd2a55643
children
rev   line source
41
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
1 # -*- coding: utf-8 -*-
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
2 # Description:
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
3 # Tests for the CPE parsing methods
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
4 #
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
5 # Authors:
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
6 # BenoƮt Allard <benoit.allard@greenbone.net>
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
7 #
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
8 # Copyright:
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
9 # Copyright (C) 2014 Greenbone Networks GmbH
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
10 #
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
11 # This program is free software; you can redistribute it and/or
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
12 # modify it under the terms of the GNU General Public License
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
13 # as published by the Free Software Foundation; either version 2
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
14 # of the License, or (at your option) any later version.
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
15 #
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
16 # This program is distributed in the hope that it will be useful,
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
19 # GNU General Public License for more details.
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
20 #
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
21 # You should have received a copy of the GNU General Public License
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
22 # along with this program; if not, write to the Free Software
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
23 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
24
40
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
25 import unittest
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
26
41
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
27 from farolluz.parsers.cpe import CPE, CPEAttribute, parse
40
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
28
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
29 class testbindToURI(unittest.TestCase):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
30
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
31 def test_example1(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
32 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
33
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
34 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
35
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
36 def test_example2(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
37 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
38
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
39 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
40
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
41 def test_example3(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
42 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
43
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
44 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
45
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
46 def test_example4(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
47 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
48
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
49 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
50
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
51 def test_example5(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
52 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
53
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
54 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
55
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
56 class testunbindURI(unittest.TestCase):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
57
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
58 def test_example1(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
59 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
60 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
61 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
62 self.assertEqual(cpe.vendor.value, 'microsoft')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
63 self.assertEqual(cpe.product.value, 'internet_explorer')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
64 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
65 self.assertEqual(cpe.update.value, 'beta')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
66 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
67 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
68
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
69 def test_example2(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
70 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
71 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
72 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
73 self.assertEqual(cpe.vendor.value, 'microsoft')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
74 self.assertEqual(cpe.product.value, 'internet_explorer')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
75 self.assertEqual(cpe.version.value, r'8\.\*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
76 self.assertEqual(cpe.update.value, 'sp\?')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
77 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
78 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
79
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
80 def test_example3(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
81 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
82 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
83 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
84 self.assertEqual(cpe.vendor.value, 'microsoft')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
85 self.assertEqual(cpe.product.value, 'internet_explorer')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
86 self.assertEqual(cpe.version.value, r'8\.*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
87 self.assertEqual(cpe.update.value, 'sp?')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
88 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
89 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
90
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
91 def test_example4(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
92 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
93 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
94 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
95 self.assertEqual(cpe.vendor.value, 'hp')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
96 self.assertEqual(cpe.product.value, 'insight_diagnostics')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
97 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
98 self.assertTrue(cpe.update.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
99 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
100 self.assertEqual(cpe.sw_edition.value, 'online')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
101 self.assertEqual(cpe.target_sw.value, 'win2003')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
102 self.assertEqual(cpe.target_hw.value, 'x64')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
103 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
104 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
105
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
106 def test_example5(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
107 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
108 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
109 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
110 self.assertEqual(cpe.vendor.value, 'hp')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
111 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
112 self.assertEqual(cpe.version.value, '7\.51')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
113 self.assertTrue(cpe.update.na)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
114 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
115 self.assertTrue(cpe.sw_edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
116 self.assertEqual(cpe.target_sw.value, 'linux')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
117 self.assertTrue(cpe.target_hw.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
118 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
119 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
120
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
121
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
122 def test_example6(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
123 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
124 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
125
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
126
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
127 def test_example7(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
128 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
129 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
130 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
131 self.assertEqual(cpe.vendor.value, 'foo\~bar')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
132 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
133 self.assertTrue(cpe.version.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
134 self.assertTrue(cpe.update.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
135 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
136 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
137
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
138 def test_example8(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
139 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
140 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
141
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
142 class testbindFS(unittest.TestCase):
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_example1(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('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
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(), '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
148
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
149 def test_example2(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
150 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
151
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
152 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
153
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
154 cpe.version = CPEAttribute(r'8\.\*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
155
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
156 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
157
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
158 def test_example3(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
159 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
160
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
161 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
162
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
163 def test_example4(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
164 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
165
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
166 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
167
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
168 def test_example5(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
169 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
170
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
171 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
172
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
173 class testunbind_fs(unittest.TestCase):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
174
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
175 def test_example1(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
176 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
177 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
178 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
179 self.assertEqual(cpe.vendor.value, 'microsoft')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
180 self.assertEqual(cpe.product.value, 'internet_explorer')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
181 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
182 self.assertEqual(cpe.update.value, "beta")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
183 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
184 self.assertTrue(cpe.sw_edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
185 self.assertTrue(cpe.target_sw.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
186 self.assertTrue(cpe.target_hw.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
187 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
188 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
189
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
190 def test_example2(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
191 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
192 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
193 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
194 self.assertEqual(cpe.vendor.value, 'microsoft')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
195 self.assertEqual(cpe.product.value, 'internet_explorer')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
196 self.assertEqual(cpe.version.value, '8\.*')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
197 self.assertEqual(cpe.update.value, "sp?")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
198 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
199 self.assertTrue(cpe.sw_edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
200 self.assertTrue(cpe.target_sw.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
201 self.assertTrue(cpe.target_hw.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
202 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
203 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
204
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
205 def test_example3(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
206 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
207 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
208 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
209 self.assertEqual(cpe.vendor.value, 'hp')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
210 self.assertEqual(cpe.product.value, 'insight_diagnostics')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
211 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
212 self.assertTrue(cpe.update.na)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
213 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
214 self.assertEqual(cpe.sw_edition.value, "online")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
215 self.assertEqual(cpe.target_sw.value, "win2003")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
216 self.assertEqual(cpe.target_hw.value, "x64")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
217 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
218 self.assertTrue(cpe.language.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
219
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
220 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
221
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
222
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
223 def test_example4(self):
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
224 cpe = CPE()
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
225 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
226 self.assertEqual(cpe.part.value, 'a')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
227 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
228 self.assertEqual(cpe.product.value, 'big\$money')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
229 self.assertEqual(cpe.version.value, '2010')
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
230 self.assertTrue(cpe.update.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
231 self.assertTrue(cpe.edition.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
232 self.assertEqual(cpe.sw_edition.value, "special")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
233 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
234 self.assertEqual(cpe.target_hw.value, "80gb")
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
235 self.assertTrue(cpe.other.any)
1d9b2b06067e Add a CPE parser (and tests)
Benoît Allard <benoit.allard@greenbone.net>
parents:
diff changeset
236 self.assertTrue(cpe.language.any)
41
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
237
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
238 class testParse(unittest.TestCase):
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
239
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
240 def testURI(self):
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
241 cpe = parse('cpe:/a:fogproject:fog:0.31')
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
242 self.assertEqual(cpe.part.value, 'a')
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
243
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
244 def testFS(self):
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
245 cpe = parse('cpe:2.3:a:tenable:web_ui:2.3.3:*:*:*:*:*:*')
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
246 self.assertEqual(cpe.vendor.value, 'tenable')
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
247
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
248 def testGarbage(self):
bb1dd2a55643 CPE: Add a generic 'parse' method
Benoît Allard <benoit.allard@greenbone.net>
parents: 40
diff changeset
249 self.assertRaises(ValueError, parse, 'garbage')
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)