22 #include <cgreen/cgreen.h>
23 #include <cgreen/mocks.h>
35 Ensure (xmlutils, parse_entity_parses_simple_xml)
40 xml =
"<a><b>1</b></a>";
42 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
44 assert_that (
entity_name (entity), is_equal_to_string (
"a"));
47 assert_that (
entity_name (b), is_equal_to_string (
"b"));
49 assert_that (
entity_text (b), is_equal_to_string (
"1"));
52 Ensure (xmlutils, parse_entity_parses_xml_with_attributes)
57 xml =
"<a><b ba1='test'>1</b></a>";
59 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
66 Ensure (xmlutils, parse_entity_handles_declaration)
71 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><b ba1='test'>1</b></a>";
73 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
75 assert_that (
entity_name (entity), is_equal_to_string (
"a"));
78 assert_that (
entity_name (b), is_equal_to_string (
"b"));
80 assert_that (
entity_text (b), is_equal_to_string (
"1"));
83 Ensure (xmlutils, parse_entity_handles_namespace)
88 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><n:b ba1='test'>1</n:b></a>";
90 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
92 assert_that (
entity_name (entity), is_equal_to_string (
"a"));
95 assert_that (
entity_name (b), is_equal_to_string (
"n:b"));
97 assert_that (
entity_text (b), is_equal_to_string (
"1"));
100 Ensure (xmlutils, parse_entity_oval_timestamp)
102 gchar *generator_name;
103 entity_t generator, timestamp, entity;
106 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \
107 "<oval_definitions xsi:schemaLocation=\"http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#windows windows-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#independent independent-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd\" xmlns=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:oval=\"http://oval.mitre.org/XMLSchema/oval-common-5\" xmlns:oval-def=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\">" \
109 " <oval:product_name>The OVAL Repository</oval:product_name>" \
110 " <oval:schema_version>5.10</oval:schema_version>" \
111 " <oval:timestamp>2015-08-20T10:09:07.183-04:00</oval:timestamp>" \
113 "</oval_definitions>";
115 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
117 assert_that (
entity_name (entity), is_equal_to_string (
"oval_definitions"));
118 generator_name = g_strdup (
"generator");
120 g_free (generator_name);
121 assert_that (generator, is_not_null);
123 assert_that (timestamp, is_not_null);
124 assert_that (
entity_text (timestamp), is_equal_to_string (
"2015-08-20T10:09:07.183-04:00"));
129 Ensure (xmlutils, next_entities_handles_multiple_children)
135 xml =
"<top><a>1</a><b></b><c>3</c></top>";
137 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
139 assert_that (
entity_name (entity), is_equal_to_string (
"top"));
144 assert_that (child, is_not_null);
145 assert_that (
entity_name (child), is_equal_to_string (
"a"));
146 assert_that (
entity_text (child), is_equal_to_string (
"1"));
150 assert_that (child, is_not_null);
151 assert_that (
entity_name (child), is_equal_to_string (
"b"));
152 assert_that (
entity_text (child), is_equal_to_string (
""));
156 assert_that (child, is_not_null);
157 assert_that (
entity_name (child), is_equal_to_string (
"c"));
158 assert_that (
entity_text (child), is_equal_to_string (
"3"));
164 Ensure (xmlutils, parse_element_parses_simple_xml)
169 xml =
"<a><b>1</b></a>";
171 assert_that (
parse_element (xml, &element), is_equal_to (0));
173 assert_that (
element_name (element), is_equal_to_string (
"a"));
176 assert_that (
element_name (b), is_equal_to_string (
"b"));
178 assert_that (
element_text (b), is_equal_to_string (
"1"));
181 Ensure (xmlutils, parse_element_parses_xml_with_attributes)
186 xml =
"<a><b ba1='test'>1</b></a>";
188 assert_that (
parse_element (xml, &element), is_equal_to (0));
195 Ensure (xmlutils, parse_element_handles_declaration)
200 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><b ba1='test'>1</b></a>";
202 assert_that (
parse_element (xml, &element), is_equal_to (0));
204 assert_that (
element_name (element), is_equal_to_string (
"a"));
207 assert_that (
element_name (b), is_equal_to_string (
"b"));
209 assert_that (
element_text (b), is_equal_to_string (
"1"));
212 Ensure (xmlutils, parse_element_handles_namespace)
217 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><n:b ba1='test' n2:ba2='test2'>1</n:b></a>";
219 assert_that (
parse_element (xml, &element), is_equal_to (0));
221 assert_that (
element_name (element), is_equal_to_string (
"a"));
224 assert_that (
element_name (b), is_equal_to_string (
"n:b"));
226 assert_that (
element_text (b), is_equal_to_string (
"1"));
231 Ensure (xmlutils, parse_element_oval_timestamp)
233 gchar *generator_name;
237 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \
238 "<oval_definitions xsi:schemaLocation=\"http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#windows windows-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#independent independent-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd\" xmlns=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:oval=\"http://oval.mitre.org/XMLSchema/oval-common-5\" xmlns:oval-def=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\">" \
240 " <oval:product_name>The OVAL Repository</oval:product_name>" \
241 " <oval:schema_version>5.10</oval:schema_version>" \
242 " <oval:timestamp>2015-08-20T10:09:07.183-04:00</oval:timestamp>" \
244 "</oval_definitions>";
246 assert_that (
parse_element (xml, &element), is_equal_to (0));
248 assert_that (
element_name (element), is_equal_to_string (
"oval_definitions"));
249 generator_name = g_strdup (
"generator");
251 g_free (generator_name);
252 assert_that (generator, is_not_null);
254 assert_that (timestamp, is_not_null);
255 assert_that (
element_text (timestamp), is_equal_to_string (
"2015-08-20T10:09:07.183-04:00"));
258 Ensure (xmlutils, parse_element_item_metadata)
264 " <cpe-item name=\"cpe:/a:%240.99_kindle_books_project:%240.99_kindle_books:6::~~~android~~\">" \
265 " <title xml:lang=\"en-US\">$0.99 Kindle Books project $0.99 Kindle Books (aka com.kindle.books.for99) for android 6.0</title>" \
267 " <reference href=\"https://play.google.com/store/apps/details?id=com.kindle.books.for99\">Product information</reference>" \
268 " <reference href=\"https://docs.google.com/spreadsheets/d/1t5GXwjw82SyunALVJb2w0zi3FoLRIkfGPc7AMjRF0r4/edit?pli=1#gid=1053404143\">Government Advisory</reference>" \
270 " <meta:item-metadata nvd-id=\"289692\" status=\"FINAL\" modification-date=\"2014-11-10T17:01:25.103Z\"/>" \
274 assert_that (
parse_element (xml, &element), is_equal_to (0));
276 assert_that (
element_name (element), is_equal_to_string (
"cpe-list"));
278 assert_that (item, is_not_null);
280 assert_that (meta, is_not_null);
281 assert_that (
element_name (meta), is_equal_to_string (
"meta:item-metadata"));
284 Ensure (xmlutils, parse_element_item_metadata_with_namespace)
289 xml =
"<cpe-list xmlns=\"http://cpe.mitre.org/dictionary/2.0\" xmlns:ns6=\"http://scap.nist.gov/schema/scap-core/0.1\" xmlns:config=\"http://scap.nist.gov/schema/configuration/0.1\" xmlns:meta=\"http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2\" xmlns:cpe-23=\"http://scap.nist.gov/schema/cpe-extension/2.3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:scap-core=\"http://scap.nist.gov/schema/scap-core/0.3\" xsi:schemaLocation=\"http://cpe.mitre.org/dictionary/2.0 https://scap.nist.gov/schema/cpe/2.2/cpe-dictionary_2.2.xsd http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2 https://scap.nist.gov/schema/cpe/2.1/cpe-dictionary-metadata_0.2.xsd http://scap.nist.gov/schema/scap-core/0.3 https://scap.nist.gov/schema/nvd/scap-core_0.3.xsd http://scap.nist.gov/schema/configuration/0.1 https://scap.nist.gov/schema/nvd/configuration_0.1.xsd http://scap.nist.gov/schema/scap-core/0.1 https://scap.nist.gov/schema/nvd/scap-core_0.1.xsd\">" \
290 " <cpe-item name=\"cpe:/a:%240.99_kindle_books_project:%240.99_kindle_books:6::~~~android~~\">" \
291 " <title xml:lang=\"en-US\">$0.99 Kindle Books project $0.99 Kindle Books (aka com.kindle.books.for99) for android 6.0</title>" \
293 " <reference href=\"https://play.google.com/store/apps/details?id=com.kindle.books.for99\">Product information</reference>" \
294 " <reference href=\"https://docs.google.com/spreadsheets/d/1t5GXwjw82SyunALVJb2w0zi3FoLRIkfGPc7AMjRF0r4/edit?pli=1#gid=1053404143\">Government Advisory</reference>" \
296 " <meta:item-metadata nvd-id=\"289692\" status=\"FINAL\" modification-date=\"2014-11-10T17:01:25.103Z\"/>" \
300 assert_that (
parse_element (xml, &element), is_equal_to (0));
302 assert_that (
element_name (element), is_equal_to_string (
"cpe-list"));
304 assert_that (item, is_not_null);
306 assert_that (meta, is_not_null);
308 assert_that (
element_name (meta), is_equal_to_string (
"item-metadata"));
312 Ensure (xmlutils, parse_element_item_handles_cdata)
317 xml =
"<description><![CDATA[Several vulnerabilities were discovered in the Chromium browser. The Common Vulnerabilities and Exposures project identifies the following problems: CVE-2011-1108 Google Chrome before 9.0.597.107 does not properly implement JavaScript dialogs, which allows remote attackers to cause a denial of service or possibly have unspecified other impact via a crafted HTML document. CVE-2011-1109 Google Chrome before 9.0.597.107 does not properly process nodes in Cascading Style Sheets stylesheets, which allows remote attackers to cause a denial of service or possibly have unspecified other impact via unknown vectors that lead to a "stale pointer." CVE-2011-1113 Google Chrome before 9.0.597.107 on 64-bit Linux platforms does not properly perform pickle deserialization, which allows remote attackers to cause a denial of service via unspecified vectors. CVE-2011-1114 Google Chrome before 9.0.597.107 does not properly handle tables, which allows remote attackers to cause a denial of service or possibly have unspecified other impact via unknown vectors that lead to a "stale node." CVE-2011-1115 Google Chrome before 9.0.597.107 does not properly render tables, which allows remote attackers to cause a denial of service or possibly have unspecified other impact via unknown vectors that lead to a "stale pointer." CVE-2011-1121 Integer overflow in Google Chrome before 9.0.597.107 allows remote attackers to cause a denial of service or possibly have unspecified other impact via vectors involving a TEXTAREA element. CVE-2011-1122 The WebGL implementation in Google Chrome before 9.0.597.107 allows remote attackers to cause a denial of service via unspecified vectors, aka Issue 71960. In addition, this upload fixes the following issues : Out-of-bounds read in text searching [69640] Memory corruption in SVG fonts. [72134] Memory corruption with counter nodes. [69628] Stale node in box layout. [70027] Cross-origin error message leak with workers. [70336] Stale pointer in table painting. [72028] Stale pointer with SVG cursors. [73746]]]></description>";
319 assert_that (
parse_element (xml, &element), is_equal_to (0));
320 assert_that (
element_name (element), is_equal_to_string (
"description"));
321 assert_that (
element_text (element), is_equal_to_string (
"Several vulnerabilities were discovered in the Chromium browser. The Common Vulnerabilities and Exposures project identifies the following problems: CVE-2011-1108 Google Chrome before 9.0.597.107 does not properly implement JavaScript dialogs, which allows remote attackers to cause a denial of service or possibly have unspecified other impact via a crafted HTML document. CVE-2011-1109 Google Chrome before 9.0.597.107 does not properly process nodes in Cascading Style Sheets stylesheets, which allows remote attackers to cause a denial of service or possibly have unspecified other impact via unknown vectors that lead to a "stale pointer." CVE-2011-1113 Google Chrome before 9.0.597.107 on 64-bit Linux platforms does not properly perform pickle deserialization, which allows remote attackers to cause a denial of service via unspecified vectors. CVE-2011-1114 Google Chrome before 9.0.597.107 does not properly handle tables, which allows remote attackers to cause a denial of service or possibly have unspecified other impact via unknown vectors that lead to a "stale node." CVE-2011-1115 Google Chrome before 9.0.597.107 does not properly render tables, which allows remote attackers to cause a denial of service or possibly have unspecified other impact via unknown vectors that lead to a "stale pointer." CVE-2011-1121 Integer overflow in Google Chrome before 9.0.597.107 allows remote attackers to cause a denial of service or possibly have unspecified other impact via vectors involving a TEXTAREA element. CVE-2011-1122 The WebGL implementation in Google Chrome before 9.0.597.107 allows remote attackers to cause a denial of service via unspecified vectors, aka Issue 71960. In addition, this upload fixes the following issues : Out-of-bounds read in text searching [69640] Memory corruption in SVG fonts. [72134] Memory corruption with counter nodes. [69628] Stale node in box layout. [70027] Cross-origin error message leak with workers. [70336] Stale pointer in table painting. [72028] Stale pointer with SVG cursors. [73746]"));
326 Ensure (xmlutils, element_next_handles_multiple_children)
331 xml =
"<top><a>1</a><b>2</b><c>3</c></top>";
333 assert_that (
parse_element (xml, &element), is_equal_to (0));
335 assert_that (
element_name (element), is_equal_to_string (
"top"));
338 assert_that (child, is_not_null);
339 assert_that (
element_name (child), is_equal_to_string (
"a"));
340 assert_that (
element_text (child), is_equal_to_string (
"1"));
343 assert_that (child, is_not_null);
344 assert_that (
element_name (child), is_equal_to_string (
"b"));
345 assert_that (
element_text (child), is_equal_to_string (
"2"));
348 assert_that (child, is_not_null);
349 assert_that (
element_name (child), is_equal_to_string (
"c"));
350 assert_that (
element_text (child), is_equal_to_string (
"3"));
353 Ensure (xmlutils, parse_element_free_using_child)
358 xml =
"<a><b><c>1</c></b></a>";
360 assert_that (
parse_element (xml, &element), is_equal_to (0));
361 assert_that (
element_name (element), is_equal_to_string (
"a"));
363 assert_that (element, is_not_null);
365 assert_that (element, is_not_null);
376 suite = create_test_suite ();
378 add_test_with_context (suite, xmlutils, parse_entity_parses_simple_xml);
379 add_test_with_context (suite, xmlutils, parse_entity_parses_xml_with_attributes);
380 add_test_with_context (suite, xmlutils, parse_entity_handles_declaration);
381 add_test_with_context (suite, xmlutils, parse_entity_handles_namespace);
382 add_test_with_context (suite, xmlutils, parse_entity_oval_timestamp);
384 add_test_with_context (suite, xmlutils, next_entities_handles_multiple_children);
386 add_test_with_context (suite, xmlutils, parse_element_parses_simple_xml);
387 add_test_with_context (suite, xmlutils, parse_element_parses_xml_with_attributes);
388 add_test_with_context (suite, xmlutils, parse_element_handles_declaration);
389 add_test_with_context (suite, xmlutils, parse_element_handles_namespace);
390 add_test_with_context (suite, xmlutils, parse_element_oval_timestamp);
391 add_test_with_context (suite, xmlutils, parse_element_item_metadata);
392 add_test_with_context (suite, xmlutils, parse_element_item_metadata_with_namespace);
393 add_test_with_context (suite, xmlutils, parse_element_item_handles_cdata);
394 add_test_with_context (suite, xmlutils, parse_element_free_using_child);
396 add_test_with_context (suite, xmlutils, element_next_handles_multiple_children);
399 return run_single_test (suite, argv[1], create_text_reporter ());
401 return run_test_suite (suite, create_text_reporter ());