8#include <cgreen/cgreen.h>
9#include <cgreen/mocks.h>
21Ensure (xmlutils, parse_entity_parses_simple_xml)
26 xml =
"<a><b>1</b></a>";
28 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
30 assert_that (
entity_name (entity), is_equal_to_string (
"a"));
33 assert_that (
entity_name (b), is_equal_to_string (
"b"));
35 assert_that (
entity_text (b), is_equal_to_string (
"1"));
38Ensure (xmlutils, parse_entity_parses_xml_with_attributes)
43 xml =
"<a><b ba1='test'>1</b></a>";
45 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
52Ensure (xmlutils, parse_entity_handles_declaration)
57 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><b ba1='test'>1</b></a>";
59 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
61 assert_that (
entity_name (entity), is_equal_to_string (
"a"));
64 assert_that (
entity_name (b), is_equal_to_string (
"b"));
66 assert_that (
entity_text (b), is_equal_to_string (
"1"));
69Ensure (xmlutils, parse_entity_handles_namespace)
75 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><n:b ba1='test'>1</n:b></a>";
77 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
79 assert_that (
entity_name (entity), is_equal_to_string (
"a"));
82 assert_that (
entity_name (b), is_equal_to_string (
"n:b"));
84 assert_that (
entity_text (b), is_equal_to_string (
"1"));
87Ensure (xmlutils, parse_entity_oval_timestamp)
89 gchar *generator_name;
90 entity_t generator, timestamp, entity;
93 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
95 "xsi:schemaLocation=\"http://oval.mitre.org/XMLSchema/"
96 "oval-definitions-5 oval-definitions-schema.xsd "
97 "http://oval.mitre.org/XMLSchema/oval-definitions-5#linux "
98 "linux-definitions-schema.xsd "
99 "http://oval.mitre.org/XMLSchema/oval-definitions-5#windows "
100 "windows-definitions-schema.xsd "
101 "http://oval.mitre.org/XMLSchema/oval-definitions-5#independent "
102 "independent-definitions-schema.xsd "
103 "http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd "
104 "http://oval.mitre.org/XMLSchema/oval-definitions-5#unix "
105 "unix-definitions-schema.xsd\" "
106 "xmlns=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\" "
107 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
108 "xmlns:oval=\"http://oval.mitre.org/XMLSchema/oval-common-5\" "
109 "xmlns:oval-def=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\">"
111 " <oval:product_name>The OVAL Repository</oval:product_name>"
112 " <oval:schema_version>5.10</oval:schema_version>"
113 " <oval:timestamp>2015-08-20T10:09:07.183-04:00</oval:timestamp>"
115 "</oval_definitions>";
117 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
119 assert_that (
entity_name (entity), is_equal_to_string (
"oval_definitions"));
120 generator_name = g_strdup (
"generator");
122 g_free (generator_name);
123 assert_that (generator, is_not_null);
125 assert_that (timestamp, is_not_null);
127 is_equal_to_string (
"2015-08-20T10:09:07.183-04:00"));
132Ensure (xmlutils, next_entities_handles_multiple_children)
138 xml =
"<top><a>1</a><b></b><c>3</c></top>";
140 assert_that (
parse_entity (xml, &entity), is_equal_to (0));
142 assert_that (
entity_name (entity), is_equal_to_string (
"top"));
147 assert_that (child, is_not_null);
148 assert_that (
entity_name (child), is_equal_to_string (
"a"));
149 assert_that (
entity_text (child), is_equal_to_string (
"1"));
153 assert_that (child, is_not_null);
154 assert_that (
entity_name (child), is_equal_to_string (
"b"));
155 assert_that (
entity_text (child), is_equal_to_string (
""));
159 assert_that (child, is_not_null);
160 assert_that (
entity_name (child), is_equal_to_string (
"c"));
161 assert_that (
entity_text (child), is_equal_to_string (
"3"));
167Ensure (xmlutils, parse_element_parses_simple_xml)
172 xml =
"<a><b>1</b></a>";
174 assert_that (
parse_element (xml, &element), is_equal_to (0));
176 assert_that (
element_name (element), is_equal_to_string (
"a"));
179 assert_that (
element_name (b), is_equal_to_string (
"b"));
181 assert_that (
element_text (b), is_equal_to_string (
"1"));
184Ensure (xmlutils, parse_element_parses_xml_with_attributes)
189 xml =
"<a><b ba1='test'>1</b></a>";
191 assert_that (
parse_element (xml, &element), is_equal_to (0));
198Ensure (xmlutils, parse_element_handles_declaration)
203 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><b ba1='test'>1</b></a>";
205 assert_that (
parse_element (xml, &element), is_equal_to (0));
207 assert_that (
element_name (element), is_equal_to_string (
"a"));
210 assert_that (
element_name (b), is_equal_to_string (
"b"));
212 assert_that (
element_text (b), is_equal_to_string (
"1"));
215Ensure (xmlutils, parse_element_handles_namespace)
220 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><a><n:b ba1='test' "
221 "n2:ba2='test2'>1</n:b></a>";
223 assert_that (
parse_element (xml, &element), is_equal_to (0));
225 assert_that (
element_name (element), is_equal_to_string (
"a"));
228 assert_that (
element_name (b), is_equal_to_string (
"n:b"));
230 assert_that (
element_text (b), is_equal_to_string (
"1"));
235Ensure (xmlutils, parse_element_oval_timestamp)
237 gchar *generator_name;
241 xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
243 "xsi:schemaLocation=\"http://oval.mitre.org/XMLSchema/"
244 "oval-definitions-5 oval-definitions-schema.xsd "
245 "http://oval.mitre.org/XMLSchema/oval-definitions-5#linux "
246 "linux-definitions-schema.xsd "
247 "http://oval.mitre.org/XMLSchema/oval-definitions-5#windows "
248 "windows-definitions-schema.xsd "
249 "http://oval.mitre.org/XMLSchema/oval-definitions-5#independent "
250 "independent-definitions-schema.xsd "
251 "http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd "
252 "http://oval.mitre.org/XMLSchema/oval-definitions-5#unix "
253 "unix-definitions-schema.xsd\" "
254 "xmlns=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\" "
255 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
256 "xmlns:oval=\"http://oval.mitre.org/XMLSchema/oval-common-5\" "
257 "xmlns:oval-def=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\">"
259 " <oval:product_name>The OVAL Repository</oval:product_name>"
260 " <oval:schema_version>5.10</oval:schema_version>"
261 " <oval:timestamp>2015-08-20T10:09:07.183-04:00</oval:timestamp>"
263 "</oval_definitions>";
265 assert_that (
parse_element (xml, &element), is_equal_to (0));
267 assert_that (
element_name (element), is_equal_to_string (
"oval_definitions"));
268 generator_name = g_strdup (
"generator");
270 g_free (generator_name);
271 assert_that (generator, is_not_null);
273 assert_that (timestamp, is_not_null);
275 is_equal_to_string (
"2015-08-20T10:09:07.183-04:00"));
278Ensure (xmlutils, parse_element_item_metadata)
286 "a:%240.99_kindle_books_project:%240.99_kindle_books:6::~~~android~~\">"
287 " <title xml:lang=\"en-US\">$0.99 Kindle Books project $0.99 Kindle "
288 "Books (aka com.kindle.books.for99) for android 6.0</title>"
291 "href=\"https://play.google.com/store/apps/"
292 "details?id=com.kindle.books.for99\">Product information</reference>"
294 "href=\"https://docs.google.com/spreadsheets/d/"
295 "1t5GXwjw82SyunALVJb2w0zi3FoLRIkfGPc7AMjRF0r4/"
296 "edit?pli=1#gid=1053404143\">Government Advisory</reference>"
298 " <meta:item-metadata nvd-id=\"289692\" status=\"FINAL\" "
299 "modification-date=\"2014-11-10T17:01:25.103Z\"/>"
303 assert_that (
parse_element (xml, &element), is_equal_to (0));
305 assert_that (
element_name (element), is_equal_to_string (
"cpe-list"));
307 assert_that (item, is_not_null);
309 assert_that (meta, is_not_null);
310 assert_that (
element_name (meta), is_equal_to_string (
"meta:item-metadata"));
313Ensure (xmlutils, parse_element_item_metadata_with_namespace)
318 xml =
"<cpe-list xmlns=\"http://cpe.mitre.org/dictionary/2.0\" "
319 "xmlns:ns6=\"http://scap.nist.gov/schema/scap-core/0.1\" "
320 "xmlns:config=\"http://scap.nist.gov/schema/configuration/0.1\" "
321 "xmlns:meta=\"http://scap.nist.gov/schema/cpe-dictionary-metadata/"
322 "0.2\" xmlns:cpe-23=\"http://scap.nist.gov/schema/cpe-extension/2.3\" "
323 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
324 "xmlns:scap-core=\"http://scap.nist.gov/schema/scap-core/0.3\" "
325 "xsi:schemaLocation=\"http://cpe.mitre.org/dictionary/2.0 "
326 "https://scap.nist.gov/schema/cpe/2.2/cpe-dictionary_2.2.xsd "
327 "http://scap.nist.gov/schema/cpe-dictionary-metadata/0.2 "
328 "https://scap.nist.gov/schema/cpe/2.1/cpe-dictionary-metadata_0.2.xsd "
329 "http://scap.nist.gov/schema/scap-core/0.3 "
330 "https://scap.nist.gov/schema/nvd/scap-core_0.3.xsd "
331 "http://scap.nist.gov/schema/configuration/0.1 "
332 "https://scap.nist.gov/schema/nvd/configuration_0.1.xsd "
333 "http://scap.nist.gov/schema/scap-core/0.1 "
334 "https://scap.nist.gov/schema/nvd/scap-core_0.1.xsd\">"
337 "a:%240.99_kindle_books_project:%240.99_kindle_books:6::~~~android~~\">"
338 " <title xml:lang=\"en-US\">$0.99 Kindle Books project $0.99 Kindle "
339 "Books (aka com.kindle.books.for99) for android 6.0</title>"
342 "href=\"https://play.google.com/store/apps/"
343 "details?id=com.kindle.books.for99\">Product information</reference>"
345 "href=\"https://docs.google.com/spreadsheets/d/"
346 "1t5GXwjw82SyunALVJb2w0zi3FoLRIkfGPc7AMjRF0r4/"
347 "edit?pli=1#gid=1053404143\">Government Advisory</reference>"
349 " <meta:item-metadata nvd-id=\"289692\" status=\"FINAL\" "
350 "modification-date=\"2014-11-10T17:01:25.103Z\"/>"
354 assert_that (
parse_element (xml, &element), is_equal_to (0));
356 assert_that (
element_name (element), is_equal_to_string (
"cpe-list"));
358 assert_that (item, is_not_null);
360 assert_that (meta, is_not_null);
362 assert_that (
element_name (meta), is_equal_to_string (
"item-metadata"));
367Ensure (xmlutils, parse_element_item_handles_cdata)
373 "<description><![CDATA[Several vulnerabilities were discovered in the "
374 "Chromium browser. The Common Vulnerabilities and Exposures project "
375 "identifies the following problems: CVE-2011-1108 Google Chrome before "
376 "9.0.597.107 does not properly implement JavaScript dialogs, which allows "
377 "remote attackers to cause a denial of service or possibly have "
378 "unspecified other impact via a crafted HTML document. CVE-2011-1109 "
379 "Google Chrome before 9.0.597.107 does not properly process nodes in "
380 "Cascading Style Sheets stylesheets, which allows remote attackers to "
381 "cause a denial of service or possibly have unspecified other impact via "
382 "unknown vectors that lead to a "stale pointer." CVE-2011-1113 "
383 "Google Chrome before 9.0.597.107 on 64-bit Linux platforms does not "
384 "properly perform pickle deserialization, which allows remote attackers to "
385 "cause a denial of service via unspecified vectors. CVE-2011-1114 Google "
386 "Chrome before 9.0.597.107 does not properly handle tables, which allows "
387 "remote attackers to cause a denial of service or possibly have "
388 "unspecified other impact via unknown vectors that lead to a "stale "
389 "node." CVE-2011-1115 Google Chrome before 9.0.597.107 does not "
390 "properly render tables, which allows remote attackers to cause a denial "
391 "of service or possibly have unspecified other impact via unknown vectors "
392 "that lead to a "stale pointer." CVE-2011-1121 Integer overflow "
393 "in Google Chrome before 9.0.597.107 allows remote attackers to cause a "
394 "denial of service or possibly have unspecified other impact via vectors "
395 "involving a TEXTAREA element. CVE-2011-1122 The WebGL implementation in "
396 "Google Chrome before 9.0.597.107 allows remote attackers to cause a "
397 "denial of service via unspecified vectors, aka Issue 71960. In addition, "
398 "this upload fixes the following issues : Out-of-bounds read in text "
399 "searching [69640] Memory corruption in SVG fonts. [72134] Memory "
400 "corruption with counter nodes. [69628] Stale node in box layout. [70027] "
401 "Cross-origin error message leak with workers. [70336] Stale pointer in "
402 "table painting. [72028] Stale pointer with SVG cursors. "
403 "[73746]]]></description>";
405 assert_that (
parse_element (xml, &element), is_equal_to (0));
406 assert_that (
element_name (element), is_equal_to_string (
"description"));
410 "Several vulnerabilities were discovered in the Chromium browser. The "
411 "Common Vulnerabilities and Exposures project identifies the following "
412 "problems: CVE-2011-1108 Google Chrome before 9.0.597.107 does not "
413 "properly implement JavaScript dialogs, which allows remote attackers to "
414 "cause a denial of service or possibly have unspecified other impact via "
415 "a crafted HTML document. CVE-2011-1109 Google Chrome before 9.0.597.107 "
416 "does not properly process nodes in Cascading Style Sheets stylesheets, "
417 "which allows remote attackers to cause a denial of service or possibly "
418 "have unspecified other impact via unknown vectors that lead to a "
419 ""stale pointer." CVE-2011-1113 Google Chrome before "
420 "9.0.597.107 on 64-bit Linux platforms does not properly perform pickle "
421 "deserialization, which allows remote attackers to cause a denial of "
422 "service via unspecified vectors. CVE-2011-1114 Google Chrome before "
423 "9.0.597.107 does not properly handle tables, which allows remote "
424 "attackers to cause a denial of service or possibly have unspecified "
425 "other impact via unknown vectors that lead to a "stale node." "
426 "CVE-2011-1115 Google Chrome before 9.0.597.107 does not properly render "
427 "tables, which allows remote attackers to cause a denial of service or "
428 "possibly have unspecified other impact via unknown vectors that lead to "
429 "a "stale pointer." CVE-2011-1121 Integer overflow in Google "
430 "Chrome before 9.0.597.107 allows remote attackers to cause a denial of "
431 "service or possibly have unspecified other impact via vectors involving "
432 "a TEXTAREA element. CVE-2011-1122 The WebGL implementation in Google "
433 "Chrome before 9.0.597.107 allows remote attackers to cause a denial of "
434 "service via unspecified vectors, aka Issue 71960. In addition, this "
435 "upload fixes the following issues : Out-of-bounds read in text "
436 "searching [69640] Memory corruption in SVG fonts. [72134] Memory "
437 "corruption with counter nodes. [69628] Stale node in box layout. "
438 "[70027] Cross-origin error message leak with workers. [70336] Stale "
439 "pointer in table painting. [72028] Stale pointer with SVG cursors. "
445Ensure (xmlutils, element_next_handles_multiple_children)
450 xml =
"<top><a>1</a><b>2</b><c>3</c></top>";
452 assert_that (
parse_element (xml, &element), is_equal_to (0));
454 assert_that (
element_name (element), is_equal_to_string (
"top"));
457 assert_that (child, is_not_null);
458 assert_that (
element_name (child), is_equal_to_string (
"a"));
459 assert_that (
element_text (child), is_equal_to_string (
"1"));
462 assert_that (child, is_not_null);
463 assert_that (
element_name (child), is_equal_to_string (
"b"));
464 assert_that (
element_text (child), is_equal_to_string (
"2"));
467 assert_that (child, is_not_null);
468 assert_that (
element_name (child), is_equal_to_string (
"c"));
469 assert_that (
element_text (child), is_equal_to_string (
"3"));
472Ensure (xmlutils, parse_element_free_using_child)
477 xml =
"<a><b><c>1</c></b></a>";
479 assert_that (
parse_element (xml, &element), is_equal_to (0));
480 assert_that (
element_name (element), is_equal_to_string (
"a"));
482 assert_that (element, is_not_null);
484 assert_that (element, is_not_null);
488Ensure (xmlutils, print_element_to_string_prints)
494 xml =
"<a aa=\"1\">a text<b><c ca=\"x\" ca2=\"y\">1</c><d/><e></e></b> and "
496 str = g_string_new (
"");
498 assert_that (
parse_element (xml, &element), is_equal_to (0));
500 assert_that (str->str, is_equal_to_string (
501 "<a aa=\"1\">a text and more a text<b><c ca=\"x\" "
502 "ca2=\"y\">1</c><d></d><e></e></b></a>"));
503 g_string_free (str, TRUE);
514 suite = create_test_suite ();
516 add_test_with_context (suite, xmlutils, parse_entity_parses_simple_xml);
517 add_test_with_context (suite, xmlutils,
518 parse_entity_parses_xml_with_attributes);
519 add_test_with_context (suite, xmlutils, parse_entity_handles_declaration);
520 add_test_with_context (suite, xmlutils, parse_entity_handles_namespace);
521 add_test_with_context (suite, xmlutils, parse_entity_oval_timestamp);
523 add_test_with_context (suite, xmlutils,
524 next_entities_handles_multiple_children);
526 add_test_with_context (suite, xmlutils, parse_element_parses_simple_xml);
527 add_test_with_context (suite, xmlutils,
528 parse_element_parses_xml_with_attributes);
529 add_test_with_context (suite, xmlutils, parse_element_handles_declaration);
530 add_test_with_context (suite, xmlutils, parse_element_handles_namespace);
531 add_test_with_context (suite, xmlutils, parse_element_oval_timestamp);
532 add_test_with_context (suite, xmlutils, parse_element_item_metadata);
533 add_test_with_context (suite, xmlutils,
534 parse_element_item_metadata_with_namespace);
535 add_test_with_context (suite, xmlutils, parse_element_item_handles_cdata);
536 add_test_with_context (suite, xmlutils, parse_element_free_using_child);
538 add_test_with_context (suite, xmlutils, print_element_to_string_prints);
540 add_test_with_context (suite, xmlutils,
541 element_next_handles_multiple_children);
544 return run_single_test (suite, argv[1], create_text_reporter ());
546 return run_test_suite (suite, create_text_reporter ());
entities_t entities
Children.
void element_free(element_t element)
Free an entire element tree.
const char * entity_attribute(entity_t entity, const char *name)
Get an attribute of an entity.
char * entity_name(entity_t entity)
Get the name an entity.
char * entity_text(entity_t entity)
Get the text an entity.
const gchar * element_name(element_t element)
Get the name of an element.
entity_t first_entity(entities_t entities)
Return the first entity from an entities_t.
gchar * element_text(element_t element)
Get text of an element.
void print_element_to_string(element_t element, GString *string)
Print an XML element tree to a GString, appending it if string is not.
entities_t next_entities(entities_t entities)
Return all the entities from an entities_t after the first.
gchar * element_attribute(element_t element, const gchar *name)
Get an attribute of an element.
element_t element_first_child(element_t element)
Get the first child of an element.
int parse_element(const gchar *string, element_t *element)
Read an XML element tree from a string.
entity_t entity_child(entity_t entity, const char *name)
Get a child of an entity.
element_t element_next(element_t element)
Get the next sibling of an element.
element_t element_child(element_t element, const gchar *name)
Get a child of an element.
int parse_entity(const char *string, entity_t *entity)
Read an XML entity tree from a string.
struct _xmlNode * element_t
GSList * entities_t
Entities.
Ensure(xmlutils, parse_entity_parses_simple_xml)
int main(int argc, char **argv)