ruby-saml 0.8.12 → 0.8.17

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (50) hide show
  1. checksums.yaml +7 -7
  2. data/lib/onelogin/ruby-saml/logoutrequest.rb +2 -1
  3. data/lib/onelogin/ruby-saml/logoutresponse.rb +9 -51
  4. data/lib/onelogin/ruby-saml/response.rb +133 -21
  5. data/lib/onelogin/ruby-saml/settings.rb +28 -10
  6. data/lib/onelogin/ruby-saml/slo_logoutrequest.rb +101 -0
  7. data/lib/onelogin/ruby-saml/slo_logoutresponse.rb +12 -9
  8. data/lib/onelogin/ruby-saml/utils.rb +92 -0
  9. data/lib/onelogin/ruby-saml/version.rb +1 -1
  10. data/lib/ruby-saml.rb +1 -0
  11. data/lib/xml_security.rb +222 -86
  12. data/test/certificates/certificate.der +0 -0
  13. data/test/certificates/formatted_certificate +14 -0
  14. data/test/certificates/formatted_chained_certificate +42 -0
  15. data/test/certificates/formatted_private_key +12 -0
  16. data/test/certificates/formatted_rsa_private_key +12 -0
  17. data/test/certificates/invalid_certificate1 +1 -0
  18. data/test/certificates/invalid_certificate2 +1 -0
  19. data/test/certificates/invalid_certificate3 +12 -0
  20. data/test/certificates/invalid_chained_certificate1 +1 -0
  21. data/test/certificates/invalid_private_key1 +1 -0
  22. data/test/certificates/invalid_private_key2 +1 -0
  23. data/test/certificates/invalid_private_key3 +10 -0
  24. data/test/certificates/invalid_rsa_private_key1 +1 -0
  25. data/test/certificates/invalid_rsa_private_key2 +1 -0
  26. data/test/certificates/invalid_rsa_private_key3 +10 -0
  27. data/test/certificates/ruby-saml-2.crt +15 -0
  28. data/test/logoutresponse_test.rb +2 -16
  29. data/test/requests/logoutrequest_fixtures.rb +47 -0
  30. data/test/response_test.rb +227 -15
  31. data/test/responses/adfs_response_xmlns.xml +45 -0
  32. data/test/responses/invalids/invalid_issuer_assertion.xml.base64 +1 -0
  33. data/test/responses/invalids/invalid_issuer_message.xml.base64 +1 -0
  34. data/test/responses/invalids/multiple_signed.xml.base64 +1 -0
  35. data/test/responses/invalids/no_signature.xml.base64 +1 -0
  36. data/test/responses/invalids/response_with_concealed_signed_assertion.xml +51 -0
  37. data/test/responses/invalids/response_with_doubled_signed_assertion.xml +49 -0
  38. data/test/responses/invalids/signature_wrapping_attack.xml.base64 +1 -0
  39. data/test/responses/logoutresponse_fixtures.rb +4 -4
  40. data/test/responses/response_with_signed_assertion_3.xml +30 -0
  41. data/test/responses/response_with_signed_message_and_assertion.xml +34 -0
  42. data/test/responses/response_with_undefined_recipient.xml.base64 +1 -0
  43. data/test/responses/valid_response_without_x509certificate.xml.base64 +1 -0
  44. data/test/settings_test.rb +106 -0
  45. data/test/slo_logoutrequest_test.rb +66 -0
  46. data/test/slo_logoutresponse_test.rb +8 -0
  47. data/test/test_helper.rb +62 -30
  48. data/test/utils_test.rb +191 -1
  49. data/test/xml_security_test.rb +329 -36
  50. metadata +109 -45
