Skip to content

Commit

Permalink
[api] Rework commit c2de991, cleaner solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
saschpe committed Nov 11, 2011
1 parent a62c3f9 commit 8223912
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
12 changes: 4 additions & 8 deletions src/api/app/controllers/application_controller.rb
Expand Up @@ -27,7 +27,10 @@ class ApplicationController < ActionController::Base
helper RbacHelper


before_filter :validate_xml, :add_api_version
before_filter :validate_xml_request, :add_api_version
if defined?( RESPONSE_SCHEMA_VALIDATION ) && RESPONSE_SCHEMA_VALIDATION == true
after_filter :validate_xml_response
end

if Rails.env.test?
before_filter :start_test_backend
Expand Down Expand Up @@ -67,13 +70,6 @@ def start_test_backend
hide_action :start_test_backend

protected
def validate_xml
validate_xml_request
if defined?( RESPONSE_SCHEMA_VALIDATION ) && RESPONSE_SCHEMA_VALIDATION == true && ['*/*', 'xml'].include?(request.format)
validate_xml_response
end
end

def set_current_user
User.current = nil
User.currentID = nil
Expand Down
10 changes: 5 additions & 5 deletions src/api/lib/opensuse/validator.rb
Expand Up @@ -48,11 +48,11 @@ def validate_xml_request

# This method should be called in the ApplicationController of your Rails app.
def validate_xml_response
opt = params()
opt[:method] = request.method.to_s
opt[:type] = "response"
logger.debug "Validate XML response: #{response}"
if response.status.to_s == "200 OK"
if ['*/*', 'xml'].include?(request.format) && response.status.to_s == "200 OK"
opt = params()
opt[:method] = request.method.to_s
opt[:type] = "response"
logger.debug "Validate XML response: #{response}"
Suse::Validator.validate(opt, response.body.to_s)
end
end
Expand Down

0 comments on commit 8223912

Please sign in to comment.