Commit ba22310
Changed files (11)
lib
saml
spec
saml
kit
bindings
lib/saml/kit/bindings/binding.rb
@@ -14,7 +14,7 @@ module Saml
binding == other
end
- def serialize(_builder, relay_state: nil)
+ def serialize(*)
[]
end
lib/saml/kit/builders/templates/service_provider_metadata.builder
@@ -12,6 +12,6 @@ xml.SPSSODescriptor descriptor_options do
xml.NameIDFormat format
end
acs_urls.each_with_index do |item, index|
- xml.AssertionConsumerService Binding: item[:binding], Location: item[:location], index: index, isDefault: index == 0
+ xml.AssertionConsumerService Binding: item[:binding], Location: item[:location], index: index, isDefault: index.zero?
end
end
lib/saml/kit/buildable.rb
@@ -4,19 +4,19 @@ module Saml
extend ActiveSupport::Concern
class_methods do
- def build(*args) # :yields builder
+ def build(*args)
builder(*args) do |builder|
yield builder if block_given?
end.build
end
- def build_xml(*args) # :yields builder
+ def build_xml(*args)
builder(*args) do |builder|
yield builder if block_given?
end.to_xml
end
- def builder(*args) # :yields builder
+ def builder(*args)
builder_class.new(*args).tap do |builder|
yield builder if block_given?
end
lib/saml/kit/composite_metadata.rb
@@ -30,12 +30,16 @@ module Saml
end
def method_missing(name, *args)
- if target = find { |x| x.respond_to?(name) }
+ if (target = find { |x| x.respond_to?(name) })
target.public_send(name, *args)
else
super
end
end
+
+ def respond_to_missing?(method, *)
+ find { |x| x.respond_to?(method) }
+ end
end
end
end
lib/saml/kit/configuration.rb
@@ -36,7 +36,7 @@ module Saml
# The total allowable clock drift for session timeout validation.
attr_accessor :clock_drift
- def initialize # :yields configuration
+ def initialize
@clock_drift = 30.seconds
@digest_method = :SHA256
@key_pairs = []
@@ -97,10 +97,10 @@ module Saml
private
def ensure_proper_use!(use)
- unless USES.include?(use)
- error_message = 'Use must be either :signing or :encryption'
- raise ArgumentError, error_message
- end
+ return if USES.include?(use)
+
+ error_message = 'Use must be either :signing or :encryption'
+ raise ArgumentError, error_message
end
end
end
lib/saml/kit/default_registry.rb
@@ -62,7 +62,7 @@ module Saml
# Yields each registered [Saml::Kit::Metadata] to the block.
def each
- @items.each do |_key, value|
+ @items.each_value do |value|
yield value
end
end
lib/saml/kit/identity_provider_metadata.rb
@@ -71,7 +71,7 @@ module Saml
# @param relay_state [Object] The RelayState to include the returned SAML params.
# @param configuration [Saml::Kit::Configuration] the configuration to use for generating the request.
# @return [Array] The url and saml params encoded using the rules for the specified binding.
- def login_request_for(binding:, relay_state: nil, configuration: Saml::Kit.configuration) # :yields builder
+ def login_request_for(binding:, relay_state: nil, configuration: Saml::Kit.configuration)
builder = Saml::Kit::AuthenticationRequest.builder(configuration: configuration) do |x|
x.embed_signature = want_authn_requests_signed
yield x if block_given?
lib/saml/kit/respondable.rb
@@ -33,10 +33,9 @@ module Saml
def must_match_request_id
return if request_id.nil?
+ return if in_response_to == request_id
- if in_response_to != request_id
- errors[:in_response_to] << error_message(:invalid_response_to)
- end
+ errors[:in_response_to] << error_message(:invalid_response_to)
end
end
end
lib/saml/kit/signature.rb
@@ -72,19 +72,22 @@ module Saml
return errors[:base].push(error_message(:empty)) if certificate.nil?
signature = Xmldsig::Signature.new(@node, 'ID=$uri or @Id')
- unless signature.valid?(certificate.x509)
- signature.errors.each do |attribute|
- errors.add(attribute, error_message(attribute))
- end
+ return if signature.valid?(certificate.x509)
+ signature.errors.each do |attribute|
+ errors.add(attribute, error_message(attribute))
end
end
def validate_certificate(now = Time.now.utc)
- if certificate.present? && !certificate.active?(now)
- errors.add(:certificate, error_message(:certificate,
- not_before: certificate.not_before,
- not_after: certificate.not_after))
- end
+ return unless certificate.present?
+ return if certificate.active?(now)
+
+ message = error_message(
+ :certificate,
+ not_before: certificate.not_before,
+ not_after: certificate.not_after
+ )
+ errors.add(:certificate, message)
end
def at_xpath(xpath)
spec/saml/kit/bindings/http_redirect_spec.rb
@@ -57,7 +57,7 @@ RSpec.describe Saml::Kit::Bindings::HttpRedirect do
expect(result).to be_trusted
end
- it 'deserializes the SAMLRequest to an AuthnRequest' do
+ it 'deserializes the SAMLRequest to an AuthnRequest with symbolized keys' do
url, = subject.serialize(Saml::Kit::AuthenticationRequest.builder)
result = subject.deserialize(query_params_from(url).symbolize_keys)
expect(result).to be_instance_of(Saml::Kit::AuthenticationRequest)
.rubocop.yml
@@ -47,8 +47,10 @@ Lint/InterpolationCheck:
Metrics/BlockLength:
Exclude:
- - 'Rakefile'
+ - '**/**/*.builder'
- '**/*.rake'
+ - '*.gemspec'
+ - 'Rakefile'
- 'spec/**/*.rb'
Metrics/ModuleLength:
@@ -56,9 +58,17 @@ Metrics/ModuleLength:
- 'spec/**/*.rb'
Metrics/LineLength:
+ Max: 160
Exclude:
- 'spec/**/*.rb'
+Naming/FileName:
+ Exclude:
+ - 'lib/saml-kit.rb'
+
+Style/Documentation:
+ Enabled: false
+
Style/StringLiterals:
EnforcedStyle: 'single_quotes'
@@ -76,3 +86,6 @@ RSpec/NamedSubject:
RSpec/NestedGroups:
Max: 7
+
+RSpec/SubjectStub:
+ Enabled: false