ruby-saml 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ruby-saml might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 785edd651b4a713d7a01a4841676034300a5465b
4
- data.tar.gz: 33e3be90b834541836dad199a3843f0f50dc1d73
3
+ metadata.gz: 639540398f041bbcc593b2d2fdb14cf93028ce45
4
+ data.tar.gz: ab5128758b3789b7354906a8f9145af07ac873e5
5
5
  SHA512:
6
- metadata.gz: 7f0297c376b1b4ae225cd8b93a5541ff06829e89dcb8ee796b1ad1256a401532f1bf96ae257a8e63114f18de72333769d89f83bb4ac188e2659710dd75c9d3d0
7
- data.tar.gz: ca1e2d0aefbdf122c4c214736c3c3d704184387f5becff71f4f1ebfdb1dc6b4d83a63dd1b267c12decdd69b1a8ada3db5886f4c6b64d46904a254e9dca85f260
6
+ metadata.gz: 6ff40b3269727503ec6977fec4697e3babe3742cf6bc214281a156745057f581df8cfd7b93ec3499e23bf3ed99d806abe38bc03d4e7784b83ccb0b617494d883
7
+ data.tar.gz: 3fe0c819cb2183ed1c574f4a2d02db01894a69bc1c4673582d4646fc80217ed88504de2ae0c59bbe22cc209212e9aa5a895a7d22c5be83fc10589be713247c50
data/README.md CHANGED
@@ -614,3 +614,5 @@ settings.attribute_consuming_service.configure do
614
614
  add_attribute :name => "Another Attribute", :name_format => "Name Format", :friendly_name => "Friendly Name", :attribute_value => "Attribute Value"
615
615
  end
616
616
  ```
617
+
618
+ The `attribute_value` option additionally accepts an array of possible values.
@@ -1,5 +1,14 @@
1
1
  # RubySaml Changelog
2
2
 
3
+ ### 1.4.2 (January 11, 2017)
4
+ * Improve tests format
5
+ * Fix nokogiri requirements based on ruby version
6
+ * Only publish KeyDescriptor[use="encryption"] at SP metadata if security[:want_assertions_encrypted] is true
7
+ * Be able to skip destination validation
8
+ * Improved inResponse validation on SAMLResponses and LogoutResponses
9
+ * [#354](https://github.com/onelogin/ruby-saml/pull/354) Allow scheme and domain to match ignoring case
10
+ * [#363](https://github.com/onelogin/ruby-saml/pull/363) Add support for multiple requested attributes
11
+
3
12
  ### 1.4.1 (October 19, 2016)
4
13
  * [#357](https://github.com/onelogin/ruby-saml/pull/357) Add EncryptedAttribute support. Improve decrypt method
5
14
  * Allow multiple authn_context_decl_ref in settings
@@ -180,12 +180,11 @@ module OneLogin
180
180
  #
181
181
  def valid_in_response_to?
182
182
  return true unless options.has_key? :matches_request_id
183
+ return true if options[:matches_request_id].nil?
184
+ return true unless options[:matches_request_id] != in_response_to
183
185
 
184
- unless options[:matches_request_id] == in_response_to
185
- return append_error("Response does not match the request ID, expected: <#{options[:matches_request_id]}>, but was: <#{in_response_to}>")
186
- end
187
-
188
- true
186
+ error_msg = "The InResponseTo of the Logout Response: #{in_response_to}, does not match the ID of the Logout Request sent by the SP: #{options[:matches_request_id]}"
187
+ append_error(error_msg)
189
188
  end
190
189
 
191
190
  # Validates the Issuer of the Logout Response
@@ -195,7 +194,7 @@ module OneLogin
195
194
  def valid_issuer?
196
195
  return true if settings.idp_entity_id.nil? || issuer.nil?
197
196
 
198
- unless URI.parse(issuer) == URI.parse(settings.idp_entity_id)
197
+ unless OneLogin::RubySaml::Utils.uri_match?(issuer, settings.idp_entity_id)
199
198
  return append_error("Doesn't match the issuer, expected: <#{settings.idp_entity_id}>, but was: <#{issuer}>")
200
199
  end
201
200
  true
@@ -42,11 +42,13 @@ module OneLogin
42
42
  xc = xd.add_element "ds:X509Certificate"
43
43
  xc.text = cert_text
44
44
 
45
- kd2 = sp_sso.add_element "md:KeyDescriptor", { "use" => "encryption" }
46
- ki2 = kd2.add_element "ds:KeyInfo", {"xmlns:ds" => "http://www.w3.org/2000/09/xmldsig#"}
47
- xd2 = ki2.add_element "ds:X509Data"
48
- xc2 = xd2.add_element "ds:X509Certificate"
49
- xc2.text = cert_text
45
+ if settings.security[:want_assertions_encrypted]
46
+ kd2 = sp_sso.add_element "md:KeyDescriptor", { "use" => "encryption" }
47
+ ki2 = kd2.add_element "ds:KeyInfo", {"xmlns:ds" => "http://www.w3.org/2000/09/xmldsig#"}
48
+ xd2 = ki2.add_element "ds:X509Data"
49
+ xc2 = xd2.add_element "ds:X509Certificate"
50
+ xc2.text = cert_text
51
+ end
50
52
  end
51
53
 
52
54
  root.attributes["ID"] = OneLogin::RubySaml::Utils.uuid
@@ -89,8 +91,10 @@ module OneLogin
89
91
  "FriendlyName" => attribute[:friendly_name]
90
92
  }
91
93
  unless attribute[:attribute_value].nil?
92
- sp_attr_val = sp_req_attr.add_element "saml:AttributeValue"
93
- sp_attr_val.text = attribute[:attribute_value]
94
+ Array(attribute[:attribute_value]).each do |value|
95
+ sp_attr_val = sp_req_attr.add_element "saml:AttributeValue"
96
+ sp_attr_val.text = value.to_str
97
+ end
94
98
  end
95
99
  end
96
100
  end
@@ -563,7 +563,7 @@ module OneLogin
563
563
  #
564
564
  def validate_in_response_to
565
565
  return true unless options.has_key? :matches_request_id
566
- return true if options[:matches_request_id].nil? || options[:matches_request_id].empty?
566
+ return true if options[:matches_request_id].nil?
567
567
  return true unless options[:matches_request_id] != in_response_to
568
568
 
569
569
  error_msg = "The InResponseTo of the Response: #{in_response_to}, does not match the ID of the AuthNRequest sent by the SP: #{options[:matches_request_id]}"
@@ -586,12 +586,14 @@ module OneLogin
586
586
  true
587
587
  end
588
588
 
589
- # Validates the Destination, (If the SAML Response is received where expected)
589
+ # Validates the Destination, (If the SAML Response is received where expected).
590
+ # If the response was initialized with the :skip_destination option, this validation is skipped,
590
591
  # If fails, the error is added to the errors array
591
592
  # @return [Boolean] True if there is a Destination element that matches the Consumer Service URL, otherwise False
592
593
  #
593
594
  def validate_destination
594
595
  return true if destination.nil?
596
+ return true if options[:skip_destination]
595
597
 
596
598
  if destination.empty?
597
599
  error_msg = "The response has an empty Destination value"
@@ -600,7 +602,7 @@ module OneLogin
600
602
 
601
603
  return true if settings.assertion_consumer_service_url.nil? || settings.assertion_consumer_service_url.empty?
602
604
 
603
- unless destination == settings.assertion_consumer_service_url
605
+ unless OneLogin::RubySaml::Utils.uri_match?(destination, settings.assertion_consumer_service_url)
604
606
  error_msg = "The response was received at #{destination} instead of #{settings.assertion_consumer_service_url}"
605
607
  return append_error(error_msg)
606
608
  end
@@ -675,7 +677,7 @@ module OneLogin
675
677
  end
676
678
 
677
679
  obtained_issuers.each do |issuer|
678
- unless URI.parse(issuer) == URI.parse(settings.idp_entity_id)
680
+ unless OneLogin::RubySaml::Utils.uri_match?(issuer, settings.idp_entity_id)
679
681
  error_msg = "Doesn't match the issuer, expected: <#{settings.idp_entity_id}>, but was: <#{issuer}>"
680
682
  return append_error(error_msg)
681
683
  end
@@ -151,15 +151,16 @@ module OneLogin
151
151
  :compress_response => true,
152
152
  :soft => true,
153
153
  :security => {
154
- :authn_requests_signed => false,
155
- :logout_requests_signed => false,
156
- :logout_responses_signed => false,
157
- :want_assertions_signed => false,
158
- :want_name_id => false,
159
- :metadata_signed => false,
160
- :embed_sign => false,
161
- :digest_method => XMLSecurity::Document::SHA1,
162
- :signature_method => XMLSecurity::Document::RSA_SHA1
154
+ :authn_requests_signed => false,
155
+ :logout_requests_signed => false,
156
+ :logout_responses_signed => false,
157
+ :want_assertions_signed => false,
158
+ :want_assertions_encrypted => false,
159
+ :want_name_id => false,
160
+ :metadata_signed => false,
161
+ :embed_sign => false,
162
+ :digest_method => XMLSecurity::Document::SHA1,
163
+ :signature_method => XMLSecurity::Document::RSA_SHA1
163
164
  }.freeze,
164
165
  :double_quote_xml_attribute_values => false,
165
166
  }.freeze
@@ -212,7 +212,7 @@ module OneLogin
212
212
  def validate_issuer
213
213
  return true if settings.nil? || settings.idp_entity_id.nil? || issuer.nil?
214
214
 
215
- unless URI.parse(issuer) == URI.parse(settings.idp_entity_id)
215
+ unless OneLogin::RubySaml::Utils.uri_match?(issuer, settings.idp_entity_id)
216
216
  return append_error("Doesn't match the issuer, expected: <#{settings.idp_entity_id}>, but was: <#{issuer}>")
217
217
  end
218
218
 
@@ -193,6 +193,33 @@ module OneLogin
193
193
  def self.uuid
194
194
  RUBY_VERSION < '1.9' ? "_#{@@uuid_generator.generate}" : "_#{SecureRandom.uuid}"
195
195
  end
196
+
197
+ # Given two strings, attempt to match them as URIs using Rails' parse method. If they can be parsed,
198
+ # then the fully-qualified domain name and the host should performa a case-insensitive match, per the
199
+ # RFC for URIs. If Rails can not parse the string in to URL pieces, return a boolean match of the
200
+ # two strings. This maintains the previous functionality.
201
+ # @return [Boolean]
202
+ def self.uri_match?(destination_url, settings_url)
203
+ dest_uri = URI.parse(destination_url)
204
+ acs_uri = URI.parse(settings_url)
205
+
206
+ if dest_uri.scheme.nil? || acs_uri.scheme.nil? || dest_uri.host.nil? || acs_uri.host.nil?
207
+ raise URI::InvalidURIError
208
+ else
209
+ dest_uri.scheme.downcase == acs_uri.scheme.downcase &&
210
+ dest_uri.host.downcase == acs_uri.host.downcase &&
211
+ dest_uri.path == acs_uri.path &&
212
+ dest_uri.query == acs_uri.query
213
+ end
214
+ rescue URI::InvalidURIError
215
+ original_uri_match?(destination_url, settings_url)
216
+ end
217
+
218
+ # If Rails' URI.parse can't match to valid URL, default back to the original matching service.
219
+ # @return [Boolean]
220
+ def self.original_uri_match?(destination_url, settings_url)
221
+ destination_url == settings_url
222
+ end
196
223
  end
197
224
  end
198
225
  end
@@ -1,5 +1,5 @@
1
1
  module OneLogin
2
2
  module RubySaml
3
- VERSION = '1.4.1'
3
+ VERSION = '1.4.2'
4
4
  end
5
5
  end
@@ -25,8 +25,6 @@ Gem::Specification.new do |s|
25
25
  s.summary = %q{SAML Ruby Tookit}
26
26
  s.test_files = `git ls-files test/*`.split("\n")
27
27
 
28
-
29
-
30
28
  # Because runtime dependencies are determined at build time, we cannot make
31
29
  # Nokogiri's version dependent on the Ruby version, even though we would
32
30
  # have liked to constrain Ruby 1.8.7 to install only the 1.5.x versions.
@@ -36,6 +34,8 @@ Gem::Specification.new do |s|
36
34
  elsif RUBY_VERSION < '1.9'
37
35
  s.add_runtime_dependency('uuid')
38
36
  s.add_runtime_dependency('nokogiri', '<= 1.5.11')
37
+ elsif RUBY_VERSION < '2.1'
38
+ s.add_runtime_dependency('nokogiri', '>= 1.5.10', '<= 1.6.8.1')
39
39
  else
40
40
  s.add_runtime_dependency('nokogiri', '>= 1.5.10')
41
41
  end
@@ -103,7 +103,7 @@ class RubySamlTest < Minitest::Test
103
103
 
104
104
  assert !logoutresponse.validate
105
105
  refute_equal expected_request_id, logoutresponse.in_response_to
106
- assert_includes logoutresponse.errors, "Response does not match the request ID, expected: <#{expected_request_id}>, but was: <#{logoutresponse.in_response_to}>"
106
+ assert_includes logoutresponse.errors, "The InResponseTo of the Logout Response: #{logoutresponse.in_response_to}, does not match the ID of the Logout Request sent by the SP: #{expected_request_id}"
107
107
  end
108
108
 
109
109
  it "invalidate logout response with wrong request status" do
@@ -177,7 +177,7 @@ class RubySamlTest < Minitest::Test
177
177
 
178
178
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(valid_logout_response_document, settings, opts)
179
179
  assert_raises(OneLogin::RubySaml::ValidationError) { logoutresponse.validate }
180
- assert_includes logoutresponse.errors, "Response does not match the request ID, expected: <#{expected_request_id}>, but was: <#{logoutresponse.in_response_to}>"
180
+ assert_includes logoutresponse.errors, "The InResponseTo of the Logout Response: #{logoutresponse.in_response_to}, does not match the ID of the Logout Request sent by the SP: #{expected_request_id}"
181
181
  end
182
182
 
183
183
  it "raise validation error for wrong request status" do
@@ -89,7 +89,7 @@ class MetadataTest < Minitest::Test
89
89
  end
90
90
  end
91
91
 
92
- describe "when auth requests are signed" do
92
+ describe "with a sign/encrypt certificate" do
93
93
  let(:key_descriptors) do
94
94
  REXML::XPath.match(
95
95
  xml_doc,
@@ -111,22 +111,68 @@ class MetadataTest < Minitest::Test
111
111
  settings.certificate = ruby_saml_cert_text
112
112
  end
113
113
 
114
- it "generates Service Provider Metadata with AuthnRequestsSigned" do
115
- settings.security[:authn_requests_signed] = true
116
- assert_equal "true", spsso_descriptor.attribute("AuthnRequestsSigned").value
114
+ it "generates Service Provider Metadata with X509Certificate for sign" do
115
+ assert_equal 1, key_descriptors.length
116
+ assert_equal "signing", key_descriptors[0].attribute("use").value
117
+
118
+ assert_equal 1, cert_nodes.length
117
119
  assert_equal ruby_saml_cert.to_der, cert.to_der
118
120
 
119
121
  assert validate_xml!(xml_text, "saml-schema-metadata-2.0.xsd")
120
122
  end
121
123
 
122
- it "generates Service Provider Metadata with X509Certificate for sign and encrypt" do
123
- assert_equal 2, key_descriptors.length
124
- assert_equal "signing", key_descriptors[0].attribute("use").value
125
- assert_equal "encryption", key_descriptors[1].attribute("use").value
124
+ describe "and signed authentication requests" do
125
+ before do
126
+ settings.security[:authn_requests_signed] = true
127
+ end
126
128
 
127
- assert_equal 2, cert_nodes.length
128
- assert_equal ruby_saml_cert.to_der, cert.to_der
129
- assert_equal cert_nodes[0].text, cert_nodes[1].text
129
+ it "generates Service Provider Metadata with AuthnRequestsSigned" do
130
+ assert_equal "true", spsso_descriptor.attribute("AuthnRequestsSigned").value
131
+ assert_equal ruby_saml_cert.to_der, cert.to_der
132
+
133
+ assert validate_xml!(xml_text, "saml-schema-metadata-2.0.xsd")
134
+ end
135
+ end
136
+
137
+ describe "and encrypted assertions" do
138
+ before do
139
+ settings.security[:want_assertions_encrypted] = true
140
+ end
141
+
142
+ it "generates Service Provider Metadata with X509Certificate for encrypt" do
143
+ assert_equal 2, key_descriptors.length
144
+ assert_equal "encryption", key_descriptors[1].attribute("use").value
145
+
146
+ assert_equal 2, cert_nodes.length
147
+ assert_equal cert_nodes[0].text, cert_nodes[1].text
148
+ assert validate_xml!(xml_text, "saml-schema-metadata-2.0.xsd")
149
+ end
150
+ end
151
+ end
152
+
153
+ describe "when attribute service is configured with multiple attribute values" do
154
+ let(:attr_svc) { REXML::XPath.first(xml_doc, "//md:AttributeConsumingService") }
155
+ let(:req_attr) { REXML::XPath.first(xml_doc, "//md:RequestedAttribute") }
156
+
157
+ before do
158
+ settings.attribute_consuming_service.configure do
159
+ service_name "Test Service"
160
+ add_attribute(:name => "Name", :name_format => "Name Format", :friendly_name => "Friendly Name", :attribute_value => ["Attribute Value One", "Attribute Value Two"])
161
+ end
162
+ end
163
+
164
+ it "generates attribute service" do
165
+ assert_equal "true", attr_svc.attribute("isDefault").value
166
+ assert_equal "1", attr_svc.attribute("index").value
167
+ assert_equal REXML::XPath.first(xml_doc, "//md:ServiceName").text.strip, "Test Service"
168
+
169
+ assert_equal "Name", req_attr.attribute("Name").value
170
+ assert_equal "Name Format", req_attr.attribute("NameFormat").value
171
+ assert_equal "Friendly Name", req_attr.attribute("FriendlyName").value
172
+
173
+ attribute_values = REXML::XPath.match(xml_doc, "//saml:AttributeValue").map(&:text)
174
+ assert_equal "Attribute Value One", attribute_values[0]
175
+ assert_equal "Attribute Value Two", attribute_values[1]
130
176
 
131
177
  assert validate_xml!(xml_text, "saml-schema-metadata-2.0.xsd")
132
178
  end
@@ -24,6 +24,7 @@ class RubySamlTest < Minitest::Test
24
24
  let(:response_no_conditions) { OneLogin::RubySaml::Response.new(read_invalid_response("no_conditions.xml.base64")) }
25
25
  let(:response_no_authnstatement) { OneLogin::RubySaml::Response.new(read_invalid_response("no_authnstatement.xml.base64")) }
26
26
  let(:response_empty_destination) { OneLogin::RubySaml::Response.new(read_invalid_response("empty_destination.xml.base64")) }
27
+ let(:response_empty_destination_with_skip) { OneLogin::RubySaml::Response.new(read_invalid_response("empty_destination.xml.base64"), {:skip_destination => true}) }
27
28
  let(:response_no_status) { OneLogin::RubySaml::Response.new(read_invalid_response("no_status.xml.base64")) }
28
29
  let(:response_no_statuscode) { OneLogin::RubySaml::Response.new(read_invalid_response("no_status_code.xml.base64")) }
29
30
  let(:response_statuscode_responder) { OneLogin::RubySaml::Response.new(read_invalid_response("status_code_responder.xml.base64")) }
@@ -435,6 +436,40 @@ class RubySamlTest < Minitest::Test
435
436
  assert !response_empty_destination.send(:validate_destination)
436
437
  assert_includes response_empty_destination.errors, "The response has an empty Destination value"
437
438
  end
439
+
440
+ it "return true when the destination of the SAML Response is empty but skip_destination option is used" do
441
+ response_empty_destination_with_skip.settings = settings
442
+ assert response_empty_destination_with_skip.send(:validate_destination)
443
+ assert_empty response_empty_destination.errors
444
+ end
445
+
446
+ it "returns true on a case insensitive match on the domain" do
447
+ response_valid_signed_without_x509certificate.settings = settings
448
+ response_valid_signed_without_x509certificate.settings.assertion_consumer_service_url = 'http://APP.muDa.no/sso/consume'
449
+ assert response_valid_signed_without_x509certificate.send(:validate_destination)
450
+ assert_empty response_valid_signed_without_x509certificate.errors
451
+ end
452
+
453
+ it "returns true on a case insensitive match on the scheme" do
454
+ response_valid_signed_without_x509certificate.settings = settings
455
+ response_valid_signed_without_x509certificate.settings.assertion_consumer_service_url = 'HTTP://app.muda.no/sso/consume'
456
+ assert response_valid_signed_without_x509certificate.send(:validate_destination)
457
+ assert_empty response_valid_signed_without_x509certificate.errors
458
+ end
459
+
460
+ it "returns false on a case insenstive match on the path" do
461
+ response_valid_signed_without_x509certificate.settings = settings
462
+ response_valid_signed_without_x509certificate.settings.assertion_consumer_service_url = 'http://app.muda.no/SSO/consume'
463
+ assert !response_valid_signed_without_x509certificate.send(:validate_destination)
464
+ assert_includes response_valid_signed_without_x509certificate.errors, "The response was received at #{response_valid_signed_without_x509certificate.destination} instead of #{response_valid_signed_without_x509certificate.settings.assertion_consumer_service_url}"
465
+ end
466
+
467
+ it "returns true if it can't parse out a full URI." do
468
+ response_valid_signed_without_x509certificate.settings = settings
469
+ response_valid_signed_without_x509certificate.settings.assertion_consumer_service_url = 'presenter'
470
+ assert !response_valid_signed_without_x509certificate.send(:validate_destination)
471
+ assert_includes response_valid_signed_without_x509certificate.errors, "The response was received at #{response_valid_signed_without_x509certificate.destination} instead of #{response_valid_signed_without_x509certificate.settings.assertion_consumer_service_url}"
472
+ end
438
473
  end
439
474
 
440
475
  describe "#validate_issuer" do
@@ -1035,14 +1070,14 @@ class RubySamlTest < Minitest::Test
1035
1070
  end
1036
1071
 
1037
1072
  it "check what happens when trying retrieve attribute that does not exists" do
1038
- assert_equal nil, response_multiple_attr_values.attributes[:attribute_not_exists]
1039
- assert_equal nil, response_multiple_attr_values.attributes.single(:attribute_not_exists)
1040
- assert_equal nil, response_multiple_attr_values.attributes.multi(:attribute_not_exists)
1073
+ assert_nil response_multiple_attr_values.attributes[:attribute_not_exists]
1074
+ assert_nil response_multiple_attr_values.attributes.single(:attribute_not_exists)
1075
+ assert_nil response_multiple_attr_values.attributes.multi(:attribute_not_exists)
1041
1076
 
1042
1077
  OneLogin::RubySaml::Attributes.single_value_compatibility = false
1043
- assert_equal nil, response_multiple_attr_values.attributes[:attribute_not_exists]
1044
- assert_equal nil, response_multiple_attr_values.attributes.single(:attribute_not_exists)
1045
- assert_equal nil, response_multiple_attr_values.attributes.multi(:attribute_not_exists)
1078
+ assert_nil response_multiple_attr_values.attributes[:attribute_not_exists]
1079
+ assert_nil response_multiple_attr_values.attributes.single(:attribute_not_exists)
1080
+ assert_nil response_multiple_attr_values.attributes.multi(:attribute_not_exists)
1046
1081
  OneLogin::RubySaml::Attributes.single_value_compatibility = true
1047
1082
  end
1048
1083
 
@@ -99,13 +99,13 @@ class SettingsTest < Minitest::Test
99
99
  it "returns nil when the cert is an empty string" do
100
100
  @settings = OneLogin::RubySaml::Settings.new
101
101
  @settings.idp_cert = ""
102
- assert_equal nil, @settings.get_idp_cert
102
+ assert_nil @settings.get_idp_cert
103
103
  end
104
104
 
105
105
  it "returns nil when the cert is nil" do
106
106
  @settings = OneLogin::RubySaml::Settings.new
107
107
  @settings.idp_cert = nil
108
- assert_equal nil, @settings.get_idp_cert
108
+ assert_nil @settings.get_idp_cert
109
109
  end
110
110
 
111
111
  it "returns the certificate when it is valid" do
@@ -127,13 +127,13 @@ class SettingsTest < Minitest::Test
127
127
  it "returns nil when the cert is an empty string" do
128
128
  @settings = OneLogin::RubySaml::Settings.new
129
129
  @settings.certificate = ""
130
- assert_equal nil, @settings.get_sp_cert
130
+ assert_nil @settings.get_sp_cert
131
131
  end
132
132
 
133
133
  it "returns nil when the cert is nil" do
134
134
  @settings = OneLogin::RubySaml::Settings.new
135
135
  @settings.certificate = nil
136
- assert_equal nil, @settings.get_sp_cert
136
+ assert_nil @settings.get_sp_cert
137
137
  end
138
138
 
139
139
  it "returns the certificate when it is valid" do
@@ -156,13 +156,13 @@ class SettingsTest < Minitest::Test
156
156
  it "returns nil when the private key is an empty string" do
157
157
  @settings = OneLogin::RubySaml::Settings.new
158
158
  @settings.private_key = ""
159
- assert_equal nil, @settings.get_sp_key
159
+ assert_nil @settings.get_sp_key
160
160
  end
161
161
 
162
162
  it "returns nil when the private key is nil" do
163
163
  @settings = OneLogin::RubySaml::Settings.new
164
164
  @settings.private_key = nil
165
- assert_equal nil, @settings.get_sp_key
165
+ assert_nil @settings.get_sp_key
166
166
  end
167
167
 
168
168
  it "returns the private key when it is valid" do
@@ -106,7 +106,7 @@ class RubySamlTest < Minitest::Test
106
106
  describe "#not_on_or_after" do
107
107
  it "extract the value of the NotOnOrAfter attribute" do
108
108
  time_value = '2014-07-17T01:01:48Z'
109
- assert_equal nil, logout_request.not_on_or_after
109
+ assert_nil logout_request.not_on_or_after
110
110
  logout_request.document.root.attributes['NotOnOrAfter'] = time_value
111
111
  assert_equal Time.parse(time_value), logout_request.not_on_or_after
112
112
  end
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
2
2
 
3
3
  class UtilsTest < Minitest::Test
4
4
  describe ".format_cert" do
@@ -13,7 +13,7 @@ class UtilsTest < Minitest::Test
13
13
 
14
14
  it "returns nil when the cert is nil" do
15
15
  cert = nil
16
- assert_equal nil, OneLogin::RubySaml::Utils.format_cert(cert)
16
+ assert_nil OneLogin::RubySaml::Utils.format_cert(cert)
17
17
  end
18
18
 
19
19
  it "returns the certificate when it is valid" do
@@ -48,7 +48,7 @@ class UtilsTest < Minitest::Test
48
48
 
49
49
  it "returns nil when the private key is nil" do
50
50
  private_key = nil
51
- assert_equal nil, OneLogin::RubySaml::Utils.format_private_key(private_key)
51
+ assert_nil OneLogin::RubySaml::Utils.format_private_key(private_key)
52
52
  end
53
53
 
54
54
  it "returns the private key when it is valid" do
@@ -154,5 +154,55 @@ class UtilsTest < Minitest::Test
154
154
  refute_equal OneLogin::RubySaml::Utils.uuid, OneLogin::RubySaml::Utils.uuid
155
155
  end
156
156
  end
157
+
158
+ describe 'uri_match' do
159
+ it 'matches two urls' do
160
+ destination = 'http://www.example.com/test?var=stuff'
161
+ settings = 'http://www.example.com/test?var=stuff'
162
+ assert OneLogin::RubySaml::Utils.uri_match?(destination, settings)
163
+ end
164
+
165
+ it 'fails to match two urls' do
166
+ destination = 'http://www.example.com/test?var=stuff'
167
+ settings = 'http://www.example.com/othertest?var=stuff'
168
+ assert !OneLogin::RubySaml::Utils.uri_match?(destination, settings)
169
+ end
170
+
171
+ it "matches two URLs if the scheme case doesn't match" do
172
+ destination = 'http://www.example.com/test?var=stuff'
173
+ settings = 'HTTP://www.example.com/test?var=stuff'
174
+ assert OneLogin::RubySaml::Utils.uri_match?(destination, settings)
175
+ end
176
+
177
+ it "matches two URLs if the host case doesn't match" do
178
+ destination = 'http://www.EXAMPLE.com/test?var=stuff'
179
+ settings = 'http://www.example.com/test?var=stuff'
180
+ assert OneLogin::RubySaml::Utils.uri_match?(destination, settings)
181
+ end
182
+
183
+ it "fails to match two URLs if the path case doesn't match" do
184
+ destination = 'http://www.example.com/TEST?var=stuff'
185
+ settings = 'http://www.example.com/test?var=stuff'
186
+ assert !OneLogin::RubySaml::Utils.uri_match?(destination, settings)
187
+ end
188
+
189
+ it "fails to match two URLs if the query case doesn't match" do
190
+ destination = 'http://www.example.com/test?var=stuff'
191
+ settings = 'http://www.example.com/test?var=STUFF'
192
+ assert !OneLogin::RubySaml::Utils.uri_match?(destination, settings)
193
+ end
194
+
195
+ it 'matches two non urls' do
196
+ destination = 'stuff'
197
+ settings = 'stuff'
198
+ assert OneLogin::RubySaml::Utils.uri_match?(destination, settings)
199
+ end
200
+
201
+ it "fails to match two non urls" do
202
+ destination = 'stuff'
203
+ settings = 'not stuff'
204
+ assert !OneLogin::RubySaml::Utils.uri_match?(destination, settings)
205
+ end
206
+ end
157
207
  end
158
208
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-saml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - OneLogin LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2017-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri