@@ -36,7 +36,7 @@ def parse_remote(url, validate_cert = true, options = {})
3636 end
3737
3838 # Parse the Identity Provider metadata and update the settings with the IdP values
39- # @param idp_metadata [String]
39+ # @param idp_metadata [String]
4040 # @param options [Hash] :settings to provide the OneLogin::RubySaml::Settings object or an hash for Settings overrides
4141 #
4242 def parse ( idp_metadata , options = { } )
@@ -67,36 +67,28 @@ def parse(idp_metadata, options = {})
6767 # @raise [HttpError] Failure to fetch remote IdP metadata
6868 def get_idp_metadata ( url , validate_cert )
6969 uri = URI . parse ( url )
70- if uri . scheme == "http"
71- response = Net ::HTTP . get_response ( uri )
72- meta_text = response . body
73- elsif uri . scheme == "https"
74- http = Net ::HTTP . new ( uri . host , uri . port )
70+ raise ArgumentError . new ( "url must begin with http or https" ) unless /^https?/ =~ uri . scheme
71+ http = Net ::HTTP . new ( uri . host , uri . port )
72+
73+ if uri . scheme == "https"
7574 http . use_ssl = true
7675 # Most IdPs will probably use self signed certs
77- if validate_cert
78- http . verify_mode = OpenSSL ::SSL ::VERIFY_PEER
79-
80- # Net::HTTP in Ruby 1.8 did not set the default certificate store
81- # automatically when VERIFY_PEER was specified.
82- if RUBY_VERSION < '1.9' && !http . ca_file && !http . ca_path && !http . cert_store
83- http . cert_store = OpenSSL ::SSL ::SSLContext ::DEFAULT_CERT_STORE
84- end
85- else
86- http . verify_mode = OpenSSL ::SSL ::VERIFY_NONE
76+ http . verify_mode = validate_cert ? OpenSSL ::SSL ::VERIFY_PEER : OpenSSL ::SSL ::VERIFY_NONE
77+
78+ # Net::HTTP in Ruby 1.8 did not set the default certificate store
79+ # automatically when VERIFY_PEER was specified.
80+ if RUBY_VERSION < '1.9' && !http . ca_file && !http . ca_path && !http . cert_store
81+ http . cert_store = OpenSSL ::SSL ::SSLContext ::DEFAULT_CERT_STORE
8782 end
88- get = Net ::HTTP ::Get . new ( uri . request_uri )
89- response = http . request ( get )
90- meta_text = response . body
91- else
92- raise ArgumentError . new ( "url must begin with http or https" )
9383 end
9484
95- unless response . is_a? Net ::HTTPSuccess
96- raise OneLogin :: RubySaml :: HttpError . new ( "Failed to fetch idp metadata" )
97- end
85+ get = Net ::HTTP :: Get . new ( uri . request_uri )
86+ response = http . request ( get )
87+ return response . body if response . is_a? Net :: HTTPSuccess
9888
99- meta_text
89+ raise OneLogin ::RubySaml ::HttpError . new (
90+ "Failed to fetch idp metadata: #{ response . code } : #{ response . message } "
91+ )
10092 end
10193
10294 # @return [String|nil] IdP Entity ID value if exists
0 commit comments