Binary file
@@ -0,0 +1,14 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICPDCCAaWgAwIBAgIIEiC/9HMAWWAwDQYJKoZIhvcNAQEFBQAwTzELMAkGA1UE
3
+ BhMCVVMxDDAKBgNVBAoTA2libTEMMAoGA1UECxMDc3NvMSQwIgYDVQQDExtjMjVh
4
+ MDI3Ny50b3JvbnRvLmNhLmlibS5jb20wHhcNMTEwNTI0MTYzNTQ4WhcNMjEwNTIx
5
+ wsQMPBj4WQTNzTYMCQYDVQQGEwJVUzEMMAoGA1UEChMDaWJtMQwwCgYDVQQLEwNz
6
+ c28xJDAiBgNVBAMTG2MyNWEwMjc3LnRvcm9udG8uY2EuaWJtLmNvbTCBnzANBgkq
7
+ hkiG9w0BAQEFAAOBjQAwgYkCgYEAgzfYQZuf5FVdJTcrsIQZ+YHTPjOsw2MGo0jC
8
+ mdGMcp4brWeFgk1OVaOmytPx6P76wHWR436AleX3crHBPd8gPxuZdnvBQ7PkrKpw
9
+ Vvaq52juenFrho8JY0TeVgVkY5jAh45Y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obx9aG3
12
+ kh+rNyrlgM3K6dYfnKG1/YH5sJCAOvg8kDr0fQAQifH8lFVWumKUMoAe0bFTfwWt
13
+ p/VJ8MprrEJth6PFeZdczpuv+fpLcNj2VmNVJqvQYvS4m36OnBFh1QFZW8UrbFIf
14
+ dtm2nuZ+twSKqfKwjLdqcoX0p39h7Uw/
15
+ -----END CERTIFICATE-----
@@ -32,12 +32,12 @@ class LogoutResponseTest < Minitest::Test
32
32
  describe "#validate" do
33
33
  it "validate the response" do
34
34
  in_relation_to_request_id = random_id
35
-
35
+ settings.idp_entity_id = "https://example.com/idp"
36
36
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(valid_response({:uuid => in_relation_to_request_id}), settings)
37
37
 
38
38
  assert logoutresponse.validate
39
39
 
40
- assert_equal settings.sp_entity_id, logoutresponse.issuer
40
+ assert_equal settings.idp_entity_id, logoutresponse.issuer
41
41
  assert_equal in_relation_to_request_id, logoutresponse.in_response_to
42
42
 
43
43
  assert logoutresponse.success?
@@ -87,20 +87,6 @@ class LogoutResponseTest < Minitest::Test
87
87
  assert_raises(OneLogin::RubySaml::ValidationError) { logoutresponse.validate! }
88
88
  end
89
89
 
90
- it "raise validation error when in bad state" do
91
- # no settings
92
- logoutresponse = OneLogin::RubySaml::Logoutresponse.new(unsuccessful_response)
93
- assert_raises(OneLogin::RubySaml::ValidationError) { logoutresponse.validate! }
94
- end
95
-
96
- it "raise validation error when in lack of sp_entity_id setting" do
97
- bad_settings = settings
98
- bad_settings.issuer = nil
99
- bad_settings.sp_entity_id = nil
100
- logoutresponse = OneLogin::RubySaml::Logoutresponse.new(unsuccessful_response, bad_settings)
101
- assert_raises(OneLogin::RubySaml::ValidationError) { logoutresponse.validate! }
102
- end
103
-
104
90
  it "raise error for invalid xml" do
105
91
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(invalid_xml_response, settings)
106
92
 
