require File.dirname(__FILE__) + '/test_helper.rb' class SessionTest < ActiveSupport::TestCase setup :setup_http_stubs, :setup_users def setup_http_stubs stub_request(:post, "http://example:bogus@localhost/crowd/console/rest/usermanagement/latest/authentication?username=ben"). with(:body => "benrocks", :headers => {'Accept'=>'*/*', 'Content-Type'=>'text/xml'}). to_return(:status => 200, :body => %q[BenJohnsonRob Dimarcoben@foo.comtrue], :headers => {}) stub_request(:post, "http://example:bogus@localhost/crowd/console/rest/usermanagement/latest/authentication?username=ben"). with(:body => "bogus", :headers => {'Accept'=>'*/*', 'Content-Type'=>'text/xml'}). to_return(:status => 400, :body => %q[Incorrect], :headers => {}) end def setup_users u = User.find_or_create_by_crowd_login :crowd_login=>"ben", :email=>"foo@bar.com" raise "Problem creating user...#{u.errors.inspect}" unless u.valid? end def test_use_crowd_rest_authentication assert_not_nil User.find_by_crowd_login 'ben' UserSession.crowd_base_url = "http://localhost/crowd/console" UserSession.crowd_application_name = "example" UserSession.crowd_application_password = "bogus" session = UserSession.new(:crowd_login => 'ben', :crowd_password => "benrocks") assert session.save end def test_invalid_password assert_not_nil User.find_by_crowd_login 'ben' UserSession.crowd_base_url = "http://localhost/crowd/console" UserSession.crowd_application_name = "example" UserSession.crowd_application_password = "bogus" session = UserSession.new(:crowd_login => 'ben', :crowd_password => "bogus") assert !session.save assert_equal ["Crowd password is not valid"], session.errors.full_messages end end