summaryrefslogtreecommitdiff
path: root/test/rexml
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-15 11:45:27 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-15 11:45:27 +0000
commita38971c595a6a5ee6f4cf0b2c066311a4694a59c (patch)
tree61e3ae28de7be6eb616be541fbd679edeaba79ec /test/rexml
parenta5406b873c7519d8bfb5982e7905e71977b846a9 (diff)
* 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
Diffstat (limited to 'test/rexml')
-rw-r--r--test/rexml/test_document.rb130
1 files changed, 65 insertions, 65 deletions
diff --git a/test/rexml/test_document.rb b/test/rexml/test_document.rb
index 8f37b2f..f4e78c9 100644
--- a/test/rexml/test_document.rb
+++ b/test/rexml/test_document.rb
@@ -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,35 +88,21 @@ EOF
</member>
EOF
- XML_WITH_NESTED_PARAMETER_ENTITY = <<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;">
- <!ENTITY % c "%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;">
- <!ENTITY % d "%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;">
- <!ENTITY % e "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;">
- <!ENTITY % f "%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;">
- <!ENTITY % g "%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;">
- <!ENTITY test "test %g;">
-]>
-<cd></cd>
-EOF
-
- XML_WITH_NESTED_EMPTY_PARAMETER_ENTITY = <<EOF
-<!DOCTYPE root [
- <!ENTITY % a "">
- <!ENTITY % b "%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;">
- <!ENTITY % c "%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;">
- <!ENTITY % d "%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;">
- <!ENTITY % e "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;">
- <!ENTITY % f "%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;">
- <!ENTITY % g "%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;">
- <!ENTITY test "test %g;">
-]>
-<cd></cd>
-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
- XML_WITH_4_ENTITY_EXPANSION = <<EOF
+ def test_general_entity_with_default_entity
+ xml = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "a">
@@ -114,64 +115,63 @@ EOF
</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)
+ 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_WITH_4_ENTITY_EXPANSION)
+ 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;">
+ <!ENTITY % c "%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;">
+ <!ENTITY % d "%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;">
+ <!ENTITY % e "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;">
+ <!ENTITY % f "%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;">
+ <!ENTITY % g "%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;">
+ <!ENTITY test "test %g;">
+]>
+<cd></cd>
+EOF
+
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)
+ 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;">
+ <!ENTITY % c "%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;">
+ <!ENTITY % d "%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;">
+ <!ENTITY % e "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;">
+ <!ENTITY % f "%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;">
+ <!ENTITY % g "%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;">
+ <!ENTITY test "test %g;">
+]>
+<cd></cd>
+EOF
+
assert_raise(REXML::ParseException) do
- REXML::Document.new(XML_WITH_NESTED_EMPTY_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_EMPTY_PARAMETER_ENTITY)
+ REXML::Document.new(xml)
end
end
end