@@ -0,0 +1,47 @@
1
+ #encoding: utf-8
2
+
3
+ def default_request_opts
4
+ {
5
+ :uuid => "_28024690-000e-0130-b6d2-38f6b112be8b",
6
+ :issue_instant => Time.now.strftime('%Y-%m-%dT%H:%M:%SZ'),
7
+ :nameid => "testuser@example.com",
8
+ :nameid_format => "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
9
+ :settings => settings
10
+ }
11
+ end
12
+
13
+ def valid_request(opts = {})
14
+ opts = default_request_opts.merge!(opts)
15
+
16
+ "<samlp:LogoutRequest
17
+ xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"
18
+ xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\"
19
+ ID=\"#{random_id}\" Version=\"2.0\"
20
+ IssueInstant=\"#{opts[:issue_instant]}\"
21
+ Destination=\"#{opts[:settings].idp_slo_target_url}\">
22
+ <saml:Issuer>#{opts[:settings].idp_entity_id}</saml:Issuer>
23
+ <saml:NameID Format=\"#{opts[:nameid_format]}\">#{opts[:nameid]}</saml:NameID>
24
+ </samlp:LogoutRequest>"
25
+ end
26
+
27
+ def invalid_xml_request
28
+ "<samlp:SomethingAwful
29
+ xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"
30
+ ID=\"#{random_id}\" Version=\"2.0\">
31
+ </samlp:SomethingAwful>"
32
+ end
33
+
34
+ def settings
35
+ @settings ||= OneLogin::RubySaml::Settings.new(
36
+ {
37
+ :assertion_consumer_service_url => "http://app.muda.no/sso/consume",
38
+ :single_logout_service_url => "http://app.muda.no/sso/consume_logout",
39
+ :sp_entity_id => "http://app.muda.no",
40
+ :sp_name_qualifier => "http://sso.muda.no",
41
+ :idp_sso_target_url => "http://sso.muda.no/sso",
42
+ :idp_slo_target_url => "http://sso.muda.no/slo",
43
+ :idp_cert_fingerprint => "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
44
+ :name_identifier_format => "urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
45
+ }
46
+ )
47
+ end
@@ -4,7 +4,10 @@ class ResponseTest < Minitest::Test
4
4
 
5
5
  describe "Response" do
6
6
  it "raise an exception when response is initialized with nil" do
7
- assert_raises(ArgumentError) { OneLogin::RubySaml::Response.new(nil) }
7
+ err = assert_raises(ArgumentError) do
8
+ OneLogin::RubySaml::Response.new(nil)
9
+ end
10
+ assert_equal "Response cannot be nil", err.message
8
11
  end
9
12
 
10
13
  it "be able to parse a document which contains ampersands" do
@@ -45,12 +48,71 @@ class ResponseTest < Minitest::Test
45
48
  end
46
49
 
47
50
  describe "#validate!" do
51
+ it "raise when settings not initialized" do
52
+ response = OneLogin::RubySaml::Response.new(response_document)
53
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
54
+ response.validate!
55
+ end
56
+ assert_equal "No settings on response", err.message
57
+ end
58
+
48
59
  it "raise when encountering a condition that prevents the document from being valid" do
49
60
  response = OneLogin::RubySaml::Response.new(response_document)
50
- assert_raises(OneLogin::RubySaml::ValidationError) do
61
+ response.settings = settings
62
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
63
+ response.validate!
64
+ end
65
+ assert_equal "Current time is on or after NotOnOrAfter condition", err.message
66
+ end
67
+
68
+ it "raises an exception when no cert or fingerprint provided" do
69
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed)
70
+ response.stubs(:conditions).returns(nil)
71
+ settings = OneLogin::RubySaml::Settings.new
72
+ response.settings = settings
73
+ settings.idp_cert = nil
74
+ settings.idp_cert_fingerprint = nil
75
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
76
+ response.validate!
77
+ end
78
+ assert_equal "No fingerprint or certificate on settings", err.message
79
+ end
80
+
81
+ it "raise when no signature" do
82
+ response_no_signed_elements = OneLogin::RubySaml::Response.new(read_invalid_response("no_signature.xml.base64"))
83
+ settings.idp_cert_fingerprint = signature_fingerprint_1
84
+ response_no_signed_elements.settings = settings
85
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
86
+ response_no_signed_elements.validate!
87
+ end
88
+ assert_equal "Found an unexpected number of Signature Element. SAML Response rejected", err.message
89
+ end
90
+
91
+ it "raise when multiple signatures" do
92
+ response_multiple_signed = OneLogin::RubySaml::Response.new(read_invalid_response("multiple_signed.xml.base64"))
93
+ settings.idp_cert_fingerprint = signature_fingerprint_1
94
+ response_multiple_signed.settings = settings
95
+ response_multiple_signed.stubs(:validate_structure).returns(true)
96
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
97
+ response_multiple_signed.validate!
98
+ end
99
+ assert_equal "Duplicated ID. SAML Response rejected", err.message
100
+ end
101
+
102
+ it "raise when fingerprint missmatch" do
103
+ resp_xml = Base64.decode64(response_document_valid_signed)
104
+ response = OneLogin::RubySaml::Response.new(Base64.encode64(resp_xml))
105
+ response.stubs(:conditions).returns(nil)
106
+ settings = OneLogin::RubySaml::Settings.new
107
+ settings.idp_cert_fingerprint = signature_fingerprint_1
108
+ response.settings = settings
109
+
110
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
51
111
  response.validate!
