Commit 45f85f6

mo khan <mo@mokhan.ca>
2022-03-30 20:58:34
feat: drop ruby 2.5 and 2.6 tag: v1.3.0
fix: upgrade to Ruby 2.7+ *args syntax. * https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/ fix: resolve deprecation warnings * https://github.com/rails/rails/pull/32313
1 parent 6e457e2
.github/workflows/ci.yml
@@ -2,43 +2,35 @@
 name: Continuous Integration
 on:
   push:
-    branches: [main]
   pull_request:
-    branches: [main]
 jobs:
   test:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        ruby-version: ['2.5', '2.6', '2.7']
+        ruby-version: ['2.7', '3.0', '3.1']
     steps:
       - uses: actions/checkout@v2
-      - name: Set up Ruby
-        uses: ruby/setup-ruby@v1
+      - uses: ruby/setup-ruby@v1
         with:
           ruby-version: ${{ matrix.ruby-version }}
           bundler-cache: true
-      - name: Running tests…
-        run: sh bin/test
+      - run: sh bin/test
   style:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
-      - name: Set up Ruby
-        uses: ruby/setup-ruby@v1
+      - uses: ruby/setup-ruby@v1
         with:
           ruby-version: '2.7'
           bundler-cache: true
-      - name: Running style checks…
-        run: sh bin/style
+      - run: sh bin/style
   audit:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
-      - name: Set up Ruby
-        uses: ruby/setup-ruby@v1
+      - uses: ruby/setup-ruby@v1
         with:
           ruby-version: '2.7'
           bundler-cache: true
-      - name: Running audit…
-        run: sh bin/audit
+      - run: sh bin/audit
lib/saml/kit/concerns/buildable.rb
@@ -9,20 +9,20 @@ module Saml
       extend ActiveSupport::Concern
 
       class_methods do
-        def build(*args)
-          builder(*args) do |builder|
+        def build(*args, **kwargs)
+          builder(*args, **kwargs) do |builder|
             yield builder if block_given?
           end.build
         end
 
-        def build_xml(*args)
-          builder(*args) do |builder|
+        def build_xml(*args, **kwargs)
+          builder(*args, **kwargs) do |builder|
             yield builder if block_given?
           end.to_xml
         end
 
-        def builder(*args)
-          builder_class.new(*args).tap do |builder|
+        def builder(*args, **kwargs)
+          builder_class.new(*args, **kwargs).tap do |builder|
             yield builder if block_given?
           end
         end
lib/saml/kit/concerns/translatable.rb
@@ -9,7 +9,7 @@ module Saml
       # @!visibility private
       def error_message(attribute, options = {})
         default_options = { scope: "saml/kit.errors.#{name}" }
-        I18n.translate(attribute, default_options.merge(options))
+        I18n.translate(attribute, **default_options.merge(options))
       end
     end
   end
lib/saml/kit/concerns/trustable.rb
@@ -53,7 +53,7 @@ module Saml
         return unless signature.present?
 
         signature.valid?
-        signature.errors.each do |attribute, error|
+        signature.each_error do |attribute, error|
           errors.add(attribute, error)
         end
       end
lib/saml/kit/concerns/validatable.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module Saml
+  module Kit
+    # This module is responsible for
+    # providing an adapter to the ActiveModel::Validations
+    # module.
+    module Validatable
+      extend ActiveSupport::Concern
+      include ActiveModel::Validations
+
+      def each_error
+        if Gem::Requirement.new('>= 6.1').satisfied_by?(ActiveModel.version)
+          errors.each do |error|
+            yield error.attribute, error.message
+          end
+        else
+          errors.each do |attribute, message|
+            yield attribute, message
+          end
+        end
+      end
+    end
+  end
+end
lib/saml/kit/assertion.rb
@@ -126,7 +126,7 @@ module Saml
       def must_have_valid_signature
         return if !signed? || signature.valid?
 
-        signature.errors.each do |attribute, message|
+        signature.each_error do |attribute, message|
           errors.add(attribute, message)
         end
       end
