Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields committed Mar 8, 2023
1 parent 4143536 commit e76833f
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 154 deletions.
83 changes: 25 additions & 58 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-03-08 09:07:11 UTC using RuboCop version 1.45.1.
# on 2023-03-08 09:38:19 UTC using RuboCop version 1.45.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 11
# Offense count: 18
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterGuardClause:
Exclude:
Expand All @@ -16,6 +16,7 @@ Layout/EmptyLineAfterGuardClause:
- 'lib/onelogin/ruby-saml/logoutresponse.rb'
- 'lib/onelogin/ruby-saml/response.rb'
- 'lib/onelogin/ruby-saml/saml_message.rb'
- 'lib/onelogin/ruby-saml/slo_logoutrequest.rb'
- 'lib/onelogin/ruby-saml/slo_logoutresponse.rb'

# Offense count: 10
Expand Down Expand Up @@ -94,7 +95,7 @@ Layout/IndentationConsistency:
Exclude:
- 'lib/onelogin/ruby-saml/authrequest.rb'

# Offense count: 3
# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Width, AllowedPatterns.
Layout/IndentationWidth:
Expand Down Expand Up @@ -205,23 +206,18 @@ Lint/UselessAssignment:
# Offense count: 39
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 101
Max: 100

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 27

# Offense count: 4
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 4

# Offense count: 9
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 668
Max: 652

# Offense count: 23
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand All @@ -231,7 +227,7 @@ Metrics/CyclomaticComplexity:
# Offense count: 58
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 68
Max: 63

# Offense count: 2
# Configuration parameters: Max, CountKeywordArgs.
Expand Down Expand Up @@ -379,15 +375,14 @@ Style/Documentation:
- 'lib/onelogin/ruby-saml/logging.rb'
- 'lib/xml_security.rb'

# Offense count: 3
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
Style/GuardClause:
Exclude:
- 'lib/onelogin/ruby-saml/response.rb'
- 'lib/onelogin/ruby-saml/utils.rb'

# Offense count: 69
# Offense count: 60
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
Expand All @@ -403,24 +398,30 @@ Style/IfUnlessModifier:
- 'lib/onelogin/ruby-saml/utils.rb'
- 'lib/xml_security.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/NegatedIfElseCondition:
# Offense count: 15
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'lib/onelogin/ruby-saml/authrequest.rb'
- 'lib/onelogin/ruby-saml/idp_metadata_parser.rb'
- 'lib/onelogin/ruby-saml/logoutresponse.rb'
- 'lib/onelogin/ruby-saml/metadata.rb'
- 'lib/onelogin/ruby-saml/response.rb'
- 'lib/onelogin/ruby-saml/saml_message.rb'
- 'lib/onelogin/ruby-saml/settings.rb'
- 'lib/onelogin/ruby-saml/slo_logoutrequest.rb'
- 'lib/onelogin/ruby-saml/utils.rb'
- 'lib/xml_security.rb'

# Offense count: 7
# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'lib/onelogin/ruby-saml/idp_metadata_parser.rb'
- 'lib/onelogin/ruby-saml/metadata.rb'
- 'lib/onelogin/ruby-saml/response.rb'
- 'lib/onelogin/ruby-saml/saml_message.rb'
- 'lib/onelogin/ruby-saml/utils.rb'

# Offense count: 452
# Offense count: 450
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Expand All @@ -442,41 +443,7 @@ Style/StringLiterals:
- 'lib/onelogin/ruby-saml/utils.rb'
- 'lib/xml_security.rb'

# Offense count: 8
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MinSize.
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: brackets

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
Style/TernaryParentheses:
Exclude:
- 'lib/onelogin/ruby-saml/authrequest.rb'
- 'lib/onelogin/ruby-saml/logoutrequest.rb'
- 'lib/onelogin/ruby-saml/slo_logoutresponse.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInHashLiteral:
Exclude:
- 'lib/onelogin/ruby-saml/authrequest.rb'
- 'lib/onelogin/ruby-saml/idp_metadata_parser.rb'
- 'lib/onelogin/ruby-saml/metadata.rb'

# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/ZeroLengthPredicate:
Exclude:
- 'lib/onelogin/ruby-saml/attribute_service.rb'
- 'lib/onelogin/ruby-saml/response.rb'

