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 38 redirect_to_ssl
39 39 end
40 40 def redirect_to_ssl
  41 + return true if environment.disable_ssl
41 42 redirect_to(params.merge(:protocol => 'https://'))
42 43 end
43 44  
... ...
app/models/environment.rb
... ... @@ -283,6 +283,14 @@ class Environment < ActiveRecord::Base
283 283 result
284 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 294 def to_s
287 295 self.name || '?'
288 296 end
... ...
db/schema.rb
... ... @@ -77,8 +77,8 @@ ActiveRecord::Schema.define(:version => 55) do
77 77 t.boolean "virtual", :default => false
78 78 end
79 79  
80   - add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id"
81 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 83 create_table "blocks", :force => true do |t|
84 84 t.string "title"
... ... @@ -118,8 +118,8 @@ ActiveRecord::Schema.define(:version => 55) do
118 118 t.boolean "virtual", :default => false
119 119 end
120 120  
121   - add_index "categories_profiles", ["category_id"], :name => "index_categories_profiles_on_category_id"
122 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 124 create_table "comments", :force => true do |t|
125 125 t.string "title"
... ... @@ -186,8 +186,8 @@ ActiveRecord::Schema.define(:version => 55) do
186 186 t.datetime "updated_at"
187 187 end
188 188  
189   - add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id"
190 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 192 create_table "products", :force => true do |t|
193 193 t.integer "enterprise_id"
... ... @@ -258,8 +258,8 @@ ActiveRecord::Schema.define(:version => 55) do
258 258 t.datetime "created_at"
259 259 end
260 260  
261   - add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type"
262 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 264 create_table "tags", :force => true do |t|
265 265 t.string "name"
... ...
test/functional/application_controller_test.rb
... ... @@ -292,9 +292,17 @@ class ApplicationControllerTest < Test::Unit::TestCase
292 292 end
293 293  
294 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 306 end
299 307  
300 308 end
... ...
test/unit/environment_test.rb
... ... @@ -409,4 +409,14 @@ class EnvironmentTest < Test::Unit::TestCase
409 409 assert !e.person_template.public?
410 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 422 end
... ...