Skip to content

Commit

Permalink
[api] make sure we validate the XML response if configured
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Apr 16, 2012
1 parent 2dd17d7 commit 0c6739e
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/api/app/controllers/application_controller.rb
Expand Up @@ -33,7 +33,7 @@ class ApplicationController < ActionController::Base
@http_user = nil

before_filter :validate_xml_request, :add_api_version
if defined?( RESPONSE_SCHEMA_VALIDATION ) && RESPONSE_SCHEMA_VALIDATION == true
if CONFIG['response_schema_validation'] == true
after_filter :validate_xml_response
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/config/environments/development.rb
Expand Up @@ -69,7 +69,7 @@
CONFIG['extended_backend_log'] = true
YMP_URL='http://software.opensuse.org/ymp'

RESPONSE_SCHEMA_VALIDATION = true
CONFIG['response_schema_validation'] = true

require 'socket'
fname = "#{Rails.root}/config/environments/development.#{Socket.gethostname}.rb"
Expand Down
2 changes: 1 addition & 1 deletion src/api/config/environments/production.rb
Expand Up @@ -127,7 +127,7 @@
#end

# disabled on production for performance reasons
# RESPONSE_SCHEMA_VALIDATION = true
# CONFIG['response_schema_validation'] = true

#require 'memory_debugger'
# dumps the objects after every request
Expand Down
2 changes: 1 addition & 1 deletion src/api/config/environments/production_test.rb
Expand Up @@ -48,4 +48,4 @@
hermesconf.dbname = 'hermes'
end

RESPONSE_SCHEMA_VALIDATION = true
CONFIG['response_schema_validation'] = true
2 changes: 1 addition & 1 deletion src/api/config/environments/stage.rb
Expand Up @@ -40,4 +40,4 @@

ActionController::AbstractRequest.relative_url_root = "/stage"

RESPONSE_SCHEMA_VALIDATION = true
CONFIG['response_schema_validation'] = true
2 changes: 1 addition & 1 deletion src/api/config/environments/test.rb
Expand Up @@ -47,5 +47,5 @@
# Max number of times to attempt to contact the LDAP servers
MAX_LDAP_ATTEMPTS = 10

RESPONSE_SCHEMA_VALIDATION = true
CONFIG['response_schema_validation'] = true

3 changes: 3 additions & 0 deletions src/api/config/options.yml.example
Expand Up @@ -34,3 +34,6 @@ new_user_registration: allow
# Minimum count of rating votes a project/package needs to # be taken in account
# for global statistics:
min_votes_for_rating: 3

# Set to true to verify XML reponses comply to the schema
response_schema_validation: false
2 changes: 1 addition & 1 deletion src/api/lib/opensuse/validator.rb
Expand Up @@ -49,7 +49,7 @@ def validate_xml_request

# This method should be called in the ApplicationController of your Rails app.
def validate_xml_response
if request.format != "json" && response.status.to_s == "200 OK" && response.headers['Content-Type'] !~ /.*\/json/i
if request.format != "json" && response.status.to_s[0..2] == "200" && response.headers['Content-Type'] !~ /.*\/json/i && response.headers["Content-Disposition"] != "attachment"
opt = params()
opt[:method] = request.method.to_s
opt[:type] = "response"
Expand Down

0 comments on commit 0c6739e

Please sign in to comment.