forked from entp/ruby-openid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_xrires.rb
67 lines (56 loc) · 2.03 KB
/
test_xrires.rb
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
64
65
66
67
require "test_helper"
require 'openid/yadis/xrires'
module OpenID
module Yadis
class XRDSFetcher
def initialize(results)
@results = results
end
def fetch(url, body=nil, headers=nil, redirect_limit=nil)
return @results.shift
end
nil
end
end
class ProxyQueryTestCase < Test::Unit::TestCase
def setup
@proxy_url = 'http://xri.example.com/'
@proxy = XRI::ProxyResolver.new(@proxy_url)
@servicetype = 'xri://+i-service*(+forwarding)*($v*1.0)'
@servicetype_enc = 'xri%3A%2F%2F%2Bi-service%2A%28%2Bforwarding%29%2A%28%24v%2A1.0%29'
end
def unesc(s)
CGI::unescape(s)
end
def test_proxy_url
st = @servicetype
ste = @servicetype_enc
args_esc = "_xrd_r=application%2Fxrds%2Bxml&_xrd_t=" + ste
pqu = @proxy.method('query_url')
h = @proxy_url
assert_equal(unesc(h + '=foo?' + args_esc), unesc(pqu.call('=foo', st)))
assert_equal(unesc(h + '=foo/bar?baz&' + args_esc),
unesc(pqu.call('=foo/bar?baz', st)))
assert_equal(unesc(h + '=foo/bar?baz=quux&' + args_esc),
unesc(pqu.call('=foo/bar?baz=quux', st)))
assert_equal(unesc(h + '=foo/bar?mi=fa&so=la&' + args_esc),
unesc(pqu.call('=foo/bar?mi=fa&so=la', st)))
# With no service endpoint selection.
args_esc = "_xrd_r=application%2Fxrds%2Bxml"
assert_equal(unesc(h + '=foo?' + args_esc), unesc(pqu.call('=foo', nil)))
end
def test_proxy_url_qmarks
st = @servicetype
ste = @servicetype_enc
args_esc = "_xrd_r=application%2Fxrds%2Bxml&_xrd_t=" + ste
pqu = @proxy.method('query_url')
h = @proxy_url
assert_equal(unesc(h + '=foo/bar?' + args_esc),
unesc(pqu.call('=foo/bar??', st)))
assert_equal(unesc(h + '=foo/bar?' + args_esc),
unesc(pqu.call('=foo/bar???', st)))
end
end
end
end