# Offense count: 96
# Offense count: 100
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/attribute_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def configure(&block)
# @return [Boolean] True if the AttributeService object has been initialized and set with the required values
# (has attributes and a name)
def configured?
@attributes.length > 0 && !@name.nil?
!@attributes.empty? && !@name.nil?
end

# Set a name to the service
Expand Down
10 changes: 5 additions & 5 deletions lib/onelogin/ruby-saml/authrequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def request_id
#
def create(settings, params = {})
params = create_params(settings, params)
params_prefix = (settings.idp_sso_service_url =~ /\?/) ? '&' : '?'
params_prefix = /\?/.match?(settings.idp_sso_service_url) ? '&' : '?'
saml_request = CGI.escape(params.delete("SAMLRequest"))
request_params = +"#{params_prefix}SAMLRequest=#{saml_request}"
params.each_pair do |key, value|
Expand Down Expand Up @@ -152,14 +152,14 @@ def create_xml_document(settings)

if settings.authn_context || settings.authn_context_decl_ref

if !settings.authn_context_comparison.nil?
comparison = settings.authn_context_comparison
else
if settings.authn_context_comparison.nil?
comparison = 'exact'
else
comparison = settings.authn_context_comparison
end

requested_context = root.add_element "samlp:RequestedAuthnContext", {
"Comparison" => comparison,
"Comparison" => comparison
}

unless settings.authn_context.nil?
Expand Down
4 changes: 2 additions & 2 deletions lib/onelogin/ruby-saml/idp_metadata_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module Vocabulary

# fetch IdP descriptors from a metadata document
def self.get_idps(metadata_document, only_entity_id=nil)
path = "//md:EntityDescriptor#{('[@entityID="' + only_entity_id + '"]') if only_entity_id}/md:IDPSSODescriptor"
path = "//md:EntityDescriptor#{"[@entityID=\"#{only_entity_id}\"]" if only_entity_id}/md:IDPSSODescriptor"
REXML::XPath.match(
metadata_document,
path,
Expand Down Expand Up @@ -238,7 +238,7 @@ def to_hash(options = {})
idp_cert_fingerprint: nil,
idp_cert_multi: nil,
valid_until: valid_until,
cache_duration: cache_duration,
cache_duration: cache_duration
}.tap do |response_hash|
merge_certificates_into(response_hash) unless certificates.nil?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/logoutrequest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def request_id
#
def create(settings, params={})
params = create_params(settings, params)
params_prefix = (settings.idp_slo_service_url =~ /\?/) ? '&' : '?'
params_prefix = /\?/.match?(settings.idp_slo_service_url) ? '&' : '?'
saml_request = CGI.escape(params.delete("SAMLRequest"))
request_params = +"#{params_prefix}SAMLRequest=#{saml_request}"
params.each_pair do |key, value|
Expand Down
14 changes: 7 additions & 7 deletions lib/onelogin/ruby-saml/logoutresponse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ def status_message
def validate(collect_errors = false)
reset_errors!

validations = [
:valid_state?,
:validate_success_status,
:validate_structure,
:valid_in_response_to?,
:valid_issuer?,
:validate_signature
validations = %i[
valid_state?
validate_success_status
validate_structure
valid_in_response_to?
valid_issuer?
validate_signature
]

if collect_errors
Expand Down
4 changes: 2 additions & 2 deletions lib/onelogin/ruby-saml/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def add_root_element(meta_doc, settings, valid_until, cache_duration)
root.attributes["ID"] = OneLogin::RubySaml::Utils.uuid
root.attributes["entityID"] = settings.sp_entity_id if settings.sp_entity_id
root.attributes["validUntil"] = valid_until.utc.strftime('%Y-%m-%dT%H:%M:%SZ') if valid_until
root.attributes["cacheDuration"] = "PT" + cache_duration.to_s + "S" if cache_duration
root.attributes["cacheDuration"] = "PT#{cache_duration}S" if cache_duration
root
end

def add_sp_sso_element(root, settings)
root.add_element "md:SPSSODescriptor", {
"protocolSupportEnumeration" => "urn:oasis:names:tc:SAML:2.0:protocol",
"AuthnRequestsSigned" => settings.security[:authn_requests_signed],
"WantAssertionsSigned" => settings.security[:want_assertions_signed],
"WantAssertionsSigned" => settings.security[:want_assertions_signed]
}
end

Expand Down

0 comments on commit e76833f

Please sign in to comment.