52
112
  end
113
+ assert_equal 'Fingerprint mismatch', err.message
53
114
  end
115
+
54
116
  end
55
117
 
56
118
  describe "#is_valid?" do
@@ -64,6 +126,16 @@ class ResponseTest < Minitest::Test
64
126
  assert !response.is_valid?
65
127
  end
66
128
 
129
+ it "return false when no cert or fingerprint provided" do
130
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed)
131
+ response.stubs(:conditions).returns(nil)
132
+ settings = OneLogin::RubySaml::Settings.new
133
+ response.settings = settings
134
+ settings.idp_cert = nil
135
+ settings.idp_cert_fingerprint = nil
136
+ assert !response.is_valid?
137
+ end
138
+
67
139
  it "return true when the response is initialized with valid data" do
68
140
  response = OneLogin::RubySaml::Response.new(response_document_valid_signed)
69
141
  response.stubs(:conditions).returns(nil)
@@ -80,7 +152,7 @@ class ResponseTest < Minitest::Test
80
152
  response = OneLogin::RubySaml::Response.new(response_document_valid_signed)
81
153
  response.stubs(:conditions).returns(nil)
82
154
  settings = OneLogin::RubySaml::Settings.new
83
- response.settings = settings
155
+ response.settings = settings
84
156
  assert !response.is_valid?
85
157
  assert !response.is_valid?
86
158
  end
@@ -95,7 +167,17 @@ class ResponseTest < Minitest::Test
95
167
  assert response.is_valid?
96
168
  end
97
169
 
98
- it "return true when using certificate instead of fingerprint" do
170
+ it "return true when valid response and using fingerprint" do
171
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed)
172
+ response.stubs(:conditions).returns(nil)
173
+ settings = OneLogin::RubySaml::Settings.new
174
+ response.settings = settings
175
+ settings.idp_cert = nil
176
+ settings.idp_cert_fingerprint = "4B:68:C4:53:C7:D9:94:AA:D9:02:5C:99:D5:EF:CF:56:62:87:FE:8D"
177
+ assert response.is_valid?
178
+ end
179
+
180
+ it "return true when valid response using certificate" do
99
181
  response = OneLogin::RubySaml::Response.new(response_document_valid_signed)
100
182
  response.stubs(:conditions).returns(nil)
101
183
  settings = OneLogin::RubySaml::Settings.new
@@ -136,6 +218,51 @@ class ResponseTest < Minitest::Test
136
218
  assert response.validate!
137
219
  end
138
220
 
221
+ it "support signature elements with no KeyInfo if cert provided" do
222
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed_without_x509certificate)
223
+ response.stubs(:conditions).returns(nil)
224
+ settings = OneLogin::RubySaml::Settings.new
225
+ response.settings = settings
226
+ settings.idp_cert = ruby_saml_cert
227
+ settings.idp_cert_fingerprint = nil
228
+ XMLSecurity::SignedDocument.any_instance.expects(:validate_signature).returns(true)
229
+ assert response.validate!
230
+ end
231
+
232
+ it "support signature elements with no KeyInfo if cert provided as text" do
233
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed_without_x509certificate)
234
+ response.stubs(:conditions).returns(nil)
235
+ settings = OneLogin::RubySaml::Settings.new
236
+ response.settings = settings
237
+ settings.idp_cert = ruby_saml_cert_text
238
+ settings.idp_cert_fingerprint = nil
239
+ XMLSecurity::SignedDocument.any_instance.expects(:validate_signature).returns(true)
240
+ assert response.validate!
241
+ end
242
+
243
+ it "returns an error if the signature contains no KeyInfo, cert is not provided and soft" do
244
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed_without_x509certificate)
245
+ response.stubs(:conditions).returns(nil)
246
+ settings = OneLogin::RubySaml::Settings.new
247
+ response.settings = settings
248
+ settings.idp_cert = nil
249
+ settings.idp_cert_fingerprint = "28:74:9B:E8:1F:E8:10:9C:A8:7C:A9:C3:E3:C5:01:6C:92:1C:B4:BA"
250
+ assert !response.is_valid?
251
+ end
252
+
253
+ it "raises an exception if the signature contains no KeyInfo, cert is not provided and no soft" do
254
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed_without_x509certificate)
255
+ response.stubs(:conditions).returns(nil)
256
+ settings = OneLogin::RubySaml::Settings.new
257
+ response.settings = settings
258
+ settings.idp_cert = nil
259
+ settings.idp_cert_fingerprint = "28:74:9B:E8:1F:E8:10:9C:A8:7C:A9:C3:E3:C5:01:6C:92:1C:B4:BA"
260
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
261
+ response.validate!
262
+ end
263
+ assert_equal "Certificate element missing in response (ds:X509Certificate) and not cert provided at settings", err.message
264
+ end
265
+
139
266
  it "validate ADFS assertions" do
