Commit 972acdcb85dfb38c088e75f089b5df6c7682878b

Authored by AntonioTerceiro
1 parent c1d3f1a0

ActionItem680: being able to disable ssl

To disable SSL, just set disable_ssl = true in the environment. Like
this:

Environment.default.update_attributes(:disable_ssl => true)

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/branches/0.11.x@2511 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/application.rb
@@ -38,6 +38,7 @@ class ApplicationController < ActionController::Base @@ -38,6 +38,7 @@ class ApplicationController < ActionController::Base
38 redirect_to_ssl 38 redirect_to_ssl
39 end 39 end
40 def redirect_to_ssl 40 def redirect_to_ssl
  41 + return true if environment.disable_ssl
41 redirect_to(params.merge(:protocol => 'https://')) 42 redirect_to(params.merge(:protocol => 'https://'))
42 end 43 end
43 44
app/models/environment.rb
@@ -283,6 +283,14 @@ class Environment < ActiveRecord::Base @@ -283,6 +283,14 @@ class Environment < ActiveRecord::Base
283 result 283 result
284 end 284 end
285 285
  286 + def disable_ssl
  287 + settings[:disable_ssl]
  288 + end
  289 +
  290 + def disable_ssl=(value)
  291 + settings[:disable_ssl] = value
  292 + end
  293 +
286 def to_s 294 def to_s
287 self.name || '?' 295 self.name || '?'
288 end 296 end
@@ -77,8 +77,8 @@ ActiveRecord::Schema.define(:version => 55) do @@ -77,8 +77,8 @@ ActiveRecord::Schema.define(:version => 55) do
77 t.boolean "virtual", :default => false 77 t.boolean "virtual", :default => false
78 end 78 end
79 79
80 - add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id"  
81 add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" 80 add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id"
  81 + add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id"
82 82
83 create_table "blocks", :force => true do |t| 83 create_table "blocks", :force => true do |t|
84 t.string "title" 84 t.string "title"
@@ -118,8 +118,8 @@ ActiveRecord::Schema.define(:version => 55) do @@ -118,8 +118,8 @@ ActiveRecord::Schema.define(:version => 55) do
118 t.boolean "virtual", :default => false 118 t.boolean "virtual", :default => false
119 end 119 end
120 120
121 - add_index "categories_profiles", ["category_id"], :name => "index_categories_profiles_on_category_id"  
122 add_index "categories_profiles", ["profile_id"], :name => "index_categories_profiles_on_profile_id" 121 add_index "categories_profiles", ["profile_id"], :name => "index_categories_profiles_on_profile_id"
  122 + add_index "categories_profiles", ["category_id"], :name => "index_categories_profiles_on_category_id"
123 123
124 create_table "comments", :force => true do |t| 124 create_table "comments", :force => true do |t|
125 t.string "title" 125 t.string "title"
@@ -186,8 +186,8 @@ ActiveRecord::Schema.define(:version => 55) do @@ -186,8 +186,8 @@ ActiveRecord::Schema.define(:version => 55) do
186 t.datetime "updated_at" 186 t.datetime "updated_at"
187 end 187 end
188 188
189 - add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id"  
190 add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id" 189 add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id"
  190 + add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id"
191 191
192 create_table "products", :force => true do |t| 192 create_table "products", :force => true do |t|
193 t.integer "enterprise_id" 193 t.integer "enterprise_id"
@@ -258,8 +258,8 @@ ActiveRecord::Schema.define(:version => 55) do @@ -258,8 +258,8 @@ ActiveRecord::Schema.define(:version => 55) do
258 t.datetime "created_at" 258 t.datetime "created_at"
259 end 259 end
260 260
261 - add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type"  
262 add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" 261 add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
  262 + add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type"
263 263
264 create_table "tags", :force => true do |t| 264 create_table "tags", :force => true do |t|
265 t.string "name" 265 t.string "name"
test/functional/application_controller_test.rb
@@ -292,9 +292,17 @@ class ApplicationControllerTest < Test::Unit::TestCase @@ -292,9 +292,17 @@ class ApplicationControllerTest < Test::Unit::TestCase
292 end 292 end
293 293
294 should 'add https protocols on redirect_to_ssl' do 294 should 'add https protocols on redirect_to_ssl' do
295 - @controller.expects(:params).returns(:x => '1', :y => '1')  
296 - @controller.expects(:redirect_to).with(:x => '1', :y => '1', :protocol => 'https://')  
297 - @controller.redirect_to_ssl 295 + get :sslonly, :x => '1', :y => '1'
  296 + assert_redirected_to :x => '1', :y => '1', :protocol => 'https://'
  297 + end
  298 +
  299 + should 'not force ssl when ssl is disabled' do
  300 + env = Environment.default
  301 + env.expects(:disable_ssl).returns(true)
  302 + @controller.stubs(:environment).returns(env)
  303 + @request.expects(:ssl?).returns(false).at_least_once
  304 + get :sslonly
  305 + assert_response :success
298 end 306 end
299 307
300 end 308 end
test/unit/environment_test.rb
@@ -409,4 +409,14 @@ class EnvironmentTest < Test::Unit::TestCase @@ -409,4 +409,14 @@ class EnvironmentTest < Test::Unit::TestCase
409 assert !e.person_template.public? 409 assert !e.person_template.public?
410 end 410 end
411 411
  412 + should 'not disable ssl by default' do
  413 + e = Environment.new
  414 + assert !e.disable_ssl
  415 + end
  416 +
  417 + should 'be able to disable ssl' do
  418 + e = Environment.new(:disable_ssl => true)
  419 + assert_equal true, e.disable_ssl
  420 + end
  421 +
412 end 422 end