Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7077: soap_action_header_patch.diff

File soap_action_header_patch.diff, 7.0 kB (added by zackchandler, 2 years ago)
  • actionwebservice/test/dispatcher_action_controller_soap_test.rb

    old new  
    8585    assert_equal "T25lIFdvcmxkIENhZsOp", retval.data.to_s 
    8686  end 
    8787 
     88  def test_require_soap_action_header 
     89    # no HTTP_SOAPACTION header will raise error by default 
     90    assert_raises(ActionWebService::Protocol::ProtocolError) do 
     91      do_method_call_with_soap_action_options(@direct_controller, :none, true, 'Add', 1, 2) 
     92    end 
     93     
     94    # no HTTP_SOAPACTION header is ok if :require_soap_action_header option is set to false 
     95    assert_equal 3, do_method_call_with_soap_action_options(@direct_controller, :none, false, 'Add', 1, 2) 
     96  end 
     97   
    8898  protected 
    8999    def exception_message(soap_fault_exception) 
    90100      soap_fault_exception.detail.cause.message 
     
    134144      wsdl = controller.process(test_request, test_response).body 
    135145      ensure_valid_wsdl(controller, wsdl, DispatcherTest::WsdlNamespace) 
    136146    end 
     147     
     148    def do_method_call_with_soap_action_options(container, soap_action_header, require_header, public_method_name, *params) 
     149      api = container.class.web_service_api 
     150      old_require_soap_action_header = api.require_soap_action_header 
     151      api.require_soap_action_header = require_header 
     152 
     153      method = api.public_api_method_instance(public_method_name) 
     154      protocol.register_api(api) 
     155      body = protocol.encode_request(public_method_name, params.dup, method.expects)     
     156      ap_request = protocol.encode_action_pack_request(service_name(container), public_method_name,  
     157                                                       body, :request_class => ActionController::TestRequest) 
     158      ap_request.env.delete('HTTP_SOAPACTION') if soap_action_header == :none 
     159      ap_response = ActionController::TestResponse.new     
     160      container.process(ap_request, ap_response) 
     161      public_method_name, return_value = protocol.decode_response(ap_response.body) 
     162     
     163      api.require_soap_action_header = old_require_soap_action_header       
     164      return_value 
     165    end 
     166     
    137167end 
  • actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb

    old new  
    4343            end 
    4444            exception = nil 
    4545            begin 
    46               ws_request = discover_web_service_request(request) 
     46              api = self.class.web_service_api 
     47              options = {} 
     48              options[:require_soap_action_header] = api ? api.require_soap_action_header : true 
     49              ws_request = discover_web_service_request(request, options) 
    4750            rescue Exception => e 
    4851              exception = e 
    4952            end 
  • actionwebservice/lib/action_web_service/protocol/abstract.rb

    old new  
    77      def setup(controller) 
    88      end 
    99 
    10       def decode_action_pack_request(action_pack_request
     10      def decode_action_pack_request(action_pack_request, options={}
    1111      end 
    1212 
    1313      def encode_action_pack_request(service_name, public_method_name, raw_body, options={}) 
  • actionwebservice/lib/action_web_service/protocol/soap_protocol.rb

    old new  
    3434          SoapProtocol.new(controller.wsdl_namespace) 
    3535        end 
    3636 
    37         def decode_action_pack_request(action_pack_request) 
    38           return nil unless soap_action = has_valid_soap_action?(action_pack_request) 
     37        def decode_action_pack_request(action_pack_request, options={}) 
     38          soap_action = has_valid_soap_action?(action_pack_request) 
     39          return nil if soap_action.nil? && options[:require_soap_action_header] != false 
    3940          service_name = action_pack_request.parameters['action'] 
    4041          input_encoding = parse_charset(action_pack_request.env['HTTP_CONTENT_TYPE']) 
    4142          protocol_options = {  
  • actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb

    old new  
    3737          XmlRpcProtocol.new 
    3838        end 
    3939 
    40         def decode_action_pack_request(action_pack_request
     40        def decode_action_pack_request(action_pack_request, options={}
    4141          service_name = action_pack_request.parameters['action'] 
    4242          decode_request(action_pack_request.raw_post, service_name) 
    4343        end 
  • actionwebservice/lib/action_web_service/protocol/discovery.rb

    old new  
    1414 
    1515      module InstanceMethods # :nodoc: 
    1616        private 
    17           def discover_web_service_request(action_pack_request
     17          def discover_web_service_request(action_pack_request, options={}
    1818            (self.class.read_inheritable_attribute("web_service_protocols") || []).each do |protocol| 
    1919              protocol = protocol.create(self) 
    20               request = protocol.decode_action_pack_request(action_pack_request
     20              request = protocol.decode_action_pack_request(action_pack_request, options
    2121              return request unless request.nil? 
    2222            end 
    2323            nil 
  • actionwebservice/lib/action_web_service/api.rb

    old new  
    2121      # Whether to transform the public API method names into camel-cased names  
    2222      class_inheritable_option :inflect_names, true 
    2323 
     24      # By default an HTTP_SOAPACTION header must be set for SOAP messages to be parsed. 
     25      # Setting this option to false can help handle clients that do not set this header. 
     26      class_inheritable_option :require_soap_action_header, true 
     27       
    2428      # Whether to allow ActiveRecord::Base models in <tt>:expects</tt>. 
    2529      # The default is +false+; you should be aware of the security implications 
    2630      # of allowing this, and ensure that you don't allow remote callers to