1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/test/xml_mini/jdom_engine_test.rb

54 lines
1.4 KiB
Ruby
Raw Normal View History

if RUBY_PLATFORM.include?("java")
require "abstract_unit"
require "active_support/xml_mini"
require "active_support/core_ext/hash/conversions"
require_relative "./common"
2012-01-05 20:12:46 -05:00
class JDOMEngineTest < ActiveSupport::TestCase
FILES_DIR = File.dirname(__FILE__) + "/../fixtures/xml"
2013-02-07 21:48:22 -05:00
include CommonXMLMiniAdapterTest
2013-02-07 21:48:22 -05:00
def test_not_allowed_to_expand_entities_to_files
attack_xml = <<-EOT
<!DOCTYPE member [
<!ENTITY a SYSTEM "file://#{FILES_DIR}/jdom_include.txt">
]>
<member>x&a;</member>
EOT
assert_equal "x", Hash.from_xml(attack_xml)["member"]
2013-02-07 21:48:22 -05:00
end
def test_not_allowed_to_expand_parameter_entities_to_files
2013-02-07 21:48:22 -05:00
attack_xml = <<-EOT
<!DOCTYPE member [
<!ENTITY % b SYSTEM "file://#{FILES_DIR}/jdom_entities.txt">
%b;
]>
<member>x&a;</member>
EOT
assert_raise Java::OrgXmlSax::SAXParseException do
assert_equal "x", Hash.from_xml(attack_xml)["member"]
2013-02-07 21:48:22 -05:00
end
end
def test_not_allowed_to_load_external_doctypes
attack_xml = <<-EOT
<!DOCTYPE member SYSTEM "file://#{FILES_DIR}/jdom_doctype.dtd">
<member>x&a;</member>
EOT
assert_equal "x", Hash.from_xml(attack_xml)["member"]
2013-02-07 21:48:22 -05:00
end
private
def adapter_name
"JDOM"
end
def expansion_attack_error
Java::OrgXmlSax::SAXParseException
end
end
end