diff options
| author | jvoisin | 2019-01-14 19:29:25 +0000 |
|---|---|---|
| committer | GitHub | 2019-01-14 19:29:25 +0000 |
| commit | e79f7e3bd992c7f0915ef9afe7afb6d79740527a (patch) | |
| tree | f881c25694eb00da2331a9ab280ec1c24a5662ab /src/tests/xxe/disable_xxe_xml_parse.phpt | |
| parent | c943db586ac46b686b49bdf61d8473e39dd93000 (diff) | |
Reorganize the testsuite
Splitting the testsuite in several components makes it easier to manage and comprehend.
This was also needed some some tests aren't passing on Alpine Linux, but we still want to run
as many of them as we can on this platform.
Diffstat (limited to 'src/tests/xxe/disable_xxe_xml_parse.phpt')
| -rw-r--r-- | src/tests/xxe/disable_xxe_xml_parse.phpt | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/tests/xxe/disable_xxe_xml_parse.phpt b/src/tests/xxe/disable_xxe_xml_parse.phpt new file mode 100644 index 0000000..ca77729 --- /dev/null +++ b/src/tests/xxe/disable_xxe_xml_parse.phpt | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | --TEST-- | ||
| 2 | Disable XXE in xml_parse | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php | ||
| 5 | if (!extension_loaded("snuffleupagus")) { | ||
| 6 | echo "skip because snuffleupagus isn't loaded"; | ||
| 7 | } elseif (!extension_loaded("xml")) { | ||
| 8 | echo "skip because the `xml` extension isn't loaded"; | ||
| 9 | } | ||
| 10 | ?> | ||
| 11 | --INI-- | ||
| 12 | sp.configuration_file={PWD}/config/disable_xxe.ini | ||
| 13 | --FILE-- | ||
| 14 | <?php | ||
| 15 | $dir = __DIR__; | ||
| 16 | $content = 'WARNING, external entity loaded!'; | ||
| 17 | file_put_contents('content.txt', $content); | ||
| 18 | |||
| 19 | $xml = <<<EOD | ||
| 20 | <?xml version="1.0"?> | ||
| 21 | <!DOCTYPE root | ||
| 22 | [ | ||
| 23 | <!ENTITY foo SYSTEM "file://$dir/content.txt"> | ||
| 24 | ]> | ||
| 25 | <test><testing>&foo;</testing></test> | ||
| 26 | EOD; | ||
| 27 | |||
| 28 | file_put_contents('content.xml', $xml); | ||
| 29 | |||
| 30 | function create_parser() { | ||
| 31 | $parser = xml_parser_create(); | ||
| 32 | xml_set_element_handler( | ||
| 33 | $parser, | ||
| 34 | function($parser, $name, array $attributes) { | ||
| 35 | var_dump($name); | ||
| 36 | echo "\n"; | ||
| 37 | var_dump($attributes); | ||
| 38 | }, | ||
| 39 | function($parser, $name) { | ||
| 40 | var_dump($name); | ||
| 41 | } | ||
| 42 | ); | ||
| 43 | |||
| 44 | xml_set_character_data_handler( | ||
| 45 | $parser, | ||
| 46 | function ($parser, $text){ | ||
| 47 | echo 'text' . $text; | ||
| 48 | } | ||
| 49 | ); | ||
| 50 | |||
| 51 | return $parser; | ||
| 52 | } | ||
| 53 | |||
| 54 | libxml_disable_entity_loader(true); | ||
| 55 | $parser = create_parser(); | ||
| 56 | $doc = xml_parse($parser, $xml, true); | ||
| 57 | xml_parser_free($parser); | ||
| 58 | |||
| 59 | libxml_disable_entity_loader(false); | ||
| 60 | $parser = create_parser(); | ||
| 61 | $doc = xml_parse($parser, $xml, true); | ||
| 62 | xml_parser_free($parser); | ||
| 63 | |||
| 64 | $xml = "<test><testing>foo</testing></test>"; | ||
| 65 | file_put_contents('content.xml', $xml); | ||
| 66 | $parser = create_parser(); | ||
| 67 | $doc = xml_parse($parser, $xml, true); | ||
| 68 | xml_parser_free($parser); | ||
| 69 | |||
| 70 | --EXPECT-- | ||
| 71 | string(4) "TEST" | ||
| 72 | |||
| 73 | array(0) { | ||
| 74 | } | ||
| 75 | string(7) "TESTING" | ||
| 76 | |||
| 77 | array(0) { | ||
| 78 | } | ||
| 79 | string(7) "TESTING" | ||
| 80 | string(4) "TEST" | ||
| 81 | string(4) "TEST" | ||
| 82 | |||
| 83 | array(0) { | ||
| 84 | } | ||
| 85 | string(7) "TESTING" | ||
| 86 | |||
| 87 | array(0) { | ||
| 88 | } | ||
| 89 | string(7) "TESTING" | ||
| 90 | string(4) "TEST" | ||
| 91 | string(4) "TEST" | ||
| 92 | |||
| 93 | array(0) { | ||
| 94 | } | ||
| 95 | string(7) "TESTING" | ||
| 96 | |||
| 97 | array(0) { | ||
| 98 | } | ||
| 99 | textfoostring(7) "TESTING" | ||
| 100 | string(4) "TEST" | ||
| 101 | --CLEAN-- | ||
| 102 | <?php | ||
| 103 | $dir = __DIR__; | ||
| 104 | unlink($dir . "/content.xml"); | ||
| 105 | unlink($dir . "/content.txt"); | ||
| 106 | ?> | ||
