* test/rexml/test_document.rb

(REXMLTests::TestDocument::EntityExpansionLimitTest): Define
  test XML in each test method because (1) each XML in used only
  one test and (2) related data and code should be close.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2014-11-15 11:45:27 +00:00
parent a5406b873c
commit a38971c595
2 changed files with 77 additions and 70 deletions

View File

@ -1,3 +1,10 @@
Sat Nov 15 20:43:31 2014 Kouhei Sutou <kou@cozmixng.org>
* test/rexml/test_document.rb
(REXMLTests::TestDocument::EntityExpansionLimitTest): Define
test XML in each test method because (1) each XML in used only
one test and (2) related data and code should be close.
Sat Nov 15 20:39:06 2014 Kouhei Sutou <kou@cozmixng.org>
* test/rexml/test_document.rb

View File

@ -41,7 +41,8 @@ EOF
REXML::Security.entity_expansion_limit = @default_entity_expansion_limit
end
XML_WITH_NESTED_ENTITY = <<EOF
def test_general_entity_have_value
xml = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
@ -57,7 +58,21 @@ EOF
</member>
EOF
XML_WITH_NESTED_EMPTY_ENTITY = <<EOF
doc = REXML::Document.new(xml)
assert_raise(RuntimeError) do
doc.root.children.first.value
end
REXML::Security.entity_expansion_limit = 100
assert_equal(100, REXML::Security.entity_expansion_limit)
doc = REXML::Document.new(xml)
assert_raise(RuntimeError) do
doc.root.children.first.value
end
assert_equal(101, doc.entity_expansion_count)
end
def test_general_entity_empty_value
xml = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
@ -73,7 +88,45 @@ EOF
</member>
EOF
XML_WITH_NESTED_PARAMETER_ENTITY = <<EOF
doc = REXML::Document.new(xml)
assert_raise(RuntimeError) do
doc.root.children.first.value
end
REXML::Security.entity_expansion_limit = 100
assert_equal(100, REXML::Security.entity_expansion_limit)
doc = REXML::Document.new(xml)
assert_raise(RuntimeError) do
doc.root.children.first.value
end
assert_equal(101, doc.entity_expansion_count)
end
def test_general_entity_with_default_entity
xml = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "a">
<!ENTITY a2 "&a; &a;">
]>
<member>
&a;
&a2;
&lt;
</member>
EOF
REXML::Security.entity_expansion_limit = 4
doc = REXML::Document.new(xml)
assert_equal("\na\na a\n<\n", doc.root.children.first.value)
REXML::Security.entity_expansion_limit = 3
doc = REXML::Document.new(xml)
assert_raise(RuntimeError) do
doc.root.children.first.value
end
end
def test_parameter_entity_have_value
xml = <<EOF
<!DOCTYPE root [
<!ENTITY % a "BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.">
<!ENTITY % b "%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;">
@ -87,7 +140,18 @@ EOF
<cd></cd>
EOF
XML_WITH_NESTED_EMPTY_PARAMETER_ENTITY = <<EOF
assert_raise(REXML::ParseException) do
REXML::Document.new(xml)
end
REXML::Security.entity_expansion_limit = 100
assert_equal(100, REXML::Security.entity_expansion_limit)
assert_raise(REXML::ParseException) do
REXML::Document.new(xml)
end
end
def test_parameter_entity_empty_value
xml = <<EOF
<!DOCTYPE root [
<!ENTITY % a "">
<!ENTITY % b "%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;">
@ -101,77 +165,13 @@ EOF
<cd></cd>
EOF
XML_WITH_4_ENTITY_EXPANSION = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "a">
<!ENTITY a2 "&a; &a;">
]>
<member>
&a;
&a2;
&lt;
</member>
EOF
def test_general_entity_have_value
doc = REXML::Document.new(XML_WITH_NESTED_ENTITY)
assert_raise(RuntimeError) do
doc.root.children.first.value
end
REXML::Security.entity_expansion_limit = 100
assert_equal(100, REXML::Security.entity_expansion_limit)
doc = REXML::Document.new(XML_WITH_NESTED_ENTITY)
assert_raise(RuntimeError) do
doc.root.children.first.value
end
assert_equal(101, doc.entity_expansion_count)
end
def test_general_entity_empty_value
doc = REXML::Document.new(XML_WITH_NESTED_EMPTY_ENTITY)
assert_raise(RuntimeError) do
doc.root.children.first.value
end
REXML::Security.entity_expansion_limit = 100
assert_equal(100, REXML::Security.entity_expansion_limit)
doc = REXML::Document.new(XML_WITH_NESTED_EMPTY_ENTITY)
assert_raise(RuntimeError) do
doc.root.children.first.value
end
assert_equal(101, doc.entity_expansion_count)
end
def test_general_entity_with_default_entity
REXML::Security.entity_expansion_limit = 4
doc = REXML::Document.new(XML_WITH_4_ENTITY_EXPANSION)
assert_equal("\na\na a\n<\n", doc.root.children.first.value)
REXML::Security.entity_expansion_limit = 3
doc = REXML::Document.new(XML_WITH_4_ENTITY_EXPANSION)
assert_raise(RuntimeError) do
doc.root.children.first.value
end
end
def test_parameter_entity_have_value
assert_raise(REXML::ParseException) do
REXML::Document.new(XML_WITH_NESTED_PARAMETER_ENTITY)
REXML::Document.new(xml)
end
REXML::Security.entity_expansion_limit = 100
assert_equal(100, REXML::Security.entity_expansion_limit)
assert_raise(REXML::ParseException) do
REXML::Document.new(XML_WITH_NESTED_PARAMETER_ENTITY)
end
end
def test_parameter_entity_empty_value
assert_raise(REXML::ParseException) do
REXML::Document.new(XML_WITH_NESTED_EMPTY_PARAMETER_ENTITY)
end
REXML::Security.entity_expansion_limit = 100
assert_equal(100, REXML::Security.entity_expansion_limit)
assert_raise(REXML::ParseException) do
REXML::Document.new(XML_WITH_NESTED_EMPTY_PARAMETER_ENTITY)
REXML::Document.new(xml)
end
end
end