foreman/test/unit/sso/apache_test.rb @ 8ffa0b9a
8ffa0b9a | Jan Pazdziora | # encoding: UTF-8
|
|
4e7ea9b8 | Marek Hulan | require 'test_helper'
|
|
class ApacheTest < ActiveSupport::TestCase
|
|||
b7589c32 | Jan Pazdziora | def setup
|
|
Setting::Auth.load_defaults
|
|||
end
|
|||
4e7ea9b8 | Marek Hulan | def test_user_is_set_when_authenticated
|
|
b7589c32 | Jan Pazdziora | Setting['authorize_login_delegation_auth_source_user_autocreate'] = 'apache'
|
|
4e7ea9b8 | Marek Hulan | apache = get_apache_method
|
|
assert apache.authenticated?
|
|||
assert_equal apache.user, 'ares'
|
|||
852ff714 | Daniel Lobato | assert_equal apache.session[:sso_method], 'SSO::Apache'
|
|
4e7ea9b8 | Marek Hulan | end
|
|
def test_available?
|
|||
# non api request
|
|||
apache = get_apache_method(false)
|
|||
Setting["authorize_login_delegation"] = true
|
|||
assert apache.available?
|
|||
Setting["authorize_login_delegation"] = false
|
|||
assert !apache.available?
|
|||
Setting["authorize_login_delegation"] = true
|
|||
# api request
|
|||
apache = get_apache_method(true)
|
|||
Setting["authorize_login_delegation_api"] = true
|
|||
assert apache.available?
|
|||
Setting["authorize_login_delegation_api"] = false
|
|||
assert !apache.available?
|
|||
end
|
|||
b7589c32 | Jan Pazdziora | ||
def test_authenticated?
|
|||
Setting['authorize_login_delegation_auth_source_user_autocreate'] = 'apache'
|
|||
apache = get_apache_method
|
|||
8ffa0b9a | Jan Pazdziora | apache.controller.request.env[SSO::Apache::CAS_USERNAME] = nil
|
|
b7589c32 | Jan Pazdziora | assert !apache.authenticated?
|
|
8ffa0b9a | Jan Pazdziora | ||
b7589c32 | Jan Pazdziora | apache.controller.request.env[SSO::Apache::CAS_USERNAME] = 'ares'
|
|
assert apache.authenticated?
|
|||
end
|
|||
8ffa0b9a | Jan Pazdziora | def test_authenticated_passes_attributes
|
|
Setting['authorize_login_delegation_auth_source_user_autocreate'] = 'apache'
|
|||
apache = get_apache_method
|
|||
apache.controller.request.env[SSO::Apache::CAS_USERNAME] = 'ares'
|
|||
apache.controller.request.env['REMOTE_USER_EMAIL'] = 'foobar@example.com'
|
|||
apache.controller.request.env['REMOTE_USER_FIRSTNAME'] = 'Foo'
|
|||
apache.controller.request.env['REMOTE_USER_LASTNAME'] = 'Bar'
|
|||
User.expects(:find_or_create_external_user).
|
|||
with({:login => 'ares', :mail => 'foobar@example.com', :firstname => 'Foo', :lastname => 'Bar'}, 'apache').
|
|||
returns(true)
|
|||
assert apache.authenticated?
|
|||
end
|
|||
def test_convert_encoding
|
|||
apache = get_apache_method
|
|||
assert apache.send(:convert_encoding, 'fó✗@e✗amp✓e.com')
|
|||
end
|
|||
b7589c32 | Jan Pazdziora | def test_authenticate!
|
|
apache = get_apache_method
|
|||
controller = apache.controller
|
|||
controller.stubs(:redirect_to).returns('correct redirect')
|
|||
response = apache.authenticate!
|
|||
assert apache.has_rendered
|
|||
assert_equal response, 'correct redirect'
|
|||
end
|
|||
def test_support_login
|
|||
apache = get_apache_method
|
|||
controller = apache.controller
|
|||
controller.request.fullpath = '/something'
|
|||
assert apache.support_login?
|
|||
controller.request.fullpath = '/extlogin'
|
|||
assert !apache.support_login?
|
|||
end
|
|||
4e7ea9b8 | Marek Hulan | def get_apache_method(api_request = false)
|
|
SSO::Apache.new(get_controller(api_request))
|
|||
end
|
|||
def get_controller(api_request)
|
|||
9a1f72f4 | Eric D. Helms | main_app = stub
|
|
main_app.stubs(:extlogin_users_path).returns('/extlogin')
|
|||
b7589c32 | Jan Pazdziora | controller = Struct.new(:request, :session, :extlogin_users_path).new(Struct.new(:env, :fullpath).new({ SSO::Apache::CAS_USERNAME => 'ares' }))
|
|
852ff714 | Daniel Lobato | controller.session = {}
|
|
390e2281 | David Davis | controller.stubs(:api_request?).returns(api_request)
|
|
9a1f72f4 | Eric D. Helms | controller.stubs(:main_app).returns(main_app)
|
|
4e7ea9b8 | Marek Hulan | controller
|
|
end
|
|||
852ff714 | Daniel Lobato | end
|