openid spec

here is the spec for the two-step openid authentication process in a rails controller.

it "should take an openid and request credentials from the identity provider" do # test OpenID my_openid = "http://identityprovider/username" finish_openid_url = "http://localhost/welcome/complete" # mock OpenID::Request oid_request = mock("OpenID::Request") oid_request.should_receive(:send_redirect?).with("http://test.host/", "http://test.host/welcome/complete", nil).and_return(true) oid_request.should_receive(:redirect_url).with("http://test.host/", "http://test.host/welcome/complete", nil).and_return(finish_openid_url) # mock OpenID::Consumer consumer = mock("OpenID::Consumer") consumer.should_receive(:begin).with(my_openid).and_return(oid_request) # mock the lib/OpenidUtility controller.should_receive(:consumer).and_return(consumer) get 'begin', :openid_identifier => my_openid response.should redirect_to(finish_openid_url) end

it "should login with a valid openid credential" do my_openid = "http://identityprovider/username" # mock Openid model oid = mock_model(Openid) user = mock_model(User) oid.should_receive(:user).and_return(user) Openid.should_receive(:find_by_openid).with(my_openid).and_return(oid) # mock OpenID::Response oid_response = mock("OpenID::Response") oid_response.should_receive(:status).and_return(OpenID::Consumer::SUCCESS) oid_response.should_receive(:identity_url).and_return(my_openid) # mock OpenID::Consumer consumer = mock("OpenID::Consumer") consumer.should_receive(:complete).and_return(oid_response) # mock the lib/OpenidUtility controller.should_receive(:consumer).and_return(consumer) controller.should_receive(:current_user=).with(user) get 'complete' response.should redirect_to("http://test.host/welcome/login") end

/typo:code

tags: