Skip to content

Commit

Permalink
Merge pull request #234 from ylansegal/feature/jruby_support_0.9
Browse files Browse the repository at this point in the history
Add explicit support for JRuby
  • Loading branch information
pitbulk committed Aug 12, 2015
2 parents 35fc801 + 7d86fe2 commit 3905e83
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Expand Up @@ -6,6 +6,8 @@ rvm:
- 2.1.5
- 2.2.0
- ree
- jruby-1.7.21
- jruby-9.0.0.0
gemfile:
- Gemfile
- gemfiles/nokogiri-1.5.gemfile
Expand All @@ -15,3 +17,7 @@ matrix:
gemfile: Gemfile
- rvm: ree
gemfile: Gemfile
- rvm: jruby-9.0.0.0
gemfile: gemfiles/nokogiri-1.5.gemfile
- rvm: jruby-1.7.21
gemfile: gemfiles/nokogiri-1.5.gemfile
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -31,6 +31,8 @@ We created a demo project for Rails4 that uses the latest version of this librar
* 1.9.x
* 2.1.x
* 2.2.x
* JRuby 1.7.19
* JRuby 9.0.0.0

## Adding Features, Pull Requests
* Fork the repository
Expand Down
14 changes: 0 additions & 14 deletions Rakefile
Expand Up @@ -25,17 +25,3 @@ end
task :test

task :default => :test

# require 'rake/rdoctask'
# Rake::RDocTask.new do |rdoc|
# if File.exist?('VERSION')
# version = File.read('VERSION')
# else
# version = ""
# end

# rdoc.rdoc_dir = 'rdoc'
# rdoc.title = "ruby-saml #{version}"
# rdoc.rdoc_files.include('README*')
# rdoc.rdoc_files.include('lib/**/*.rb')
#end
2 changes: 1 addition & 1 deletion lib/onelogin/ruby-saml/saml_message.rb
Expand Up @@ -23,7 +23,7 @@ class SamlMessage
# @return [Nokogiri::XML::Schema] Gets the schema object of the SAML 2.0 Protocol schema
#
def self.schema
@schema ||= Mutex.new.synchronize do
Mutex.new.synchronize do
Dir.chdir(File.expand_path("../../../schemas", __FILE__)) do
::Nokogiri::XML::Schema(File.read("saml-schema-protocol-2.0.xsd"))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/xml_security.rb
Expand Up @@ -360,7 +360,7 @@ def extract_inclusive_namespaces
prefix_list = element.attributes.get_attribute("PrefixList").value
prefix_list.split(" ")
else
[]
nil
end
end

Expand Down
12 changes: 10 additions & 2 deletions ruby-saml.gemspec
Expand Up @@ -30,7 +30,12 @@ Gem::Specification.new do |s|
# Because runtime dependencies are determined at build time, we cannot make
# Nokogiri's version dependent on the Ruby version, even though we would
# have liked to constrain Ruby 1.8.7 to install only the 1.5.x versions.
s.add_runtime_dependency('nokogiri', '>= 1.5.10')
if defined?(JRUBY_VERSION)
s.add_runtime_dependency('nokogiri', '>= 1.6.0')
s.add_runtime_dependency('jruby-openssl', '>= 0.9.8')
else
s.add_runtime_dependency('nokogiri', '>= 1.5.10')
end

s.add_development_dependency('minitest', '~> 5.5')
s.add_development_dependency('mocha', '~> 0.14')
Expand All @@ -40,7 +45,10 @@ Gem::Specification.new do |s|
s.add_development_dependency('systemu', '~> 2')
s.add_development_dependency('timecop', '<= 0.6.0')

if RUBY_VERSION < '1.9'
if defined?(JRUBY_VERSION)
# All recent versions of JRuby play well with pry
s.add_development_dependency('pry')
elsif RUBY_VERSION < '1.9'
# 1.8.7
s.add_development_dependency('ruby-debug', '~> 0.10.4')
elsif RUBY_VERSION < '2.0'
Expand Down
18 changes: 9 additions & 9 deletions test/response_test.rb
Expand Up @@ -56,7 +56,7 @@ class RubySamlTest < Minitest::Test

describe "Prevent XEE attack" do
before do
@response = OneLogin::RubySaml::Response.new(fixture(:attackxee))
@response = OneLogin::RubySaml::Response.new(fixture(:attackxee))
end

