Class: SecurityTest

Inherits:
ActionController::IntegrationTest
  • Object
show all
Includes:
Goldberg::TestHelper
Defined in:
lib/six-updater-web/vendor/plugins/goldberg/test/integration/security_test.rb

Overview

(Also need to test for pending registration confirmation, and for session expiry.)

Instance Method Summary collapse

Methods included from Goldberg::TestHelper

#form_login, #form_logout, included, #login_user

Instance Method Details

#test_action_securityObject

Public user can execute public actions, but when they try executing an administrator action they are redirected to login.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/integration/security_test.rb', line 12

def test_action_security
  # A public action
  get '/goldberg/auth/login'
  assert_response :success
  # An administrator action
  get '/goldberg/users/list'
  

  ('admin', 'admin')

  get '/goldberg/users/list'
  assert_response :success
end

#test_page_securityObject

Public user can view public pages, but when they try accessing an administrator page they are redirected to login.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/integration/security_test.rb', line 28

def test_page_security
  # A public page
  get '/home'
  assert_response :success
  # An administrator page
  get '/admin'
  

  ('admin', 'admin')
  
  get '/admin'
  assert_response :success
end

#test_pending_requestObject

If a public user tries to access a resource for which they lack authorisation, after logging in they should be redirected to that resource.



45
46
47
48
49
50
51
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/integration/security_test.rb', line 45

def test_pending_request
  get '/goldberg/users/list'
  

  ('admin', 'admin')
  assert_match /goldberg\/users\/list/, response.redirected_to
end

#test_session_expiryObject

User should be redirected to the session expired page if they remain inactive longer than the session timeout in System Settings.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/integration/security_test.rb', line 56

def test_session_expiry
  # Set the timeout really short
  settings = Goldberg::SystemSettings.find :first
  settings.session_timeout = 3  # Three seconds should be ample
  settings.save!

  ('admin', 'admin')
  get '/site_admin'
  assert_response :success

  # Wait longer than the timeout
  sleep 4
  get '/site_admin'
  assert_redirected_to :session_expired_page
end

#test_wrong_passwordObject

User is not logged in if password is wrong



73
74
75
76
# File 'lib/six-updater-web/vendor/plugins/goldberg/test/integration/security_test.rb', line 73

def test_wrong_password
  ('admin', 'foobar')
  assert_nil session[:goldberg][:user_id]
end