140
267
  response = OneLogin::RubySaml::Response.new(fixture(:adfs_response_sha256))
141
268
  response.stubs(:conditions).returns(nil)
@@ -154,16 +281,6 @@ class ResponseTest < Minitest::Test
154
281
  assert response.validate!
155
282
  end
156
283
 
157
- it "validate SAML 2.0 XML structure" do
158
- resp_xml = Base64.decode64(response_document_valid_signed).gsub(/emailAddress/,'test')
159
- response = OneLogin::RubySaml::Response.new(Base64.encode64(resp_xml))
160
- response.stubs(:conditions).returns(nil)
161
- settings = OneLogin::RubySaml::Settings.new
162
- settings.idp_cert_fingerprint = signature_fingerprint_1
163
- response.settings = settings
164
- assert_raises(OneLogin::RubySaml::ValidationError, 'Digest mismatch'){ response.validate! }
165
- end
166
-
167
284
  it "Prevent node text with comment (VU#475445) attack" do
168
285
  response_doc = File.read(File.join(File.dirname(__FILE__), "responses", 'response_node_text_attack.xml.base64'))
169
286
  response = OneLogin::RubySaml::Response.new(response_doc)
@@ -206,6 +323,31 @@ class ResponseTest < Minitest::Test
206
323
  end
207
324
  end
208
325
 
326
+ describe "#validate_issuer" do
327
+ it "return true when the issuer of the Message/Assertion matches the IdP entityId" do
328
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed)
329
+ response.settings = settings
330
+ assert response.send(:validate_issuer)
331
+
332
+ response.settings.idp_entity_id = 'https://app.onelogin.com/saml2'
333
+ assert response.send(:validate_issuer)
334
+ end
335
+
336
+ it "return false when the issuer of the Message does not match the IdP entityId" do
337
+ response = OneLogin::RubySaml::Response.new(read_invalid_response("invalid_issuer_message.xml.base64"))
338
+ response.settings = settings
339
+ response.settings.idp_entity_id = 'http://idp.example.com/'
340
+ assert !response.send(:validate_issuer)
341
+ end
342
+
343
+ it "return false when the issuer of the Assertion does not match the IdP entityId" do
344
+ response = OneLogin::RubySaml::Response.new(read_invalid_response("invalid_issuer_assertion.xml.base64"))
345
+ response.settings = settings
346
+ response.settings.idp_entity_id = 'http://idp.example.com/'
347
+ assert !response.send(:validate_issuer)
348
+ end
349
+ end
350
+
209
351
  describe "#name_id" do
210
352
  it "extract the value of the name id element" do
211
353
  response = OneLogin::RubySaml::Response.new(response_document)
@@ -226,6 +368,23 @@ class ResponseTest < Minitest::Test
226
368
  end
227
369
  end
228
370
 
