Skip to content

Commit a15c183

Browse files
authored
Merge pull request SAML-Toolkits#458 from davidlibrera/refactor/warnings
Remove ruby 2.4+ warnings
2 parents 10e082b + c8c1b5e commit a15c183

File tree

10 files changed

+47
-40
lines changed

10 files changed

+47
-40
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ rvm:
88
- 2.2.0
99
- 2.3.0
1010
- 2.4.0
11+
- 2.5.0
1112
- ree
1213
- jruby-1.7.21
1314
- jruby-9.0.0.0

lib/onelogin/ruby-saml/attribute_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def initialize
1616
end
1717

1818
def configure(&block)
19-
instance_eval &block
19+
instance_eval(&block)
2020
end
2121

2222
# @return [Boolean] True if the AttributeService object has been initialized and set with the required values

lib/onelogin/ruby-saml/logging.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ class Logging
77
DEFAULT_LOGGER = ::Logger.new(STDOUT)
88

99
def self.logger
10-
@logger || (defined?(::Rails) && Rails.respond_to?(:logger) && Rails.logger) || DEFAULT_LOGGER
10+
@logger ||= begin
11+
(defined?(::Rails) && Rails.respond_to?(:logger) && Rails.logger) ||
12+
DEFAULT_LOGGER
13+
end
1114
end
1215

1316
def self.logger=(logger)

lib/onelogin/ruby-saml/logoutresponse.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Logoutresponse < SamlMessage
2424
# Constructs the Logout Response. A Logout Response Object that is an extension of the SamlMessage class.
2525
# @param response [String] A UUEncoded logout response from the IdP.
2626
# @param settings [OneLogin::RubySaml::Settings|nil] Toolkit settings
27-
# @param options [Hash] Extra parameters.
27+
# @param options [Hash] Extra parameters.
2828
# :matches_request_id It will validate that the logout response matches the ID of the request.
2929
# :get_params GET Parameters, including the SAMLResponse
3030
# :relax_signature_validation to accept signatures if no idp certificate registered on settings
@@ -50,7 +50,7 @@ def initialize(response, settings = nil, options = {})
5050
# Checks if the Status has the "Success" code
5151
# @return [Boolean] True if the StatusCode is Sucess
5252
# @raise [ValidationError] if soft == false and validation fails
53-
#
53+
#
5454
def success?
5555
unless status_code == "urn:oasis:names:tc:SAML:2.0:status:Success"
5656
return append_error("Bad status code. Expected <urn:oasis:names:tc:SAML:2.0:status:Success>, but was: <#@status_code>")
@@ -146,7 +146,7 @@ def validate_success_status
146146

147147
# Validates the Logout Response against the specified schema.
148148
# @return [Boolean] True if the XML is valid, otherwise False if soft=True
149-
# @raise [ValidationError] if soft == false and validation fails
149+
# @raise [ValidationError] if soft == false and validation fails
150150
#
151151
def validate_structure
152152
unless valid_saml?(document, soft)
@@ -205,7 +205,7 @@ def valid_issuer?
205205
# Validates the Signature if it exists and the GET parameters are provided
206206
# @return [Boolean] True if not contains a Signature or if the Signature is valid, otherwise False if soft=True
207207
# @raise [ValidationError] if soft == false and validation fails
208-
#
208+
#
209209
def validate_signature
210210
return true unless !options.nil?
211211
return true unless options.has_key? :get_params
@@ -240,9 +240,9 @@ def validate_signature
240240
)
241241
else
242242
valid = false
243-
idp_certs[:signing].each do |idp_cert|
243+
idp_certs[:signing].each do |signing_idp_cert|
244244
valid = OneLogin::RubySaml::Utils.verify_signature(
245-
:cert => idp_cert,
245+
:cert => signing_idp_cert,
246246
:sig_alg => options[:get_params]['SigAlg'],
247247
:signature => options[:get_params]['Signature'],
248248
:query_string => query_string
@@ -257,7 +257,7 @@ def validate_signature
257257
error_msg = "Invalid Signature on Logout Response"
258258
return append_error(error_msg)
259259
end
260-
true
260+
true
261261
end
262262

263263
end

lib/onelogin/ruby-saml/response.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,10 @@ def attributes
171171
# identify the subject in an SP rather than email or other less opaque attributes
172172
# NameQualifier, if present is prefixed with a "/" to the value
173173
else
174-
REXML::XPath.match(e,'a:NameID', { "a" => ASSERTION }).collect{|n|
175-
(n.attributes['NameQualifier'] ? n.attributes['NameQualifier'] +"/" : '') + Utils.element_text(n)
176-
}
174+
REXML::XPath.match(e,'a:NameID', { "a" => ASSERTION }).collect do |n|
175+
base_path = n.attributes['NameQualifier'] ? "#{n.attributes['NameQualifier']}/" : ''
176+
base_path + Utils.element_text(n)
177+
end
177178
end
178179
}
179180