lib/saml/kit/composite_metadata.rb
@@ -51,9 +51,9 @@ module Saml
         @metadatum.each(&block)
       end
 
-      def method_missing(name, *args)
+      def method_missing(name, *args, **kwargs)
         if (target = find { |x| x.respond_to?(name) })
-          target.public_send(name, *args)
+          target.public_send(name, *args, **kwargs)
         else
           super
         end
lib/saml/kit/document.rb
@@ -4,7 +4,7 @@ module Saml
   module Kit
     # This class is a base class for SAML documents.
     class Document
-      include ActiveModel::Validations
+      include Validatable
       include Buildable
       include Translatable
       include Trustable
lib/saml/kit/metadata.rb
@@ -26,7 +26,7 @@ module Saml
     # for a list of options that can be specified.
     # {include:file:spec/examples/metadata_spec.rb}
     class Metadata
-      include ActiveModel::Validations
+      include Validatable
       include Buildable
       include Translatable
       include XmlParseable
@@ -192,7 +192,7 @@ module Saml
       def must_have_valid_signature
         return if !signature.present? || signature.valid?
 
-        signature.errors.each do |attribute, error|
+        signature.each_error do |attribute, error|
           errors.add(attribute, error)
         end
       end
lib/saml/kit/null_assertion.rb
@@ -6,7 +6,7 @@ module Saml
     # Null Object pattern for when a Response
     # is missing an Assertion.
     class NullAssertion
-      include ActiveModel::Validations
+      include Validatable
       include Translatable
       validate :invalid
 
lib/saml/kit/response.rb
@@ -43,9 +43,8 @@ module Saml
 
       def must_be_valid_assertion
         assertion.valid?
-        assertion.errors.each do |attribute, error|
-          attribute = :assertion if attribute == :base
-          errors.add(attribute, error)
+        assertion.each_error do |attribute, error|
+          errors.add(attribute == :base ? :assertion : attribute, error)
         end
       end
 
lib/saml/kit/signature.rb
@@ -6,7 +6,7 @@ module Saml
     # validating an xml digital signature
     # in an xml document.
     class Signature
-      include ActiveModel::Validations
+      include Validatable
       include Translatable
 
       validate :validate_signature
lib/saml/kit/version.rb
@@ -2,6 +2,6 @@
 
 module Saml
   module Kit
-    VERSION = '1.2.0'
+    VERSION = '1.3.0'
   end
 end
lib/saml/kit.rb
@@ -23,6 +23,7 @@ require 'saml/kit/concerns/respondable'
 require 'saml/kit/concerns/serializable'
 require 'saml/kit/concerns/translatable'
 require 'saml/kit/concerns/trustable'
+require 'saml/kit/concerns/validatable'
 require 'saml/kit/concerns/xml_parseable'
 require 'saml/kit/concerns/xml_templatable'
 require 'saml/kit/concerns/xsd_validatable'
spec/saml/kit/bindings/http_redirect_spec.rb
@@ -94,7 +94,7 @@ RSpec.describe Saml::Kit::Bindings::HttpRedirect do
 
     it 'returns an invalid request when the SAMLRequest is invalid' do
       expect do
-        subject.deserialize('SAMLRequest' => 'nonsense')
+        subject.deserialize({ 'SAMLRequest' => 'nonsense' })
       end.to raise_error(Zlib::DataError)
     end
 
@@ -115,7 +115,7 @@ RSpec.describe Saml::Kit::Bindings::HttpRedirect do
 
     it 'raises an error when the content is invalid' do
       expect do
-        subject.deserialize('SAMLResponse' => 'nonsense')
+        subject.deserialize({ 'SAMLResponse' => 'nonsense' })
       end.to raise_error(Zlib::DataError)
     end
 
spec/saml/kit/response_spec.rb
@@ -546,7 +546,7 @@ RSpec.describe Saml::Kit::Response do
 
     it 'parses the name id safely (CVE-2017-11428)' do
       raw = IO.read('spec/fixtures/response_node_text_attack.xml.base64')
