Skip to content

Commit

Permalink
Merge remote-tracking branch 'saml_idp/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zogoo committed Oct 24, 2024
2 parents ade27c3 + 62ca537 commit 1029a8c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/saml_idp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/saml_idp/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion saml_idp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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')

Expand All @@ -56,6 +57,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rails', '>= 5.2')
s.add_development_dependency('debug')
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')
Expand Down
29 changes: 29 additions & 0 deletions spec/lib/saml_idp/configurator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions spec/support/saml_request_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,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 = ""
Expand Down

0 comments on commit 1029a8c

Please sign in to comment.