summaryrefslogtreecommitdiffstats
path: root/vendor/gems/ruby-openid-2.1.4/test/test_responses.rb
blob: 61a0e4c194fdaa434e33924e1cf47cf5857456b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require "test/unit"
require "openid/consumer/discovery"
require "openid/consumer/responses"

module OpenID
  class Consumer
    module TestResponses
      class TestSuccessResponse < Test::Unit::TestCase
        def setup
          @endpoint = OpenIDServiceEndpoint.new
          @endpoint.claimed_id = 'identity_url'
        end

        def test_extension_response
          q = {
            'ns.sreg' => 'urn:sreg',
            'ns.unittest' => 'urn:unittest',
            'unittest.one' => '1',
            'unittest.two' => '2',
            'sreg.nickname' => 'j3h',
            'return_to' => 'return_to',
          }
          signed_list = q.keys.map { |k| 'openid.' + k }
          msg = Message.from_openid_args(q)
          resp = SuccessResponse.new(@endpoint, msg, signed_list)
          utargs = resp.extension_response('urn:unittest', false)
          assert_equal(utargs, {'one' => '1', 'two' => '2'})
          sregargs = resp.extension_response('urn:sreg', false)
          assert_equal(sregargs, {'nickname' => 'j3h'})
        end

        def test_extension_response_signed
          args = {
            'ns.sreg' => 'urn:sreg',
            'ns.unittest' => 'urn:unittest',
            'unittest.one' => '1',
            'unittest.two' => '2',
            'sreg.nickname' => 'j3h',
            'sreg.dob' => 'yesterday',
            'return_to' => 'return_to',
            'signed' => 'sreg.nickname,unittest.one,sreg.dob',
          }

          signed_list = ['openid.sreg.nickname',
                         'openid.unittest.one',
                         'openid.sreg.dob',]

          msg = Message.from_openid_args(args)
          resp = SuccessResponse.new(@endpoint, msg, signed_list)

          # All args in this NS are signed, so expect all.
          sregargs = resp.extension_response('urn:sreg', true)
          assert_equal(sregargs, {'nickname' => 'j3h', 'dob' => 'yesterday'})

          # Not all args in this NS are signed, so expect nil when
          # asking for them.
          utargs = resp.extension_response('urn:unittest', true)
          assert_equal(nil, utargs)
        end
      end
    end
  end
end