Skip to content

Commit

Permalink
Non-GET requests that would usually non-ssl-redirect will now respond…
Browse files Browse the repository at this point in the history
… with HTTP status 426

Conflicts:
	core/spec/lib/spree/core/controller_helpers/ssl_spec.rb
  • Loading branch information
radar committed Oct 11, 2013
1 parent 9f64227 commit c4a1d53
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,8 @@ en:
special_instructions: Special Instructions
split: Split
spree_gateway_error_flash_for_checkout: There was a problem with your payment information. Please check your information and try again.
ssl:
change_protocol: "Please switch to using HTTP (rather than HTTPS) and retry this request."
start: Start
state: State
state_based: State Based
Expand Down
20 changes: 12 additions & 8 deletions core/lib/spree/core/controller_helpers/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ def ssl_allowed?
# * <tt>host</tt> - Redirect to a different host name
def force_non_ssl_redirect(host = nil)
if request.ssl? && !ssl_allowed?
redirect_options = {
:protocol => 'http://',
:host => host || request.host,
:path => request.fullpath,
}
flash.keep if respond_to?(:flash)
insecure_url = ActionDispatch::Http::URL.url_for(redirect_options)
redirect_to insecure_url, :status => :moved_permanently
if request.get?
redirect_options = {
:protocol => 'http://',
:host => host || request.host,
:path => request.fullpath,
}
flash.keep if respond_to?(:flash)
insecure_url = ActionDispatch::Http::URL.url_for(redirect_options)
redirect_to insecure_url, :status => :moved_permanently
else
render :text => Spree.t(:change_protocol, :scope => :ssl), :status => :upgrade_required
end
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions core/spec/lib/spree/core/controller_helpers/ssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
controller do
include Spree::Core::ControllerHelpers::SSL
def index; render text: 'index'; end
def create; end
def self.ssl_supported?; true; end
end

Expand Down Expand Up @@ -34,6 +35,14 @@ def self.ssl_supported?; true; end
controller(described_class){ }
specify{ get(:index).should be_redirect }
end
context 'using a post returns a HTTP status 426' do
controller(described_class){ }
specify do
post(:create)
response.body.should == "Please switch to using HTTP (rather than HTTPS) and retry this request."
response.status.should == 426
end
end
end

describe 'redirect to https' do
Expand Down

0 comments on commit c4a1d53

Please sign in to comment.