371
+ describe "#name_id_format" do
372
+ it "extract the value of the name id element" do
373
+ response = OneLogin::RubySaml::Response.new(response_document)
374
+ response_signed = OneLogin::RubySaml::Response.new(response_document_valid_signed)
375
+ assert_equal "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress", response.name_id_format
376
+ assert_equal "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress", response_signed.name_id_format
377
+ end
378
+ end
379
+
380
+ describe "#sessionindex" do
381
+ it "extract the value of the sessionindex element" do
382
+ response = OneLogin::RubySaml::Response.new(fixture(:simple_saml_php))
383
+ assert_equal "_51be37965feb5579d803141076936dc2e9d1d98ebf", response.sessionindex
384
+ end
385
+ end
386
+
387
+
229
388
  describe "#check_conditions" do
230
389
  it "check time conditions" do
231
390
  response = OneLogin::RubySaml::Response.new(response_document)
@@ -252,6 +411,54 @@ class ResponseTest < Minitest::Test
252
411
  end
253
412
  end
254
413
 
414
+ describe "validate_signature" do
415
+ it "raises an exception when no cert or fingerprint provided" do
416
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed)
417
+ settings = OneLogin::RubySaml::Settings.new
418
+ response.settings = settings
419
+ settings.idp_cert = nil
420
+ settings.idp_cert_fingerprint = nil
421
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
422
+ response.send(:validate_signature, false)
423
+ end
424
+ assert_equal "No fingerprint or certificate on settings", err.message
425
+ end
426
+
427
+ it "raises an exception when wrong cert provided" do
428
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed)
429
+ settings = OneLogin::RubySaml::Settings.new
430
+ response.settings = settings
431
+ settings.idp_cert = ruby_saml_cert2
432
+ settings.idp_cert_fingerprint = nil
433
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
434
+ response.send(:validate_signature, false)
435
+ end
436
+ assert_equal "Fingerprint mismatch", err.message
437
+ end
438
+
439
+ it "raises an exception when wrong fingerprint provided" do
440
+ response = OneLogin::RubySaml::Response.new(response_document_valid_signed)
441
+ settings = OneLogin::RubySaml::Settings.new
442
+ response.settings = settings
443
+ settings.idp_cert = nil
444
+ settings.idp_cert_fingerprint = "28:74:9B:E8:1F:E8:10:9C:A8:7C:A9:C3:E3:C5:01:6C:92:1C:B4:BA"
445
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
446
+ response.send(:validate_signature, false)
447
+ end
448
+ assert_equal "Fingerprint mismatch", err.message
449
+ end
450
+
451
+ it "raises an exception when no signature" do
452
+ response_no_signed_elements = OneLogin::RubySaml::Response.new(read_invalid_response("no_signature.xml.base64"))
453
+ settings.idp_cert_fingerprint = signature_fingerprint_1
454
+ response_no_signed_elements.settings = settings
455
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
456
+ response_no_signed_elements.validate!
457
+ end
458
+ assert_equal "Found an unexpected number of Signature Element. SAML Response rejected", err.message
459
+ end
460
+ end
461
+
255
462
  describe "#attributes" do
256
463
  before do
257
464
  @response = OneLogin::RubySaml::Response.new(response_document)
@@ -444,6 +651,10 @@ class ResponseTest < Minitest::Test
444
651
  response_wrapped.stubs(:validate_subject_confirmation).returns(true)
445
652
  settings.idp_cert_fingerprint = "385b1eec71143f00db6af936e2ea12a28771d72c"
446
653
  assert !response_wrapped.is_valid?
654
+ err = assert_raises(OneLogin::RubySaml::ValidationError) do
655
+ response_wrapped.validate!
656
+ end
657
+ assert_equal "Found an invalid Signed Element. SAML Response rejected", err.message
447
658
  end
448
659
  end
449
660
 
@@ -455,8 +666,9 @@ class ResponseTest < Minitest::Test
455
666
  settings.idp_cert_fingerprint = '4b68c453c7d994aad9025c99d5efcf566287fe8d'
456
667
  response_wrapped.stubs(:conditions).returns(nil)
457
668
  response_wrapped.stubs(:validate_subject_confirmation).returns(true)
669
+ response_wrapped.stubs(:validate_structure).returns(true)
458
670
  assert !response_wrapped.is_valid?
459
- assert_raises(OneLogin::RubySaml::ValidationError, "SAML Response must contain 1 assertion"){ response_wrapped.validate! }
671
+ assert !response_wrapped.validate!
460
672
  end
461
673
  end
462
674