-      subject = Saml::Kit::Bindings::HttpPost.new(location: '').deserialize('SAMLResponse' => raw)
+      subject = Saml::Kit::Bindings::HttpPost.new(location: '').deserialize({ 'SAMLResponse' => raw })
       expect(subject.name_id).to eql('support@onelogin.com')
       expect(subject.attributes[:surname]).to eql('smith')
     end
.rubocop.yml
@@ -12,7 +12,7 @@ AllCops:
     - 'spec/examples/**/*'
     - 'tmp/**/*'
     - 'vendor/**/*'
-  TargetRubyVersion: 2.5
+  TargetRubyVersion: 2.7
 
 Layout/ArgumentAlignment:
   EnforcedStyle: with_fixed_indentation
CHANGELOG.md
@@ -1,4 +1,4 @@
-Version 1.2.0
+Version 1.3.0
 
 # Changelog
 All notable changes to this project will be documented in this file.
@@ -8,6 +8,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+## [1.3.0] - 2022-03-30
+### Removed
+
+- Drop support for ruby 2.6
+- Drop support for ruby 2.5
+
+### Changed
+
+- fix: upgrade to Ruby 2.7+ `*args` syntax.
+- fix: resolve deprecation warnings
+
 ## [1.2.0] - 2021-02-04
 ### Changed
 - Use [ActiveModel::Errors#add](https://www.rubydoc.info/docs/rails/ActiveModel%2FErrors:add)
@@ -87,7 +98,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Removed
 - Removed optional SessionNotOnOrAfter attribute from AuthnStatement.
 
-[Unreleased]: https://github.com/xlgmokha/saml-kit/compare/v1.2.0...HEAD
+[Unreleased]: https://github.com/xlgmokha/saml-kit/compare/v1.3.0...HEAD
+[1.3.0]: https://github.com/xlgmokha/saml-kit/compare/v1.2.0...v1.3.0
 [1.2.0]: https://github.com/xlgmokha/saml-kit/compare/v1.1.0...v1.2.0
 [1.1.0]: https://github.com/xlgmokha/saml-kit/compare/v1.0.31...v1.1.0
 [1.0.31]: https://github.com/xlgmokha/saml-kit/compare/v1.0.30...v1.0.31
Gemfile.lock
@@ -1,7 +1,7 @@
 PATH
   remote: .
   specs:
-    saml-kit (1.2.0)
+    saml-kit (1.3.0)
       activemodel (>= 5.1, < 8.0)
       net-hippie (>= 0.1, < 2.0)
       xml-kit (~> 0.4)
@@ -27,7 +27,7 @@ GEM
     bundler-audit (0.9.0.1)
       bundler (>= 1.2.0, < 3)
       thor (~> 1.0)
-    concurrent-ruby (1.1.9)
+    concurrent-ruby (1.1.10)
     crack (0.4.5)
       rexml
     diff-lcs (1.5.0)
@@ -36,17 +36,17 @@ GEM
     hashdiff (1.0.1)
     i18n (1.10.0)
       concurrent-ruby (~> 1.0)
-    mini_portile2 (2.6.1)
+    mini_portile2 (2.8.0)
     minitest (5.15.0)
     net-hippie (1.1.1)
-    nokogiri (1.12.5)
-      mini_portile2 (~> 2.6.1)
+    nokogiri (1.13.3)
+      mini_portile2 (~> 2.8.0)
       racc (~> 1.4)
     parallel (1.20.1)
     parser (3.0.0.0)
       ast (~> 2.4.1)
     public_suffix (4.0.6)
-    racc (1.5.2)
+    racc (1.6.0)
     rainbow (3.0.0)
     rake (13.0.6)
     regexp_parser (2.0.3)
saml-kit.gemspec
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
   spec.description   = 'A simple toolkit for working with SAML.'
   spec.homepage      = 'https://github.com/xlgmokha/saml-kit'
   spec.license       = 'MIT'
-  spec.required_ruby_version = '~> 2.5'
+  spec.required_ruby_version = '>= 2.7.0'
 
   spec.files = `git ls-files -z`.split("\x0").reject do |f|
     (