@@ -221,8 +222,8 @@ def status_code
221222
"/p:Response/p:Status/p:StatusCode/p:StatusCode",
222223
{ "p" => PROTOCOL }
223224
)
224-
statuses = nodes.collect do |node|
225-
node.attributes["Value"]
225+
statuses = nodes.collect do |inner_node|
226+
inner_node.attributes["Value"]
226227
end
227228
extra_code = statuses.join(" | ")
228229
if extra_code
@@ -288,7 +289,6 @@ def issuers
288289
raise ValidationError.new(error_msg)
289290
end
290291

291-
doc = decrypted_document.nil? ? document : decrypted_document
292292
issuer_assertion_nodes = xpath_from_signed_assertion("/a:Issuer")
293293
unless issuer_assertion_nodes.size == 1
294294
error_msg = "Issuer of the Assertion not found or multiple."

lib/onelogin/ruby-saml/saml_message.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def id(document)
6262
# @param document [REXML::Document] The message that will be validated
6363
# @param soft [Boolean] soft Enable or Disable the soft mode (In order to raise exceptions when the message is invalid or not)
6464
# @return [Boolean] True if the XML is valid, otherwise False, if soft=True
65-
# @raise [ValidationError] if soft == false and validation fails
65+
# @raise [ValidationError] if soft == false and validation fails
6666
#
6767
def valid_saml?(document, soft = true)
6868
begin
@@ -74,9 +74,9 @@ def valid_saml?(document, soft = true)
7474
raise ValidationError.new("XML load failed: #{error.message}")
7575
end
7676

77-
SamlMessage.schema.validate(xml).map do |error|
77+
SamlMessage.schema.validate(xml).map do |schema_error|
7878
return false if soft
79-
raise ValidationError.new("#{error.message}\n\n#{xml.to_s}")
79+
raise ValidationError.new("#{schema_error.message}\n\n#{xml.to_s}")
8080
end
8181
end
8282

lib/onelogin/ruby-saml/slo_logoutrequest.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class SloLogoutrequest < SamlMessage
2424

2525
# Constructs the Logout Request. A Logout Request Object that is an extension of the SamlMessage class.
2626
# @param request [String] A UUEncoded Logout Request from the IdP.
27-
# @param options [Hash] :settings to provide the OneLogin::RubySaml::Settings object
27+
# @param options [Hash] :settings to provide the OneLogin::RubySaml::Settings object
2828
# Or :allowed_clock_drift for the logout request validation process to allow a clock drift when checking dates with
29-
# Or :relax_signature_validation to accept signatures if no idp certificate registered on settings
29+
# Or :relax_signature_validation to accept signatures if no idp certificate registered on settings
3030
#
3131
# @raise [ArgumentError] If Request is nil
3232
#
@@ -192,7 +192,7 @@ def validate_not_on_or_after
192192

193193
# Validates the Logout Request against the specified schema.
194194
# @return [Boolean] True if the XML is valid, otherwise False if soft=True
195-
# @raise [ValidationError] if soft == false and validation fails
195+
# @raise [ValidationError] if soft == false and validation fails
196196
#
197197
def validate_structure
198198
unless valid_saml?(document, soft)
@@ -202,7 +202,7 @@ def validate_structure
202202
true
203203
end
204204

