# # Testing OpenWFE # # John Mettraux at openwfe.org # # Tue Jan 2 13:14:37 JST 2007 # require 'test/unit' require 'openwfe/workitem' require 'openwfe/engine/engine' class SecTest < Test::Unit::TestCase #def setup #end #def teardown #end def test_sec_0 engine = OpenWFE::Engine.new engine.ac[:ruby_eval_allowed] = true def0 = \ ''' File.open("nada.txt") do |f| f.write("nada"); end ''' dotest engine, def0 assert( OpenWFE::grep( "Insecure operation - initialize", "logs/openwferu.log").size > 0) def1 = ''' class Object def my_name "toto" end end "stringobject".my_name ''' dotest engine, def1 assert_equal( 1, OpenWFE::grep( "undefined method `my_name' for \"stringobject\":String", "logs/openwferu.log").size) def2 = ''' ''' dotest(engine, def2) def3 = ''' self.ac[:ruby_eval_allowed] = false puts self.ac[:ruby_eval_allowed] ''' dotest(engine, def3) assert OpenWFE::grep( "evaluation of ruby code is not allowed", "logs/openwferu.log") engine.stop end def test_sec_1 value = nil engine = OpenWFE::Engine.new engine.register_participant(:toto) do |workitem| workitem.attributes.delete("___map_type") # # if the xmlencoder was used in previous, this field # might be set, removing it. value = "#{workitem.attributes.size}_#{workitem.f}" end def0 = ''' ''' engine.launch(OpenWFE::LaunchItem.new(def0)) sleep 0.200 assert_equal "3_", value engine.ac[:ruby_eval_allowed] = true engine.launch(OpenWFE::LaunchItem.new(def0)) sleep 0.200 assert_equal "3_35", value engine.stop end protected def dotest (engine, def_or_li) li = if def_or_li.is_a?(OpenWFE::LaunchItem) def_or_li else OpenWFE::LaunchItem.new(def_or_li) end engine.launch(li) sleep 0.250 end end