Module: CalnetAuthenticated::TestHelper

Defined in:
lib/calnet_authenticated/test_helper.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/calnet_authenticated/test_helper.rb', line 3

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#assert_logged_inObject



57
58
59
# File 'lib/calnet_authenticated/test_helper.rb', line 57

def assert_logged_in
  assert_not_nil session[:calnetuid]
end

#assert_not_logged_inObject



61
62
63
# File 'lib/calnet_authenticated/test_helper.rb', line 61

def assert_not_logged_in
  assert_nil session[:calnetuid]
end

#assert_redirected_to_loginObject



45
46
47
48
49
# File 'lib/calnet_authenticated/test_helper.rb', line 45

def 
  assert_response :redirect
  assert_match "https://auth-test.berkeley.edu/cas/login",
    @response.redirected_to
end

#assert_redirected_to_logoutObject



51
52
53
54
55
# File 'lib/calnet_authenticated/test_helper.rb', line 51

def assert_redirected_to_logout
  assert_response :redirect
  assert_match "https://auth-test.berkeley.edu/cas/logout",
    @response.redirected_to
end

#login_as(user = nil) ⇒ Object Also known as: login, log_in



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/calnet_authenticated/test_helper.rb', line 7

def ( user=nil )
  uid = ( user.is_a?(User) ) ? user.uid : user
  if !uid.blank?
    @request.session[:calnetuid] = uid
    stub_ucb_ldap_person()
    User.find_create_and_update_by_uid(uid)

    CASClient::Frameworks::Rails::Filter.stubs(
      :filter).returns(true)
    # No longer using the GatewayFilter stuff.
    # CASClient::Frameworks::Rails::GatewayFilter.stubs(
    # :filter).returns(true)
  end
end

#stub_ucb_ldap_person(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/calnet_authenticated/test_helper.rb', line 25

def stub_ucb_ldap_person(options={})
  UCB::LDAP::Person.stubs(:find_by_uid).returns(
    UCB::LDAP::Person.new({
      :sn => ["Wendt"],
      :displayname => ["Mr. Jake Wendt, BA"],
      :telephonenumber => ["+1 510 642-9749"],
      :mail => []
    })
  )
  # Load schema locally for offline testing.
  # This will generate this warning...
  # Warning: schema loading from file
  # from ucb_ldap-1.3.2/lib/ucb_ldap_schema.rb
  # Comment this out to get the schema from Cal.
  # This will generate this warning...
  # warning: peer certificate won't be verified in this SSL session
  UCB::LDAP::Schema.stubs(
    :load_attributes_from_url).raises(StandardError)
end