Commit 2c2f7890bff7bf277381b5f4b067fc389c48ed25
1 parent
d240b511
Exists in
master
and in
22 other branches
ActionItem438: implemented SSL requirements
Changes: * Implemented require_ssl and refuse_ssl in ApplicationController * Changed AccountController to require SSL + pointing to HTTPS in login forms * Changed PublicController to refuse SSL, and fixed all controllers in app/controllers/public to inherit from it (with some exceptions). * Changed MyProfileController to require SSL Side-effects: * Some controllers had been changed in an unappropriated way for the new SSL requirement. * Some tests changed to reflect the new SSL requirements. * Needed to tweak content_viewer controller to deal with SSL URL's: + Fixed detection of user coming from public view that was broke by the SSL thing. * adapted enterprise_registration tests git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2458 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
39 changed files
with
215 additions
and
17 deletions
Show diff stats
app/controllers/application.rb
@@ -30,6 +30,22 @@ class ApplicationController < ActionController::Base | @@ -30,6 +30,22 @@ class ApplicationController < ActionController::Base | ||
30 | include AuthenticatedSystem | 30 | include AuthenticatedSystem |
31 | include PermissionCheck | 31 | include PermissionCheck |
32 | 32 | ||
33 | + def self.require_ssl(*options) | ||
34 | + before_filter :check_ssl, *options | ||
35 | + end | ||
36 | + def check_ssl | ||
37 | + return true if (request.ssl? || ENV['RAILS_ENV'] == 'development') | ||
38 | + redirect_to :protocol => 'https://' | ||
39 | + end | ||
40 | + | ||
41 | + def self.refuse_ssl(*options) | ||
42 | + before_filter :avoid_ssl, *options | ||
43 | + end | ||
44 | + def avoid_ssl | ||
45 | + return true if (!request.ssl? || ENV['RAILS_ENV'] == 'development') | ||
46 | + redirect_to :protocol => 'http://' | ||
47 | + end | ||
48 | + | ||
33 | before_init_gettext :maybe_save_locale | 49 | before_init_gettext :maybe_save_locale |
34 | after_init_gettext :check_locale | 50 | after_init_gettext :check_locale |
35 | init_gettext 'noosfero' | 51 | init_gettext 'noosfero' |
app/controllers/my_profile/cms_controller.rb
@@ -165,7 +165,7 @@ class CmsController < MyProfileController | @@ -165,7 +165,7 @@ class CmsController < MyProfileController | ||
165 | 165 | ||
166 | def record_coming_from_public_view | 166 | def record_coming_from_public_view |
167 | referer = request.referer | 167 | referer = request.referer |
168 | - if (referer == url_for(@article.url)) || (@article == @profile.home_page && referer == url_for(@profile.url)) | 168 | + if (maybe_ssl(url_for(@article.url)).include?(referer)) || (@article == @profile.home_page && maybe_ssl(url_for(@profile.url)).include?(referer)) |
169 | @back_to = 'public_view' | 169 | @back_to = 'public_view' |
170 | @back_url = @article.url | 170 | @back_url = @article.url |
171 | end | 171 | end |
@@ -173,11 +173,15 @@ class CmsController < MyProfileController | @@ -173,11 +173,15 @@ class CmsController < MyProfileController | ||
173 | 173 | ||
174 | def record_creating_from_public_view | 174 | def record_creating_from_public_view |
175 | referer = request.referer | 175 | referer = request.referer |
176 | - if (referer =~ Regexp.new("^#{url_for(profile.url)}")) | 176 | + if (referer =~ Regexp.new("^#{(url_for(profile.url).sub('https:', 'https?:'))}")) |
177 | @back_to = 'public_view' | 177 | @back_to = 'public_view' |
178 | @back_url = referer | 178 | @back_url = referer |
179 | end | 179 | end |
180 | end | 180 | end |
181 | 181 | ||
182 | + def maybe_ssl(url) | ||
183 | + [url, url.sub('https:', 'http:')] | ||
184 | + end | ||
185 | + | ||
182 | end | 186 | end |
183 | 187 |
app/controllers/my_profile_controller.rb
@@ -2,6 +2,8 @@ class MyProfileController < ApplicationController | @@ -2,6 +2,8 @@ class MyProfileController < ApplicationController | ||
2 | 2 | ||
3 | needs_profile | 3 | needs_profile |
4 | 4 | ||
5 | + require_ssl | ||
6 | + | ||
5 | # declares that the controller needs an specific type of profile. Example: | 7 | # declares that the controller needs an specific type of profile. Example: |
6 | # | 8 | # |
7 | # class PersonDetailControlles < ProfileAdminController | 9 | # class PersonDetailControlles < ProfileAdminController |
app/controllers/public/account_controller.rb
1 | -class AccountController < PublicController | 1 | +class AccountController < ApplicationController |
2 | 2 | ||
3 | inverse_captcha :field => 'e_mail' | 3 | inverse_captcha :field => 'e_mail' |
4 | 4 | ||
5 | + require_ssl :except => [ :login_popup ] | ||
6 | + | ||
5 | # say something nice, you goof! something sweet. | 7 | # say something nice, you goof! something sweet. |
6 | def index | 8 | def index |
7 | unless logged_in? | 9 | unless logged_in? |
app/controllers/public/catalog_controller.rb
app/controllers/public/content_viewer_controller.rb
1 | -class ContentViewerController < PublicController | 1 | +class ContentViewerController < ApplicationController |
2 | 2 | ||
3 | needs_profile | 3 | needs_profile |
4 | 4 | ||
@@ -28,6 +28,11 @@ class ContentViewerController < PublicController | @@ -28,6 +28,11 @@ class ContentViewerController < PublicController | ||
28 | end | 28 | end |
29 | end | 29 | end |
30 | 30 | ||
31 | + if !@page.public? && !request.ssl? | ||
32 | + redirect_to :protocol => 'https://' | ||
33 | + return | ||
34 | + end | ||
35 | + | ||
31 | if !@page.display_to?(user) | 36 | if !@page.display_to?(user) |
32 | # FIXME find a nice "access denied" layout | 37 | # FIXME find a nice "access denied" layout |
33 | render :action => 'access_denied', :status => 403, :layout => false | 38 | render :action => 'access_denied', :status => 403, :layout => false |
app/controllers/public/enterprise_registration_controller.rb
app/controllers/public/profile_controller.rb
app/controllers/public/search_controller.rb
app/controllers/public/tag_controller.rb
app/controllers/public_controller.rb
app/helpers/application_helper.rb
@@ -707,4 +707,10 @@ module ApplicationHelper | @@ -707,4 +707,10 @@ module ApplicationHelper | ||
707 | end | 707 | end |
708 | end | 708 | end |
709 | 709 | ||
710 | + def login_url | ||
711 | + options = { :controller => 'account', :action => 'login' } | ||
712 | + options.merge!(:protocol => 'https://', :host => request.host) unless ENV['RAILS_ENV'] == 'development' | ||
713 | + url_for(options) | ||
714 | + end | ||
715 | + | ||
710 | end | 716 | end |
app/views/account/_login_form.rhtml
1 | <% labelled_form_for :user, @user, | 1 | <% labelled_form_for :user, @user, |
2 | - :url => { :controller => 'account', :action => 'login' }, | 2 | + :url => login_url, |
3 | :html => { :help => _('If you are a registered user, enter your username and password to be authenticated.')+'<p/>'+_('To join on this environment, click on "<b>I want to be an user!</b>".')+'<p/>'+_('If you forgot your password, click on "<b>I forgot my password!</b>" link.') } do |f| %> | 3 | :html => { :help => _('If you are a registered user, enter your username and password to be authenticated.')+'<p/>'+_('To join on this environment, click on "<b>I want to be an user!</b>".')+'<p/>'+_('If you forgot your password, click on "<b>I forgot my password!</b>" link.') } do |f| %> |
4 | 4 | ||
5 | <%= f.text_field :login, | 5 | <%= f.text_field :login, |
app/views/account/login.rhtml
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | <% @user = User.new unless @user %> | 5 | <% @user = User.new unless @user %> |
6 | 6 | ||
7 | <% labelled_form_for :user, @user, | 7 | <% labelled_form_for :user, @user, |
8 | - :url => { :controller => 'account', :action => 'login' }, | 8 | + :url => login_url, |
9 | :html => { :help => _('If you are a registered user, enter your username and password to be authenticated.')+'<p/>'+_('To join on this environment, click on "<b>I want to be an user!</b>".')+'<p/>'+_('If you forgot your password, click on "<b>I forgot my password!</b>" link.') } do |f| %> | 9 | :html => { :help => _('If you are a registered user, enter your username and password to be authenticated.')+'<p/>'+_('To join on this environment, click on "<b>I want to be an user!</b>".')+'<p/>'+_('If you forgot your password, click on "<b>I forgot my password!</b>" link.') } do |f| %> |
10 | 10 | ||
11 | <%= f.text_field :login, | 11 | <%= f.text_field :login, |
app/views/account/login_block.rhtml
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | 11 | ||
12 | <% labelled_form_for :user, @user, | 12 | <% labelled_form_for :user, @user, |
13 | :html => { :help => _('If you are a registered user, enter your username and password to be authenticated.')+'<p/>'+_('To join on this environment, click on "<b>New user</b>".')+'<p/>'+_('If you forgot your password, click on "<b>I forgot my password!</b>" link.') }, | 13 | :html => { :help => _('If you are a registered user, enter your username and password to be authenticated.')+'<p/>'+_('To join on this environment, click on "<b>New user</b>".')+'<p/>'+_('If you forgot your password, click on "<b>I forgot my password!</b>" link.') }, |
14 | - :url => { :controller => 'account', :action => 'login' } do |f| %> | 14 | + :url => login_url do |f| %> |
15 | 15 | ||
16 | <%= f.text_field :login, | 16 | <%= f.text_field :login, |
17 | :help => _('Here goes the nickname that you give on the registration.'), | 17 | :help => _('Here goes the nickname that you give on the registration.'), |
test/functional/account_controller_test.rb
@@ -15,6 +15,8 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -15,6 +15,8 @@ class AccountControllerTest < Test::Unit::TestCase | ||
15 | @controller = AccountController.new | 15 | @controller = AccountController.new |
16 | @request = ActionController::TestRequest.new | 16 | @request = ActionController::TestRequest.new |
17 | @response = ActionController::TestResponse.new | 17 | @response = ActionController::TestResponse.new |
18 | + | ||
19 | + @request.stubs(:ssl?).returns(true) | ||
18 | end | 20 | end |
19 | 21 | ||
20 | def test_local_files_reference | 22 | def test_local_files_reference |
@@ -515,6 +517,29 @@ class AccountControllerTest < Test::Unit::TestCase | @@ -515,6 +517,29 @@ class AccountControllerTest < Test::Unit::TestCase | ||
515 | assert_equal 1, assigns(:user).person.boxes[0].blocks.size | 517 | assert_equal 1, assigns(:user).person.boxes[0].blocks.size |
516 | end | 518 | end |
517 | 519 | ||
520 | + should 'force ssl' do | ||
521 | + @request.expects(:ssl?).returns(false).at_least_once | ||
522 | + get :index | ||
523 | + assert_redirected_to :protocol => 'https://' | ||
524 | + end | ||
525 | + | ||
526 | + should 'alllow login_popup without SSL' do | ||
527 | + @request.expects(:ssl?).returns(false).at_least_once | ||
528 | + get :login_popup | ||
529 | + assert_response :success | ||
530 | + end | ||
531 | + | ||
532 | + should 'point to SSL URL in login popup' do | ||
533 | + get :login_popup | ||
534 | + assert_tag :tag => 'form', :attributes => { :action => /^https:\/\// } | ||
535 | + end | ||
536 | + | ||
537 | + should 'not point to SSL URL in login popup when in development mode' do | ||
538 | + ENV.expects(:[]).with('RAILS_ENV').returns('development').at_least_once | ||
539 | + get :login_popup | ||
540 | + assert_no_tag :tag => 'form', :attributes => { :action => /^https:\/\// } | ||
541 | + end | ||
542 | + | ||
518 | protected | 543 | protected |
519 | def create_user(options = {}, extra_options ={}) | 544 | def create_user(options = {}, extra_options ={}) |
520 | post :signup, { :user => { :login => 'quire', | 545 | post :signup, { :user => { :login => 'quire', |
test/functional/application_controller_test.rb
@@ -224,4 +224,52 @@ class ApplicationControllerTest < Test::Unit::TestCase | @@ -224,4 +224,52 @@ class ApplicationControllerTest < Test::Unit::TestCase | ||
224 | get :index | 224 | get :index |
225 | end | 225 | end |
226 | 226 | ||
227 | + should 'require ssl when told to' do | ||
228 | + @request.expects(:ssl?).returns(false).at_least_once | ||
229 | + get :sslonly | ||
230 | + assert_redirected_to :protocol => 'https://' | ||
231 | + end | ||
232 | + | ||
233 | + should 'not force ssl in development mode' do | ||
234 | + ENV.expects(:[]).with('RAILS_ENV').returns('development') | ||
235 | + @request.expects(:ssl?).returns(false).at_least_once | ||
236 | + get :sslonly | ||
237 | + assert_response :success | ||
238 | + end | ||
239 | + | ||
240 | + should 'not force ssl when not told to' do | ||
241 | + @request.expects(:ssl?).returns(false).at_least_once | ||
242 | + get :doesnt_need_ssl | ||
243 | + assert_response :success | ||
244 | + end | ||
245 | + | ||
246 | + should 'not force ssl when already in ssl' do | ||
247 | + @request.expects(:ssl?).returns(true).at_least_once | ||
248 | + get :sslonly | ||
249 | + assert_response :success | ||
250 | + end | ||
251 | + | ||
252 | + should 'refuse ssl when told to' do | ||
253 | + @request.expects(:ssl?).returns(true).at_least_once | ||
254 | + get :nossl | ||
255 | + assert_redirected_to :protocol => "http://" | ||
256 | + end | ||
257 | + | ||
258 | + should 'not refuse ssl when not told to' do | ||
259 | + @request.expects(:ssl?).returns(true).at_least_once | ||
260 | + get :doesnt_refuse_ssl | ||
261 | + assert_response :success | ||
262 | + end | ||
263 | + should 'not refuse ssl while in development mode' do | ||
264 | + ENV.expects(:[]).with('RAILS_ENV').returns('development') | ||
265 | + @request.expects(:ssl?).returns(true).at_least_once | ||
266 | + get :nossl | ||
267 | + assert_response :success | ||
268 | + end | ||
269 | + should 'not refuse ssl when not in ssl' do | ||
270 | + @request.expects(:ssl?).returns(false).at_least_once | ||
271 | + get :nossl | ||
272 | + assert_response :success | ||
273 | + end | ||
274 | + | ||
227 | end | 275 | end |
test/functional/cms_controller_test.rb
@@ -11,6 +11,7 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -11,6 +11,7 @@ class CmsControllerTest < Test::Unit::TestCase | ||
11 | def setup | 11 | def setup |
12 | @controller = CmsController.new | 12 | @controller = CmsController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
14 | + @request.stubs(:ssl?).returns(true) | ||
14 | @response = ActionController::TestResponse.new | 15 | @response = ActionController::TestResponse.new |
15 | 16 | ||
16 | @profile = create_user_with_permission('testinguser', 'post_content') | 17 | @profile = create_user_with_permission('testinguser', 'post_content') |
@@ -513,14 +514,14 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -513,14 +514,14 @@ class CmsControllerTest < Test::Unit::TestCase | ||
513 | 514 | ||
514 | get :edit, :profile => 'testinguser', :id => article.id | 515 | get :edit, :profile => 'testinguser', :id => article.id |
515 | assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } | 516 | assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } |
516 | - assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => 'http://colivre.net/testinguser/myarticle' } | 517 | + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/testinguser\/myarticle/ } |
517 | end | 518 | end |
518 | 519 | ||
519 | should 'detect when comming from home page' do | 520 | should 'detect when comming from home page' do |
520 | @request.expects(:referer).returns('http://colivre.net/testinguser') | 521 | @request.expects(:referer).returns('http://colivre.net/testinguser') |
521 | get :edit, :profile => 'testinguser', :id => @profile.home_page.id | 522 | get :edit, :profile => 'testinguser', :id => @profile.home_page.id |
522 | assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } | 523 | assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } |
523 | - assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => 'http://colivre.net/testinguser/' + @profile.home_page.slug } | 524 | + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/testinguser\/#{@profile.home_page.slug}$/ } |
524 | end | 525 | end |
525 | 526 | ||
526 | should 'go back to public view when saving coming from there' do | 527 | should 'go back to public view when saving coming from there' do |
test/functional/content_viewer_controller_test.rb
@@ -370,6 +370,8 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -370,6 +370,8 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
370 | should 'not give access to private articles if logged off' do | 370 | should 'not give access to private articles if logged off' do |
371 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 371 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
372 | intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 372 | intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) |
373 | + | ||
374 | + @request.stubs(:ssl?).returns(true) | ||
373 | get :view_page, :profile => 'test_profile', :page => [ 'my-intranet' ] | 375 | get :view_page, :profile => 'test_profile', :page => [ 'my-intranet' ] |
374 | 376 | ||
375 | assert_template 'access_denied' | 377 | assert_template 'access_denied' |
@@ -379,6 +381,8 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -379,6 +381,8 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
379 | login_as('testinguser') | 381 | login_as('testinguser') |
380 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 382 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
381 | intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 383 | intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) |
384 | + | ||
385 | + @request.stubs(:ssl?).returns(true) | ||
382 | get :view_page, :profile => 'test_profile', :page => [ 'my-intranet' ] | 386 | get :view_page, :profile => 'test_profile', :page => [ 'my-intranet' ] |
383 | 387 | ||
384 | assert_template 'access_denied' | 388 | assert_template 'access_denied' |
@@ -391,6 +395,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -391,6 +395,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
391 | profile.affiliate(person, Profile::Roles.member) | 395 | profile.affiliate(person, Profile::Roles.member) |
392 | login_as('test_user') | 396 | login_as('test_user') |
393 | 397 | ||
398 | + @request.stubs(:ssl?).returns(true) | ||
394 | get :view_page, :profile => 'test_profile', :page => [ 'my-intranet' ] | 399 | get :view_page, :profile => 'test_profile', :page => [ 'my-intranet' ] |
395 | 400 | ||
396 | assert_template 'view_page' | 401 | assert_template 'view_page' |
@@ -412,6 +417,20 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -412,6 +417,20 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
412 | 417 | ||
413 | assert_tag :tag => 'a', :attributes => {:href => ('/myprofile/' + profile.identifier + '/cms/publish/' + page.id.to_s)} | 418 | assert_tag :tag => 'a', :attributes => {:href => ('/myprofile/' + profile.identifier + '/cms/publish/' + page.id.to_s)} |
414 | end | 419 | end |
420 | + | ||
421 | + should 'require SSL for viewing non-public articles' do | ||
422 | + page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :public_article => false) | ||
423 | + get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ] | ||
424 | + assert_redirected_to :protocol => 'https://' | ||
425 | + end | ||
426 | + | ||
427 | + should 'not redirect to SSL if already on SSL' do | ||
428 | + @request.expects(:ssl?).returns(true).at_least_once | ||
429 | + page = profile.articles.create!(:name => 'myarticle', :body => 'top secret', :public_article => false) | ||
430 | + login_as('testinguser') | ||
431 | + get :view_page, :profile => 'testinguser', :page => [ 'myarticle' ] | ||
432 | + assert_response :success | ||
433 | + end | ||
415 | 434 | ||
416 | should 'not show link to publication on view if not on person profile' do | 435 | should 'not show link to publication on view if not on person profile' do |
417 | prof = Community.create!(:name => 'test comm', :identifier => 'test_comm') | 436 | prof = Community.create!(:name => 'test comm', :identifier => 'test_comm') |
test/functional/enterprise_editor_controller_test.rb
@@ -8,6 +8,7 @@ class EnterpriseEditorControllerTest < Test::Unit::TestCase | @@ -8,6 +8,7 @@ class EnterpriseEditorControllerTest < Test::Unit::TestCase | ||
8 | def setup | 8 | def setup |
9 | @controller = EnterpriseEditorController.new | 9 | @controller = EnterpriseEditorController.new |
10 | @request = ActionController::TestRequest.new | 10 | @request = ActionController::TestRequest.new |
11 | + @request.stubs(:ssl?).returns(true) | ||
11 | @response = ActionController::TestResponse.new | 12 | @response = ActionController::TestResponse.new |
12 | end | 13 | end |
13 | 14 |
test/functional/enterprise_registration_controller_test.rb
@@ -11,6 +11,7 @@ all_fixtures | @@ -11,6 +11,7 @@ all_fixtures | ||
11 | def setup | 11 | def setup |
12 | @controller = EnterpriseRegistrationController.new | 12 | @controller = EnterpriseRegistrationController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
14 | + @request.stubs(:ssl?).returns(true) | ||
14 | @response = ActionController::TestResponse.new | 15 | @response = ActionController::TestResponse.new |
15 | login_as 'ze' | 16 | login_as 'ze' |
16 | end | 17 | end |
test/functional/enterprise_validation_controller_test.rb
@@ -11,6 +11,7 @@ class EnterpriseValidationControllerTest < Test::Unit::TestCase | @@ -11,6 +11,7 @@ class EnterpriseValidationControllerTest < Test::Unit::TestCase | ||
11 | def setup | 11 | def setup |
12 | @controller = EnterpriseValidationController.new | 12 | @controller = EnterpriseValidationController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
14 | + @request.stubs(:ssl?).returns(true) | ||
14 | @response = ActionController::TestResponse.new | 15 | @response = ActionController::TestResponse.new |
15 | 16 | ||
16 | login_as 'ze' | 17 | login_as 'ze' |
test/functional/favorite_enterprises_controller_test.rb
@@ -10,6 +10,7 @@ class FavoriteEnterprisesControllerTest < Test::Unit::TestCase | @@ -10,6 +10,7 @@ class FavoriteEnterprisesControllerTest < Test::Unit::TestCase | ||
10 | def setup | 10 | def setup |
11 | @controller = FavoriteEnterprisesController.new | 11 | @controller = FavoriteEnterprisesController.new |
12 | @request = ActionController::TestRequest.new | 12 | @request = ActionController::TestRequest.new |
13 | + @request.stubs(:ssl?).returns(true) | ||
13 | @response = ActionController::TestResponse.new | 14 | @response = ActionController::TestResponse.new |
14 | 15 | ||
15 | self.profile = create_user('testuser').person | 16 | self.profile = create_user('testuser').person |
test/functional/friends_controller_test.rb
@@ -10,6 +10,7 @@ class FriendsControllerTest < Test::Unit::TestCase | @@ -10,6 +10,7 @@ class FriendsControllerTest < Test::Unit::TestCase | ||
10 | def setup | 10 | def setup |
11 | @controller = FriendsController.new | 11 | @controller = FriendsController.new |
12 | @request = ActionController::TestRequest.new | 12 | @request = ActionController::TestRequest.new |
13 | + @request.stubs(:ssl?).returns(true) | ||
13 | @response = ActionController::TestResponse.new | 14 | @response = ActionController::TestResponse.new |
14 | 15 | ||
15 | self.profile = create_user('testuser').person | 16 | self.profile = create_user('testuser').person |
test/functional/mailconf_controller_test.rb
@@ -7,6 +7,7 @@ class MailconfControllerTest < Test::Unit::TestCase | @@ -7,6 +7,7 @@ class MailconfControllerTest < Test::Unit::TestCase | ||
7 | def setup | 7 | def setup |
8 | @controller = MailconfController.new | 8 | @controller = MailconfController.new |
9 | @request = ActionController::TestRequest.new | 9 | @request = ActionController::TestRequest.new |
10 | + @request.stubs(:ssl?).returns(true) | ||
10 | @response = ActionController::TestResponse.new | 11 | @response = ActionController::TestResponse.new |
11 | 12 | ||
12 | MailConf.stubs(:enabled?).returns(true) | 13 | MailConf.stubs(:enabled?).returns(true) |
test/functional/manage_products_controller_test.rb
@@ -9,6 +9,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase | @@ -9,6 +9,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase | ||
9 | def setup | 9 | def setup |
10 | @controller = ManageProductsController.new | 10 | @controller = ManageProductsController.new |
11 | @request = ActionController::TestRequest.new | 11 | @request = ActionController::TestRequest.new |
12 | + @request.stubs(:ssl?).returns(true) | ||
12 | @response = ActionController::TestResponse.new | 13 | @response = ActionController::TestResponse.new |
13 | @enterprise = Enterprise.create(:name => 'teste', :identifier => 'test_ent') | 14 | @enterprise = Enterprise.create(:name => 'teste', :identifier => 'test_ent') |
14 | @user = create_user_with_permission('test_user', 'manage_products', @enterprise) | 15 | @user = create_user_with_permission('test_user', 'manage_products', @enterprise) |
test/functional/memberships_controller_test.rb
@@ -12,6 +12,7 @@ class MembershipsControllerTest < Test::Unit::TestCase | @@ -12,6 +12,7 @@ class MembershipsControllerTest < Test::Unit::TestCase | ||
12 | def setup | 12 | def setup |
13 | @controller = MembershipsController.new | 13 | @controller = MembershipsController.new |
14 | @request = ActionController::TestRequest.new | 14 | @request = ActionController::TestRequest.new |
15 | + @request.stubs(:ssl?).returns(true) | ||
15 | @response = ActionController::TestResponse.new | 16 | @response = ActionController::TestResponse.new |
16 | 17 | ||
17 | @profile = create_user('testuser').person | 18 | @profile = create_user('testuser').person |
test/functional/my_profile_controller_test.rb
@@ -17,6 +17,7 @@ class MyProfileControllerTest < Test::Unit::TestCase | @@ -17,6 +17,7 @@ class MyProfileControllerTest < Test::Unit::TestCase | ||
17 | def setup | 17 | def setup |
18 | @controller = MyProfileController.new | 18 | @controller = MyProfileController.new |
19 | @request = ActionController::TestRequest.new | 19 | @request = ActionController::TestRequest.new |
20 | + @request.stubs(:ssl?).returns(true) | ||
20 | @response = ActionController::TestResponse.new | 21 | @response = ActionController::TestResponse.new |
21 | end | 22 | end |
22 | 23 | ||
@@ -46,4 +47,13 @@ class MyProfileControllerTest < Test::Unit::TestCase | @@ -46,4 +47,13 @@ class MyProfileControllerTest < Test::Unit::TestCase | ||
46 | assert_response 403 # forbidden | 47 | assert_response 403 # forbidden |
47 | end | 48 | end |
48 | 49 | ||
50 | + should 'require ssl' do | ||
51 | + @controller = OnlyForPersonTestController.new | ||
52 | + org = Organization.create!(:identifier => 'hacking_institute', :name => 'Hacking Institute') | ||
53 | + | ||
54 | + @request.expects(:ssl?).returns(false).at_least_once | ||
55 | + get :index, :profile => 'hacking_institute' | ||
56 | + assert_redirected_to :protocol => 'https://' | ||
57 | + end | ||
58 | + | ||
49 | end | 59 | end |
test/functional/profile_design_controller_test.rb
@@ -9,6 +9,7 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | @@ -9,6 +9,7 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | ||
9 | def setup | 9 | def setup |
10 | @controller = ProfileDesignController.new | 10 | @controller = ProfileDesignController.new |
11 | @request = ActionController::TestRequest.new | 11 | @request = ActionController::TestRequest.new |
12 | + @request.stubs(:ssl?).returns(true) | ||
12 | @response = ActionController::TestResponse.new | 13 | @response = ActionController::TestResponse.new |
13 | 14 | ||
14 | @holder = create_user('designtestuser').person | 15 | @holder = create_user('designtestuser').person |
test/functional/profile_editor_controller_test.rb
@@ -10,6 +10,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -10,6 +10,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
10 | def setup | 10 | def setup |
11 | @controller = ProfileEditorController.new | 11 | @controller = ProfileEditorController.new |
12 | @request = ActionController::TestRequest.new | 12 | @request = ActionController::TestRequest.new |
13 | + @request.stubs(:ssl?).returns(true) | ||
13 | @response = ActionController::TestResponse.new | 14 | @response = ActionController::TestResponse.new |
14 | login_as('ze') | 15 | login_as('ze') |
15 | @profile = Person['ze'] | 16 | @profile = Person['ze'] |
test/functional/profile_members_controller_test.rb
@@ -8,6 +8,7 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | @@ -8,6 +8,7 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | ||
8 | def setup | 8 | def setup |
9 | @controller = ProfileMembersController.new | 9 | @controller = ProfileMembersController.new |
10 | @request = ActionController::TestRequest.new | 10 | @request = ActionController::TestRequest.new |
11 | + @request.stubs(:ssl?).returns(true) | ||
11 | @response = ActionController::TestResponse.new | 12 | @response = ActionController::TestResponse.new |
12 | end | 13 | end |
13 | 14 |
test/functional/public_controller_test.rb
@@ -6,15 +6,23 @@ class PublicController; def rescue_action(e) raise e end; end | @@ -6,15 +6,23 @@ class PublicController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class PublicControllerTest < Test::Unit::TestCase | 7 | class PublicControllerTest < Test::Unit::TestCase |
8 | 8 | ||
9 | + class TestingPublicStuffController < PublicController | ||
10 | + def index | ||
11 | + render :text => 'test', :layout => false | ||
12 | + end | ||
13 | + end | ||
14 | + | ||
9 | def setup | 15 | def setup |
10 | - @controller = PublicController.new | 16 | + @controller = TestingPublicStuffController.new |
11 | @request = ActionController::TestRequest.new | 17 | @request = ActionController::TestRequest.new |
18 | + @request.stubs(:ssl?).returns(true) | ||
12 | @response = ActionController::TestResponse.new | 19 | @response = ActionController::TestResponse.new |
13 | end | 20 | end |
14 | 21 | ||
15 | # Replace this with your real tests. | 22 | # Replace this with your real tests. |
16 | - def test_truth | ||
17 | - assert true | 23 | + should 'refuse SSL' do |
24 | + get :index | ||
25 | + assert_redirected_to :protocol => 'http://' | ||
18 | end | 26 | end |
19 | 27 | ||
20 | end | 28 | end |
test/functional/tasks_controller_test.rb
@@ -10,6 +10,7 @@ class TasksControllerTest < Test::Unit::TestCase | @@ -10,6 +10,7 @@ class TasksControllerTest < Test::Unit::TestCase | ||
10 | def setup | 10 | def setup |
11 | @controller = TasksController.new | 11 | @controller = TasksController.new |
12 | @request = ActionController::TestRequest.new | 12 | @request = ActionController::TestRequest.new |
13 | + @request.stubs(:ssl?).returns(true) | ||
13 | @response = ActionController::TestResponse.new | 14 | @response = ActionController::TestResponse.new |
14 | 15 | ||
15 | self.profile = create_user('testuser').person | 16 | self.profile = create_user('testuser').person |
test/functional/themes_controller_test.rb
@@ -8,6 +8,7 @@ class ThemesControllerTest < Test::Unit::TestCase | @@ -8,6 +8,7 @@ class ThemesControllerTest < Test::Unit::TestCase | ||
8 | def setup | 8 | def setup |
9 | @controller = ThemesController.new | 9 | @controller = ThemesController.new |
10 | @request = ActionController::TestRequest.new | 10 | @request = ActionController::TestRequest.new |
11 | + @request.stubs(:ssl?).returns(true) | ||
11 | @response = ActionController::TestResponse.new | 12 | @response = ActionController::TestResponse.new |
12 | 13 | ||
13 | Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) | 14 | Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) |
test/integration/forgot_password_test.rb
@@ -2,6 +2,10 @@ require "#{File.dirname(__FILE__)}/../test_helper" | @@ -2,6 +2,10 @@ require "#{File.dirname(__FILE__)}/../test_helper" | ||
2 | 2 | ||
3 | class ForgotPasswordTest < ActionController::IntegrationTest | 3 | class ForgotPasswordTest < ActionController::IntegrationTest |
4 | 4 | ||
5 | + def setup | ||
6 | + ActionController::Integration::Session.any_instance.stubs(:https?).returns(true) | ||
7 | + end | ||
8 | + | ||
5 | def test_forgot_password | 9 | def test_forgot_password |
6 | 10 | ||
7 | User.destroy_all | 11 | User.destroy_all |
test/integration/signup_test.rb
1 | require "#{File.dirname(__FILE__)}/../test_helper" | 1 | require "#{File.dirname(__FILE__)}/../test_helper" |
2 | 2 | ||
3 | -class AccountTest < ActionController::IntegrationTest | 3 | +class SignupTest < ActionController::IntegrationTest |
4 | all_fixtures | 4 | all_fixtures |
5 | 5 | ||
6 | + def setup | ||
7 | + ActionController::Integration::Session.any_instance.stubs(:https?).returns(true) | ||
8 | + end | ||
9 | + | ||
6 | def test_should_require_acceptance_of_terms_for_signup | 10 | def test_should_require_acceptance_of_terms_for_signup |
7 | Environment.default.update_attributes(:terms_of_use => 'You agree to not be annoying.') | 11 | Environment.default.update_attributes(:terms_of_use => 'You agree to not be annoying.') |
8 | 12 |
test/integration/user_registers_at_the_application_test.rb
@@ -9,6 +9,11 @@ class UserRegistersAtTheApplicationTest < ActionController::IntegrationTest | @@ -9,6 +9,11 @@ class UserRegistersAtTheApplicationTest < ActionController::IntegrationTest | ||
9 | assert_can_signup | 9 | assert_can_signup |
10 | 10 | ||
11 | get '/account/signup' | 11 | get '/account/signup' |
12 | + | ||
13 | + # going SSL | ||
14 | + assert_response :redirect | ||
15 | + follow_redirect! | ||
16 | + | ||
12 | assert_response :success | 17 | assert_response :success |
13 | 18 | ||
14 | post '/account/signup', :user => { :login => 'mylogin', :password => 'mypassword', :password_confirmation => 'mypassword', :email => 'mylogin@example.com' } | 19 | post '/account/signup', :user => { :login => 'mylogin', :password => 'mypassword', :password_confirmation => 'mypassword', :email => 'mylogin@example.com' } |
@@ -30,6 +35,11 @@ class UserRegistersAtTheApplicationTest < ActionController::IntegrationTest | @@ -30,6 +35,11 @@ class UserRegistersAtTheApplicationTest < ActionController::IntegrationTest | ||
30 | assert_can_signup | 35 | assert_can_signup |
31 | 36 | ||
32 | get '/account/signup' | 37 | get '/account/signup' |
38 | + | ||
39 | + # going SSL | ||
40 | + assert_response :redirect | ||
41 | + follow_redirect! | ||
42 | + | ||
33 | assert_response :success | 43 | assert_response :success |
34 | 44 | ||
35 | post '/account/signup', :user => { :login => 'ze', :password => 'mypassword', :password_confirmation => 'mypassword', :email => 'mylogin@example.com' } | 45 | post '/account/signup', :user => { :login => 'ze', :password => 'mypassword', :password_confirmation => 'mypassword', :email => 'mylogin@example.com' } |
test/mocks/test/test_controller.rb
@@ -39,4 +39,20 @@ class TestController < ApplicationController | @@ -39,4 +39,20 @@ class TestController < ApplicationController | ||
39 | ' | 39 | ' |
40 | end | 40 | end |
41 | 41 | ||
42 | + require_ssl :only => 'sslonly' | ||
43 | + def sslonly | ||
44 | + render :text => 'this should be seen only on SSL', :layout => false | ||
45 | + end | ||
46 | + def doesnt_need_ssl | ||
47 | + render :text => 'this should be seen even without SSL', :layout => false | ||
48 | + end | ||
49 | + | ||
50 | + refuse_ssl :only => 'nossl' | ||
51 | + def nossl | ||
52 | + render :text => 'this should not be seen over SSL', :layout => false | ||
53 | + end | ||
54 | + def doesnt_refuse_ssl | ||
55 | + render :text => 'this should be seen over SSL or not, whatever', :layout => false | ||
56 | + end | ||
57 | + | ||
42 | end | 58 | end |
test/test_helper.rb
@@ -239,6 +239,8 @@ class ActionController::IntegrationTest | @@ -239,6 +239,8 @@ class ActionController::IntegrationTest | ||
239 | 239 | ||
240 | 240 | ||
241 | def login(username, password) | 241 | def login(username, password) |
242 | + ActionController::Integration::Session.any_instance.stubs(:https?).returns(true) | ||
243 | + | ||
242 | post '/account/login', :user => { :login => username, :password => password } | 244 | post '/account/login', :user => { :login => username, :password => password } |
243 | assert_response :redirect | 245 | assert_response :redirect |
244 | follow_redirect! | 246 | follow_redirect! |