205-
# Validates that the Logout Request provided in the initialization is not empty,
205+
# Validates that the Logout Request provided in the initialization is not empty,
206206
# @return [Boolean] True if the required info is found, otherwise False if soft=True
207207
# @raise [ValidationError] if soft == false and validation fails
208208
#
@@ -289,9 +289,9 @@ def validate_signature
289289
)
290290
else
291291
valid = false
292-
idp_certs[:signing].each do |idp_cert|
292+
idp_certs[:signing].each do |signing_idp_cert|
293293
valid = OneLogin::RubySaml::Utils.verify_signature(
294-
:cert => idp_cert,
294+
:cert => signing_idp_cert,
295295
:sig_alg => options[:get_params]['SigAlg'],
296296
:signature => options[:get_params]['Signature'],
297297
:query_string => query_string

lib/onelogin/ruby-saml/utils.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def self.format_cert(cert)
3232
formatted_cert.join("\n")
3333
else
3434
cert = cert.gsub(/\-{5}\s?(BEGIN|END) CERTIFICATE\s?\-{5}/, "")
35-
cert = cert.gsub(/[\n\r\s]/, "")
35+
cert = cert.gsub(/\r/, "")
36+
cert = cert.gsub(/\n/, "")
37+
cert = cert.gsub(/\s/, "")
3638
cert = cert.scan(/.{1,64}/)
3739
cert = cert.join("\n")
3840
"-----BEGIN CERTIFICATE-----\n#{cert}\n-----END CERTIFICATE-----"
@@ -51,7 +53,9 @@ def self.format_private_key(key)
5153
# is this an rsa key?
5254
rsa_key = key.match("RSA PRIVATE KEY")
5355
key = key.gsub(/\-{5}\s?(BEGIN|END)( RSA)? PRIVATE KEY\s?\-{5}/, "")
54-
key = key.gsub(/[\n\r\s]/, "")
56+
key = key.gsub(/\n/, "")
57+
key = key.gsub(/\r/, "")
58+
key = key.gsub(/\s/, "")
5559
key = key.scan(/.{1,64}/)
5660
key = key.join("\n")
5761
key_label = rsa_key ? "RSA PRIVATE KEY" : "PRIVATE KEY"
@@ -98,7 +102,7 @@ def self.build_query_from_raw_parts(params)
98102
# @param rawparams [Hash] Raw GET Parameters
99103
# @param params [Hash] GET Parameters
100104
# @return [Hash] New raw parameters
101-
#
105+
#
102106
def self.prepare_raw_get_params(rawparams, params)
103107
rawparams ||= {}
104108

@@ -107,7 +111,7 @@ def self.prepare_raw_get_params(rawparams, params)
107111
end
108112
if rawparams['SAMLResponse'].nil? && !params['SAMLResponse'].nil?
109113
rawparams['SAMLResponse'] = CGI.escape(params['SAMLResponse'])
110-
end
114+
end
111115
if rawparams['RelayState'].nil? && !params['RelayState'].nil?
112116
rawparams['RelayState'] = CGI.escape(params['RelayState'])
113117
end
@@ -136,16 +140,16 @@ def self.verify_signature(params)
136140
# @param status_code [String] StatusCode value
137141
# @param status_message [Strig] StatusMessage value
138142
# @return [String] The status error message
139-
def self.status_error_msg(error_msg, status_code = nil, status_message = nil)
140-
unless status_code.nil?
141-
if status_code.include? "|"
142-
status_codes = status_code.split(' | ')
143+
def self.status_error_msg(error_msg, raw_status_code = nil, status_message = nil)
144+
unless raw_status_code.nil?
145+
if raw_status_code.include? "|"
146+
status_codes = raw_status_code.split(' | ')
143147
values = status_codes.collect do |status_code|
144148
status_code.split(':').last
145149
end
146150
printable_code = values.join(" => ")
147151
else
148-
printable_code = status_code.split(':').last
152+
printable_code = raw_status_code.split(':').last
149153
end
150154
error_msg << ', was ' + printable_code
151155
end

lib/xml_security.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Document < BaseDocument
9191
ENVELOPED_SIG = "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
9292
INC_PREFIX_LIST = "#default samlp saml ds xs xsi md"
9393

94-
attr_accessor :uuid
94+
attr_writer :uuid
9595

9696
def uuid
9797
@uuid ||= begin
@@ -187,7 +187,7 @@ def compute_digest(document, digest_algorithm)
187187
class SignedDocument < BaseDocument
188188
include OneLogin::RubySaml::ErrorHandling
189189

190-
attr_accessor :signed_element_id
190+
attr_writer :signed_element_id
191191

192192
def initialize(response, errors = [])
193193
super(response)
@@ -211,7 +211,7 @@ def validate_document(idp_cert_fingerprint, soft = true, options = {})
211211
cert_text = Base64.decode64(base64_cert)
212212
begin
213213
cert = OpenSSL::X509::Certificate.new(cert_text)
214-
rescue OpenSSL::X509::CertificateError => e
214+
rescue OpenSSL::X509::CertificateError => _e
215215
return append_error("Certificate Error", soft)
216216
end
217217

@@ -254,7 +254,7 @@ def validate_document_with_cert(idp_cert)
254254
cert_text = Base64.decode64(base64_cert)
255255
begin
256256
cert = OpenSSL::X509::Certificate.new(cert_text)
257-
rescue OpenSSL::X509::CertificateError => e
257+
rescue OpenSSL::X509::CertificateError => _e
258258
return append_error("Certificate Error", soft)
259259
end
260260

@@ -318,10 +318,9 @@ def validate_signature(base64_cert, soft = true)
318318

319319
# check digests
320320
ref = REXML::XPath.first(sig_element, "//ds:Reference", {"ds"=>DSIG})
321-
uri = ref.attributes.get_attribute("URI").value
322321

323322
hashed_element = document.at_xpath("//*[@ID=$id]", nil, { 'id' => extract_signed_element_id })
324-
323+
325324
canon_algorithm = canon_algorithm REXML::XPath.first(
326325
ref,
327326
'//ds:CanonicalizationMethod',

ruby-saml.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
4444
s.add_development_dependency('mocha', '~> 0.14')
4545
s.add_development_dependency('rake', '~> 10')
4646
s.add_development_dependency('shoulda', '~> 2.11')
47-
s.add_development_dependency('simplecov','~> 0.9.0')
47+
s.add_development_dependency('simplecov')
4848
s.add_development_dependency('systemu', '~> 2')
4949
s.add_development_dependency('timecop', '<= 0.6.0')
5050

0 commit comments

Comments
 (0)