diff --git a/app/controllers/application.rb b/app/controllers/application.rb index dbff29b..998a009 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -38,6 +38,7 @@ class ApplicationController < ActionController::Base redirect_to_ssl end def redirect_to_ssl + return true if environment.disable_ssl redirect_to(params.merge(:protocol => 'https://')) end diff --git a/app/models/environment.rb b/app/models/environment.rb index 65c31f7..74195c6 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -283,6 +283,14 @@ class Environment < ActiveRecord::Base result end + def disable_ssl + settings[:disable_ssl] + end + + def disable_ssl=(value) + settings[:disable_ssl] = value + end + def to_s self.name || '?' end diff --git a/db/schema.rb b/db/schema.rb index 6830403..335b547 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -77,8 +77,8 @@ ActiveRecord::Schema.define(:version => 55) do t.boolean "virtual", :default => false end - add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" + add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" create_table "blocks", :force => true do |t| t.string "title" @@ -118,8 +118,8 @@ ActiveRecord::Schema.define(:version => 55) do t.boolean "virtual", :default => false end - add_index "categories_profiles", ["category_id"], :name => "index_categories_profiles_on_category_id" add_index "categories_profiles", ["profile_id"], :name => "index_categories_profiles_on_profile_id" + add_index "categories_profiles", ["category_id"], :name => "index_categories_profiles_on_category_id" create_table "comments", :force => true do |t| t.string "title" @@ -186,8 +186,8 @@ ActiveRecord::Schema.define(:version => 55) do t.datetime "updated_at" end - add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id" add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id" + add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id" create_table "products", :force => true do |t| t.integer "enterprise_id" @@ -258,8 +258,8 @@ ActiveRecord::Schema.define(:version => 55) do t.datetime "created_at" end - add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" + add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" create_table "tags", :force => true do |t| t.string "name" diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index c97f7e2..fd2201a 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -292,9 +292,17 @@ class ApplicationControllerTest < Test::Unit::TestCase end should 'add https protocols on redirect_to_ssl' do - @controller.expects(:params).returns(:x => '1', :y => '1') - @controller.expects(:redirect_to).with(:x => '1', :y => '1', :protocol => 'https://') - @controller.redirect_to_ssl + get :sslonly, :x => '1', :y => '1' + assert_redirected_to :x => '1', :y => '1', :protocol => 'https://' + end + + should 'not force ssl when ssl is disabled' do + env = Environment.default + env.expects(:disable_ssl).returns(true) + @controller.stubs(:environment).returns(env) + @request.expects(:ssl?).returns(false).at_least_once + get :sslonly + assert_response :success end end diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 8e0cb88..225ef9f 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -409,4 +409,14 @@ class EnvironmentTest < Test::Unit::TestCase assert !e.person_template.public? end + should 'not disable ssl by default' do + e = Environment.new + assert !e.disable_ssl + end + + should 'be able to disable ssl' do + e = Environment.new(:disable_ssl => true) + assert_equal true, e.disable_ssl + end + end -- libgit2 0.21.2