Module: CalnetAuthenticated::TestHelper

Defined in:
lib/calnet_authenticated/test_helper.rb

Instance Method Summary collapse

Instance Method Details

#assert_logged_inObject



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

def assert_logged_in
  assert_not_nil session[:calnetuid]
end

#assert_not_logged_inObject



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

def assert_not_logged_in
  assert_nil session[:calnetuid]
end

#assert_redirected_to_loginObject



41
42
43
44
45
# File 'lib/calnet_authenticated/test_helper.rb', line 41

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

#assert_redirected_to_logoutObject



47
48
49
50
51
# File 'lib/calnet_authenticated/test_helper.rb', line 47

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



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/calnet_authenticated/test_helper.rb', line 3

def ( user=nil )
  uid = ( user.is_a?($CalnetAuthenticatedUser) ) ? user.uid : user
  if !uid.blank?
    @request.session[:calnetuid] = uid
    stub_ucb_ldap_person()
    $CalnetAuthenticatedUser.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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/calnet_authenticated/test_helper.rb', line 21

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