]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rots-0.2.1/spec/spec_helper.rb
RTL support
[rails.git] / vendor / gems / rots-0.2.1 / spec / spec_helper.rb
1 $:.unshift(File.dirname(__FILE__), '..', 'lib')
2 require "rubygems"
3 require "spec"
4 require "rack"
5 require "rots"
6
7 module Rots::RequestHelper
8   
9   def checkid_setup(request, params={}, with_associate=true)
10     assoc_handle = make_association(request) if with_associate
11     send_checkid(request, :setup, params, assoc_handle)
12   end
13   
14   def checkid_immediate(request, params={}, with_associate=true)
15     assoc_handle = make_association(request) if with_associate
16     send_checkid(request, :immediate, params, assoc_handle)
17   end
18   
19   def openid_params(response)
20     uri = URI(response.headers['Location'])
21     Rack::Utils.parse_query(uri.query)
22   end
23   
24   protected
25   
26   def send_checkid(request, mode, params={}, assoc_handle = nil)
27     params = self.send(:"checkid_#{mode}_params", params)
28     params.merge('openid.assoc_handle' => assoc_handle) if assoc_handle
29     qs = "/?" + Rack::Utils.build_query(params)
30     request.get(qs)
31   end
32
33   def make_association(request)
34     associate_qs = Rack::Utils.build_query(associate_params)
35     response = request.post('/', :input => associate_qs)
36     parse_assoc_handle_from(response)
37   end
38   
39   def parse_assoc_handle_from(response)
40     response.body.split("\n")[0].match(/^assoc_handle:(.*)$/).captures[0]
41   end
42   
43   def checkid_setup_params(params = {})
44     {
45       "openid.ns" => "http://specs.openid.net/auth/2.0",
46       "openid.mode" => "checkid_setup",
47       "openid.claimed_id" => 'john.doe',
48       "openid.identity" => 'john.doe',
49       "openid.return_to" => "http://www.google.com"
50       # need to specify the openid_handle by hand
51     }.merge!(params)
52   end
53   
54   def checkid_immediate_params(params = {})
55     checkid_setup_params({'openid.mode' => 'checkid_immediate'}.merge!(params))
56   end
57   
58   def associate_params
59     {
60       "openid.ns" => "http://specs.openid.net/auth/2.0",
61       "openid.mode" => "associate",
62       "openid.session_type" => "DH-SHA1",
63       "openid.assoc_type" => "HMAC-SHA1",
64       "openid.dh_consumer_public" =>
65       "U672/RsDUNxAFFAXA+ShVh5LMD2CRdsoqdqhDCPUzfCNy2f44uTWuid/MZuGfJmiVA7QmxqM3GSb8EVq3SGK8eGEwwyzUtatqHidx72rfwAav5AUrZTnwSPQJyiCFrKNGmNhXdRJzcfzSkgaC3hVz2kpADzEevIExG6agns1sYY="
66     }
67   end
68   
69 end
70
71 Spec::Runner.configure do |config|
72   config.include Rots::RequestHelper
73 end