From 3fd021ceacd9208becc14895ad04da53e034d0b7 Mon Sep 17 00:00:00 2001 From: Mathieu Jobin Date: Tue, 3 Sep 2024 22:36:24 +0900 Subject: [PATCH 1/5] Set minimum test coverage (#207) * Set minimum test coverage to a very high value for testing * Update minimum coverage to actual current value --- spec/spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ffc9f9a8..d90955b7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,6 @@ # encoding: utf-8 require 'simplecov' +SimpleCov.minimum_coverage 96.45 SimpleCov.start do add_filter "/spec/" end From 94b00bcda10fbb790bcc05b96ab7b6563967fdf6 Mon Sep 17 00:00:00 2001 From: zogoo Date: Tue, 17 Sep 2024 23:20:12 +0200 Subject: [PATCH 2/5] [fix] Flaky test (#220) * Decode AuthnRequest params to XML format before pass to mock * Drop test case check --------- Co-authored-by: zogoo --- saml_idp.gemspec | 1 + spec/lib/saml_idp/controller_spec.rb | 2 +- spec/spec_helper.rb | 1 - spec/support/saml_request_macros.rb | 15 +++++++++++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/saml_idp.gemspec b/saml_idp.gemspec index 4c46a70d..ca7c836b 100644 --- a/saml_idp.gemspec +++ b/saml_idp.gemspec @@ -55,6 +55,7 @@ Gem::Specification.new do |s| s.add_development_dependency('capybara', '>= 2.16') s.add_development_dependency('rails', '>= 5.2') s.add_development_dependency('rake') + s.add_development_dependency('debug') s.add_development_dependency('rspec', '>= 3.7.0') s.add_development_dependency('ruby-saml', '>= 1.7.2') s.add_development_dependency('simplecov') diff --git a/spec/lib/saml_idp/controller_spec.rb b/spec/lib/saml_idp/controller_spec.rb index 883e0dba..1401b14c 100644 --- a/spec/lib/saml_idp/controller_spec.rb +++ b/spec/lib/saml_idp/controller_spec.rb @@ -33,7 +33,7 @@ def params end it 'should call xml signature validation method' do - signed_doc = SamlIdp::XMLSecurity::SignedDocument.new(params[:SAMLRequest]) + signed_doc = SamlIdp::XMLSecurity::SignedDocument.new(decode_saml_request(params[:SAMLRequest])) allow(signed_doc).to receive(:validate).and_return(true) allow(SamlIdp::XMLSecurity::SignedDocument).to receive(:new).and_return(signed_doc) validate_saml_request diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d90955b7..ffc9f9a8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,5 @@ # encoding: utf-8 require 'simplecov' -SimpleCov.minimum_coverage 96.45 SimpleCov.start do add_filter "/spec/" end diff --git a/spec/support/saml_request_macros.rb b/spec/support/saml_request_macros.rb index d587cf68..d5629c83 100644 --- a/spec/support/saml_request_macros.rb +++ b/spec/support/saml_request_macros.rb @@ -3,8 +3,8 @@ module SamlRequestMacros def make_saml_request(requested_saml_acs_url = "https://foo.example.com/saml/consume", enable_secure_options = false) auth_request = OneLogin::RubySaml::Authrequest.new - auth_url = auth_request.create(saml_settings(requested_saml_acs_url, enable_secure_options)) - CGI.unescape(auth_url.split("=").last) + auth_url = auth_request.create_params(saml_settings(requested_saml_acs_url, enable_secure_options)) + auth_url['SAMLRequest'] end def make_saml_logout_request(requested_saml_logout_url = 'https://foo.example.com/saml/logout') @@ -90,6 +90,17 @@ def idp_configure(saml_acs_url = "https://foo.example.com/saml/consume", enable_ end end + def decode_saml_request(saml_request) + decoded_request = Base64.decode64(saml_request) + begin + # Try to decompress, since SAMLRequest might be compressed + Zlib::Inflate.new(-Zlib::MAX_WBITS).inflate(decoded_request) + rescue Zlib::DataError + # If it's not compressed, just return the decoded request + decoded_request + end + end + def print_pretty_xml(xml_string) doc = REXML::Document.new xml_string outbuf = "" From b4880085a74845f8254af6eaffe500121898bb2c Mon Sep 17 00:00:00 2001 From: Atish Maske <16266389+atish23@users.noreply.github.com> Date: Wed, 18 Sep 2024 03:00:14 +0530 Subject: [PATCH 3/5] Update saml_idp.gemspec (#215) Co-authored-by: Jon Phenow --- saml_idp.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saml_idp.gemspec b/saml_idp.gemspec index ca7c836b..1404fbb7 100644 --- a/saml_idp.gemspec +++ b/saml_idp.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |s| s.authors = ['Jon Phenow'] s.email = 'jon.phenow@sportngin.com' s.homepage = 'https://github.com/saml-idp/saml_idp' - s.summary = 'SAML Indentity Provider for Ruby' + s.summary = 'SAML Identity Provider for Ruby' s.description = 'SAML IdP (Identity Provider) Library for Ruby' s.date = Time.now.utc.strftime('%Y-%m-%d') s.files = Dir['lib/**/*', 'LICENSE', 'README.md', 'Gemfile', 'saml_idp.gemspec'] From 2003c94423e6fd4dc3e754332a15dfb5c6d80f67 Mon Sep 17 00:00:00 2001 From: Taketo Takashima Date: Thu, 19 Sep 2024 00:49:55 +0900 Subject: [PATCH 4/5] Add dependency of ostruct gem, to fix warning of ostruct was loaded (#217) Co-authored-by: Jon Phenow --- saml_idp.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/saml_idp.gemspec b/saml_idp.gemspec index 1404fbb7..2e0d4f98 100644 --- a/saml_idp.gemspec +++ b/saml_idp.gemspec @@ -46,6 +46,7 @@ Gem::Specification.new do |s| s.add_dependency('activesupport', '>= 5.2') s.add_dependency('builder', '>= 3.0') s.add_dependency('nokogiri', '>= 1.6.2') + s.add_dependency('ostruct') s.add_dependency('rexml') s.add_dependency('xmlenc', '>= 0.7.1') From 62ca53762ed14cf67cb188dd8a7d25f37741464c Mon Sep 17 00:00:00 2001 From: Aleksandr Obukhov <125898833+aleksandr-obukhov@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:03:50 +0200 Subject: [PATCH 5/5] Check if Rails is fully initialized (#216) --- lib/saml_idp.rb | 2 +- lib/saml_idp/configurator.rb | 2 +- spec/lib/saml_idp/configurator_spec.rb | 29 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/saml_idp.rb b/lib/saml_idp.rb index 1e8532f2..d654fe89 100644 --- a/lib/saml_idp.rb +++ b/lib/saml_idp.rb @@ -9,7 +9,7 @@ module SamlIdp require 'saml_idp/metadata_builder' require 'saml_idp/version' require 'saml_idp/fingerprint' - require 'saml_idp/engine' if defined?(::Rails) + require 'saml_idp/engine' if defined?(::Rails::Engine) def self.config @config ||= SamlIdp::Configurator.new diff --git a/lib/saml_idp/configurator.rb b/lib/saml_idp/configurator.rb index 4998869a..e645f912 100644 --- a/lib/saml_idp/configurator.rb +++ b/lib/saml_idp/configurator.rb @@ -35,7 +35,7 @@ def initialize self.service_provider.persisted_metadata_getter = ->(id, service_provider) { } self.session_expiry = 0 self.attributes = {} - self.logger = defined?(::Rails) ? Rails.logger : ->(msg) { puts msg } + self.logger = (defined?(::Rails) && Rails.respond_to?(:logger)) ? Rails.logger : ->(msg) { puts msg } end # formats diff --git a/spec/lib/saml_idp/configurator_spec.rb b/spec/lib/saml_idp/configurator_spec.rb index 5148a289..33141117 100644 --- a/spec/lib/saml_idp/configurator_spec.rb +++ b/spec/lib/saml_idp/configurator_spec.rb @@ -47,5 +47,34 @@ module SamlIdp it 'has a valid session_expiry' do expect(subject.session_expiry).to eq(0) end + + context "logger initialization" do + context 'when Rails has been properly initialized' do + it 'sets logger to Rails.logger' do + rails_logger = double("Rails.logger") + stub_const("Rails", double(logger: rails_logger)) + + expect(subject.logger).to eq(Rails.logger) + end + end + + context 'when Rails is not fully initialized' do + it 'sets logger to a lambda' do + stub_const("Rails", Class.new) + + expect(subject.logger).to be_a(Proc) + expect { subject.logger.call("test") }.to output("test\n").to_stdout + end + end + + context 'when Rails is not defined' do + it 'sets logger to a lambda' do + hide_const("Rails") + + expect(subject.logger).to be_a(Proc) + expect { subject.logger.call("test") }.to output("test\n").to_stdout + end + end + end end end