it "false when evil attack vector is present, soft = true" do
Expand Down Expand Up @@ -419,7 +419,7 @@ class RubySamlTest < Minitest::Test
assert response_valid_signed.send(:validate_issuer)

response_valid_signed.settings.idp_entity_id = 'https://app.onelogin.com/saml2'
assert response_valid_signed.send(:validate_issuer)
assert response_valid_signed.send(:validate_issuer)
end

it "return false when the issuer of the Message does not match the IdP entityId" do
Expand Down Expand Up @@ -501,7 +501,7 @@ class RubySamlTest < Minitest::Test
response = OneLogin::RubySaml::Response.new(response_document_valid_signed, :settings => settings, :matches_request_id => "_fc4a34b0-7efb-012e-caae-782bcb13bb38")
assert response.send(:validate_in_response_to)
assert_empty response.errors
end
end

it "return true when no Request ID is provided for checking" do
response = OneLogin::RubySaml::Response.new(response_document_valid_signed, :settings => settings)
Expand Down Expand Up @@ -898,7 +898,7 @@ class RubySamlTest < Minitest::Test
it 'is not possible when encryptID inside the assertion but no private key' do
response_encrypted_nameid.settings = settings
assert_raises(OneLogin::RubySaml::ValidationError, "An EncryptedID found and no SP private key found on the settings to decrypt it") do
assert_equal "test@onelogin.com", response_encrypted_nameid.nameid
assert_equal "test@onelogin.com", response_encrypted_nameid.nameid
end
end

Expand Down Expand Up @@ -1017,7 +1017,7 @@ class RubySamlTest < Minitest::Test
describe "check right settings" do

it "is not possible to decrypt the assertion if no private key" do
response = OneLogin::RubySaml::Response.new(signed_message_encrypted_unsigned_assertion, :settings => settings)
response = OneLogin::RubySaml::Response.new(signed_message_encrypted_unsigned_assertion, :settings => settings)

encrypted_assertion_node = REXML::XPath.first(
response.document,
Expand All @@ -1033,7 +1033,7 @@ class RubySamlTest < Minitest::Test
end

it "is possible to decrypt the assertion if private key" do
response = OneLogin::RubySaml::Response.new(signed_message_encrypted_unsigned_assertion, :settings => settings)
response = OneLogin::RubySaml::Response.new(signed_message_encrypted_unsigned_assertion, :settings => settings)

encrypted_assertion_node = REXML::XPath.first(
response.document,
Expand Down Expand Up @@ -1100,9 +1100,9 @@ class RubySamlTest < Minitest::Test
assert_equal "_ce3d2948b4cf20146dee0a0b3dd6f69b6cf86f62d7", response.nameid
end
end

end
describe "test qualified name id in attributes" do
describe "test qualified name id in attributes" do

it "parsed the nameid" do
response = OneLogin::RubySaml::Response.new(read_response("signed_nameid_in_atts.xml"), :settings => settings)
Expand All @@ -1113,7 +1113,7 @@ class RubySamlTest < Minitest::Test
end
end

describe "test unqualified name id in attributes" do
describe "test unqualified name id in attributes" do

it "parsed the nameid" do
response = OneLogin::RubySaml::Response.new(read_response("signed_unqual_nameid_in_atts.xml"), :settings => settings)
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Expand Up @@ -10,6 +10,7 @@
require 'bundler'
require 'minitest/autorun'
require 'mocha/setup'
require 'timecop'

Bundler.require :default, :test

Expand Down
5 changes: 2 additions & 3 deletions test/xml_security_test.rb
@@ -1,6 +1,5 @@
require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
require 'xml_security'
require 'timecop'

class XmlSecurityTest < Minitest::Test
include XMLSecurity
Expand Down Expand Up @@ -215,14 +214,14 @@ class XmlSecurityTest < Minitest::Test
assert response.is_valid?
end

it "return an empty list when inclusive namespace element is missing" do
it "return nil when inclusive namespace element is missing" do
response = fixture(:no_signature_ns, false)
response.slice! %r{<InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="#default saml ds xs xsi"/>}

document = XMLSecurity::SignedDocument.new(response)
inclusive_namespaces = document.send(:extract_inclusive_namespaces)

assert inclusive_namespaces.empty?
assert inclusive_namespaces.nil?
end
end

Expand Down

0 comments on commit 3905e83

Please sign in to comment.