C0 code coverage information
Generated on Fri Jul 11 15:55:32 -0700 2008 with rcov 0.7.0
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
1
2 require 'openid/util'
3 require 'openid/fetchers'
4 require 'openid/yadis/constants'
5 require 'openid/yadis/parsehtml'
6
7 module OpenID
8
9 # Raised when a error occurs in the discovery process
10 class DiscoveryFailure < OpenIDError
11 attr_accessor :identity_url, :http_response
12
13 def initialize(message, http_response)
14 super(message)
15 @identity_url = nil
16 @http_response = http_response
17 end
18 end
19
20 module Yadis
21
22 # Contains the result of performing Yadis discovery on a URI
23 class DiscoveryResult
24
25 # The result of following redirects from the request_uri
26 attr_accessor :normalize_uri
27
28 # The URI from which the response text was returned (set to
29 # nil if there was no XRDS document found)
30 attr_accessor :xrds_uri
31
32 # The content-type returned with the response_text
33 attr_accessor :content_type
34
35 # The document returned from the xrds_uri
36 attr_accessor :response_text
37
38 attr_accessor :request_uri, :normalized_uri
39
40 def initialize(request_uri)
41 # Initialize the state of the object
42 #
43 # sets all attributes to None except the request_uri
44 @request_uri = request_uri
45 @normalized_uri = nil
46 @xrds_uri = nil
47 @content_type = nil
48 @response_text = nil
49 end
50
51 # Was the Yadis protocol's indirection used?
52 def used_yadis_location?
53 return @normalized_uri != @xrds_uri
54 end
55
56 # Is the response text supposed to be an XRDS document?
57 def is_xrds
58 return (used_yadis_location?() or
59 @content_type == YADIS_CONTENT_TYPE)
60 end
61 end
62
63 # Discover services for a given URI.
64 #
65 # uri: The identity URI as a well-formed http or https URI. The
66 # well-formedness and the protocol are not checked, but the
67 # results of this function are undefined if those properties do
68 # not hold.
69 #
70 # returns a DiscoveryResult object
71 #
72 # Raises DiscoveryFailure when the HTTP response does not have
73 # a 200 code.
74 def self.discover(uri)
75 result = DiscoveryResult.new(uri)
76 begin
77 resp = OpenID.fetch(uri, nil, {'Accept' => YADIS_ACCEPT_HEADER})
78 rescue Exception
79 raise DiscoveryFailure.new("Failed to fetch identity URL #{uri} : #{$!}", $!)
80 end
81 if resp.code != "200" and resp.code != "206"
82 raise DiscoveryFailure.new(
83 "HTTP Response status from identity URL host is not \"200\"."\
84 "Got status #{resp.code.inspect} for #{resp.final_url}", resp)
85 end
86
87 # Note the URL after following redirects
88 result.normalized_uri = resp.final_url
89
90 # Attempt to find out where to go to discover the document or if
91 # we already have it
92 result.content_type = resp['content-type']
93
94 result.xrds_uri = self.where_is_yadis?(resp)
95
96 if result.xrds_uri and result.used_yadis_location?
97 begin
98 resp = OpenID.fetch(result.xrds_uri)
99 rescue
100 raise DiscoveryFailure.new("Failed to fetch Yadis URL #{result.xrds_uri} : #{$!}", $!)
101 end
102 if resp.code != "200" and resp.code != "206"
103 exc = DiscoveryFailure.new(
104 "HTTP Response status from Yadis host is not \"200\". " +
105 "Got status #{resp.code.inspect} for #{resp.final_url}", resp)
106 exc.identity_url = result.normalized_uri
107 raise exc
108 end
109
110 result.content_type = resp['content-type']
111 end
112
113 result.response_text = resp.body
114 return result
115 end
116
117 # Given a HTTPResponse, return the location of the Yadis
118 # document.
119 #
120 # May be the URL just retrieved, another URL, or None, if I
121 # can't find any.
122 #
123 # [non-blocking]
124 def self.where_is_yadis?(resp)
125 # Attempt to find out where to go to discover the document or if
126 # we already have it
127 content_type = resp['content-type']
128
129 # According to the spec, the content-type header must be an
130 # exact match, or else we have to look for an indirection.
131 if (!content_type.nil? and !content_type.to_s.empty? and
132 content_type.split(';', 2)[0].downcase == YADIS_CONTENT_TYPE)
133 return resp.final_url
134 else
135 # Try the header
136 yadis_loc = resp[YADIS_HEADER_NAME.downcase]
137
138 if yadis_loc.nil?
139 # Parse as HTML if the header is missing.
140 #
141 # XXX: do we want to do something with content-type, like
142 # have a whitelist or a blacklist (for detecting that it's
143 # HTML)?
144 yadis_loc = Yadis.html_yadis_location(resp.body)
145 end
146 end
147
148 return yadis_loc
149 end
150
151 end
152
153 end
Generated using the rcov code coverage analysis tool for Ruby version 0.7.0.