]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rots-0.2.1/spec/server_app_spec.rb
Merge branch 'master' into openid
[rails.git] / vendor / gems / rots-0.2.1 / spec / server_app_spec.rb
1 require File.join(File.dirname(__FILE__), 'spec_helper')
2
3 # This is just a comment test
4
5 describe Rots::ServerApp do
6
7   describe "when the request is not an OpenID request" do
8
9     it "should return a helpful message saying that is an OpenID endpoint" do
10       request  = Rack::MockRequest.new(Rots::ServerApp.new({'sreg' => {}}, 
11         {:storage => File.join(*%w(. tmp rots)) }))
12       response = request.get("/")
13       response.should be_ok
14       response.body.should == "<html><body><h1>ROTS => This is an OpenID endpoint</h1></body></html>"
15     end
16
17   end
18
19   describe "when the request is an OpenID request" do
20     
21     before(:each) do
22       @request = Rack::MockRequest.new(Rots::ServerApp.new({
23         'identity' => 'john.doe',
24         'sreg' => {
25           'email' => "john@doe.com",
26           'nickname' => 'johndoe',
27           'fullname' => "John Doe",
28           'dob' => "1985-09-21",
29           'gender' => "M"
30         }},
31         {:storage => File.join(*%w(. tmp rots))}
32       ))
33     end
34     
35
36     describe "and it is a check_id request" do
37
38       describe "and is immediate" do
39
40         it "should return an openid.mode equal to setup_needed" do
41           response = checkid_immediate(@request)
42           params = openid_params(response)
43           params['openid.mode'].should == 'setup_needed'
44         end
45
46       end
47
48       describe "and is not immediate" do
49
50         describe "with a success flag" do
51
52           it "should return an openid.mode equal to id_res" do
53             response = checkid_setup(@request, 'openid.success' => 'true')
54             params = openid_params(response)
55             params['openid.mode'].should == 'id_res'
56           end
57
58         end
59
60         describe "without a success flag" do
61
62           it "should return an openid.mode equal to cancel" do
63             response = checkid_setup(@request)
64             params = openid_params(response)
65             params['openid.mode'].should == 'cancel'
66           end
67
68         end
69         
70         describe "using SREG extension with a success flag" do
71           
72           it "should return an openid.mode equal to id_res" do
73             response = checkid_setup(@request, 'openid.success' => 'true')
74             params = openid_params(response)
75             params['openid.mode'].should == 'id_res'
76           end
77           
78           it "should return all the sreg fields" do
79             response = checkid_setup(@request, {
80               'openid.success' => true,
81               'openid.ns.sreg' => OpenID::SReg::NS_URI,
82               'openid.sreg.required' => 'email,nickname,fullname',
83               'openid.sreg.optional' => 'dob,gender'
84             })
85             params = openid_params(response)
86             params['openid.sreg.email'].should == "john@doe.com"
87             params['openid.sreg.nickname'].should == 'johndoe'
88             params['openid.sreg.fullname'].should == "John Doe"
89             params['openid.sreg.dob'].should == "1985-09-21"
90             params['openid.sreg.gender'].should == "M"
91           end
92           
93         end
94       
95       end
96     end
97   end
98
99 end