2016-08-06 12:03:25 -04:00
|
|
|
if RUBY_PLATFORM.include?("java")
|
|
|
|
require "abstract_unit"
|
|
|
|
require "active_support/xml_mini"
|
|
|
|
require "active_support/core_ext/hash/conversions"
|
2016-11-19 10:59:24 -05:00
|
|
|
require_relative "./common"
|
2009-03-15 06:32:29 -04:00
|
|
|
|
2012-01-05 20:12:46 -05:00
|
|
|
class JDOMEngineTest < ActiveSupport::TestCase
|
2016-08-06 12:03:25 -04:00
|
|
|
FILES_DIR = File.dirname(__FILE__) + "/../fixtures/xml"
|
2013-02-07 21:48:22 -05:00
|
|
|
|
2016-11-19 10:59:24 -05:00
|
|
|
include CommonXMLMiniAdapterTest
|
2011-05-23 23:46:50 -04:00
|
|
|
|
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
|
2016-08-06 12:03:25 -04:00
|
|
|
assert_equal "x", Hash.from_xml(attack_xml)["member"]
|
2013-02-07 21:48:22 -05:00
|
|
|
end
|
|
|
|
|
2013-03-19 07:52:20 -04:00
|
|
|
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
|
2016-08-06 12:03:25 -04:00
|
|
|
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
|
2016-08-06 12:03:25 -04:00
|
|
|
assert_equal "x", Hash.from_xml(attack_xml)["member"]
|
2013-02-07 21:48:22 -05:00
|
|
|
end
|
|
|
|
|
2016-11-19 10:59:24 -05:00
|
|
|
private
|
2009-03-15 06:32:29 -04:00
|
|
|
|
2016-11-19 10:59:24 -05:00
|
|
|
def adapter_name
|
|
|
|
"JDOM"
|
2011-05-23 23:46:50 -04:00
|
|
|
end
|
2009-03-15 06:32:29 -04:00
|
|
|
|
2016-11-19 10:59:24 -05:00
|
|
|
def expansion_attack_error
|
|
|
|
Java::OrgXmlSax::SAXParseException
|
2011-05-23 23:46:50 -04:00
|
|
|
end
|
2009-03-15 06:32:29 -04:00
|
|
|
end
|
|
|
|
end
|