ruby-saml 1.7.2 → 1.12.2

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 (154) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +37 -15
  3. data/README.md +127 -25
  4. data/changelog.md +61 -0
  5. data/lib/onelogin/ruby-saml/attribute_service.rb +1 -1
  6. data/lib/onelogin/ruby-saml/attributes.rb +24 -1
  7. data/lib/onelogin/ruby-saml/authrequest.rb +29 -6
  8. data/lib/onelogin/ruby-saml/idp_metadata_parser.rb +239 -169
  9. data/lib/onelogin/ruby-saml/logging.rb +4 -1
  10. data/lib/onelogin/ruby-saml/logoutrequest.rb +27 -7
  11. data/lib/onelogin/ruby-saml/logoutresponse.rb +32 -16
  12. data/lib/onelogin/ruby-saml/metadata.rb +11 -3
  13. data/lib/onelogin/ruby-saml/response.rb +91 -30
  14. data/lib/onelogin/ruby-saml/saml_message.rb +15 -5
  15. data/lib/onelogin/ruby-saml/setting_error.rb +6 -0
  16. data/lib/onelogin/ruby-saml/settings.rb +82 -9
  17. data/lib/onelogin/ruby-saml/slo_logoutrequest.rb +26 -7
  18. data/lib/onelogin/ruby-saml/slo_logoutresponse.rb +46 -18
  19. data/lib/onelogin/ruby-saml/utils.rb +87 -10
  20. data/lib/onelogin/ruby-saml/version.rb +1 -1
  21. data/lib/xml_security.rb +39 -12
  22. data/ruby-saml.gemspec +16 -8
  23. metadata +40 -274
  24. data/test/certificates/certificate1 +0 -12
  25. data/test/certificates/certificate_without_head_foot +0 -1
  26. data/test/certificates/formatted_certificate +0 -14
  27. data/test/certificates/formatted_chained_certificate +0 -42
  28. data/test/certificates/formatted_private_key +0 -12
  29. data/test/certificates/formatted_rsa_private_key +0 -12
  30. data/test/certificates/invalid_certificate1 +0 -1
  31. data/test/certificates/invalid_certificate2 +0 -1
  32. data/test/certificates/invalid_certificate3 +0 -12
  33. data/test/certificates/invalid_chained_certificate1 +0 -1
  34. data/test/certificates/invalid_private_key1 +0 -1
  35. data/test/certificates/invalid_private_key2 +0 -1
  36. data/test/certificates/invalid_private_key3 +0 -10
  37. data/test/certificates/invalid_rsa_private_key1 +0 -1
  38. data/test/certificates/invalid_rsa_private_key2 +0 -1
  39. data/test/certificates/invalid_rsa_private_key3 +0 -10
  40. data/test/certificates/ruby-saml-2.crt +0 -15
  41. data/test/certificates/ruby-saml.crt +0 -14
  42. data/test/certificates/ruby-saml.key +0 -15
  43. data/test/idp_metadata_parser_test.rb +0 -568
  44. data/test/logging_test.rb +0 -62
  45. data/test/logout_requests/invalid_slo_request.xml +0 -6
  46. data/test/logout_requests/slo_request.xml +0 -4
  47. data/test/logout_requests/slo_request.xml.base64 +0 -1
  48. data/test/logout_requests/slo_request_deflated.xml.base64 +0 -1
  49. data/test/logout_requests/slo_request_with_name_id_format.xml +0 -4
  50. data/test/logout_requests/slo_request_with_session_index.xml +0 -5
  51. data/test/logout_responses/logoutresponse_fixtures.rb +0 -67
  52. data/test/logoutrequest_test.rb +0 -212
  53. data/test/logoutresponse_test.rb +0 -402
  54. data/test/metadata/idp_descriptor.xml +0 -26
  55. data/test/metadata/idp_descriptor_2.xml +0 -56
  56. data/test/metadata/idp_descriptor_3.xml +0 -14
  57. data/test/metadata/idp_metadata_different_sign_and_encrypt_cert.xml +0 -72
  58. data/test/metadata/idp_metadata_multi_certs.xml +0 -75
  59. data/test/metadata/idp_metadata_multi_signing_certs.xml +0 -52
  60. data/test/metadata/idp_metadata_same_sign_and_encrypt_cert.xml +0 -71
  61. data/test/metadata/idp_multiple_descriptors.xml +0 -53
  62. data/test/metadata/no_idp_descriptor.xml +0 -21
  63. data/test/metadata_test.rb +0 -331
  64. data/test/request_test.rb +0 -296
  65. data/test/response_test.rb +0 -1535
  66. data/test/responses/adfs_response_sha1.xml +0 -46
  67. data/test/responses/adfs_response_sha256.xml +0 -46
  68. data/test/responses/adfs_response_sha384.xml +0 -46
  69. data/test/responses/adfs_response_sha512.xml +0 -46
  70. data/test/responses/adfs_response_xmlns.xml +0 -45
  71. data/test/responses/attackxee.xml +0 -13
  72. data/test/responses/invalids/duplicated_attributes.xml.base64 +0 -1
  73. data/test/responses/invalids/empty_destination.xml.base64 +0 -1
  74. data/test/responses/invalids/empty_nameid.xml.base64 +0 -1
  75. data/test/responses/invalids/encrypted_new_attack.xml.base64 +0 -1
  76. data/test/responses/invalids/invalid_audience.xml.base64 +0 -1
  77. data/test/responses/invalids/invalid_issuer_assertion.xml.base64 +0 -1
  78. data/test/responses/invalids/invalid_issuer_message.xml.base64 +0 -1
  79. data/test/responses/invalids/invalid_signature_position.xml.base64 +0 -1
  80. data/test/responses/invalids/invalid_subjectconfirmation_inresponse.xml.base64 +0 -1
  81. data/test/responses/invalids/invalid_subjectconfirmation_nb.xml.base64 +0 -1
  82. data/test/responses/invalids/invalid_subjectconfirmation_noa.xml.base64 +0 -1
  83. data/test/responses/invalids/invalid_subjectconfirmation_recipient.xml.base64 +0 -1
  84. data/test/responses/invalids/multiple_assertions.xml.base64 +0 -2
  85. data/test/responses/invalids/multiple_signed.xml.base64 +0 -1
  86. data/test/responses/invalids/no_authnstatement.xml.base64 +0 -1
  87. data/test/responses/invalids/no_conditions.xml.base64 +0 -1
  88. data/test/responses/invalids/no_id.xml.base64 +0 -1
  89. data/test/responses/invalids/no_issuer_assertion.xml.base64 +0 -1
  90. data/test/responses/invalids/no_issuer_response.xml.base64 +0 -1
  91. data/test/responses/invalids/no_nameid.xml.base64 +0 -1
  92. data/test/responses/invalids/no_saml2.xml.base64 +0 -1
  93. data/test/responses/invalids/no_signature.xml.base64 +0 -1
  94. data/test/responses/invalids/no_status.xml.base64 +0 -1
  95. data/test/responses/invalids/no_status_code.xml.base64 +0 -1
  96. data/test/responses/invalids/no_subjectconfirmation_data.xml.base64 +0 -1
  97. data/test/responses/invalids/no_subjectconfirmation_method.xml.base64 +0 -1
  98. data/test/responses/invalids/response_invalid_signed_element.xml.base64 +0 -1
  99. data/test/responses/invalids/response_with_concealed_signed_assertion.xml +0 -51
  100. data/test/responses/invalids/response_with_doubled_signed_assertion.xml +0 -49
  101. data/test/responses/invalids/signature_wrapping_attack.xml.base64 +0 -1
  102. data/test/responses/invalids/status_code_responder.xml.base64 +0 -1
  103. data/test/responses/invalids/status_code_responer_and_msg.xml.base64 +0 -1
  104. data/test/responses/invalids/wrong_spnamequalifier.xml.base64 +0 -1
  105. data/test/responses/no_signature_ns.xml +0 -48
  106. data/test/responses/open_saml_response.xml +0 -56
  107. data/test/responses/response_assertion_wrapped.xml.base64 +0 -93
  108. data/test/responses/response_audience_self_closed_tag.xml.base64 +0 -1
  109. data/test/responses/response_double_status_code.xml.base64 +0 -1
  110. data/test/responses/response_encrypted_attrs.xml.base64 +0 -1
  111. data/test/responses/response_encrypted_nameid.xml.base64 +0 -1
  112. data/test/responses/response_eval.xml +0 -7
  113. data/test/responses/response_no_cert_and_encrypted_attrs.xml +0 -29
  114. data/test/responses/response_node_text_attack.xml.base64 +0 -1
  115. data/test/responses/response_unsigned_xml_base64 +0 -1
  116. data/test/responses/response_with_ampersands.xml +0 -139
  117. data/test/responses/response_with_ampersands.xml.base64 +0 -93
  118. data/test/responses/response_with_ds_namespace_at_the_root.xml.base64 +0 -1
  119. data/test/responses/response_with_multiple_attribute_statements.xml +0 -72
  120. data/test/responses/response_with_multiple_attribute_values.xml +0 -67
  121. data/test/responses/response_with_retrieval_method.xml +0 -26
  122. data/test/responses/response_with_saml2_namespace.xml.base64 +0 -102
  123. data/test/responses/response_with_signed_assertion.xml.base64 +0 -66
  124. data/test/responses/response_with_signed_assertion_2.xml.base64 +0 -1
  125. data/test/responses/response_with_signed_assertion_3.xml +0 -30
  126. data/test/responses/response_with_signed_message_and_assertion.xml +0 -34
  127. data/test/responses/response_with_undefined_recipient.xml.base64 +0 -1
  128. data/test/responses/response_without_attributes.xml.base64 +0 -79
  129. data/test/responses/response_without_reference_uri.xml.base64 +0 -1
  130. data/test/responses/response_wrapped.xml.base64 +0 -150
  131. data/test/responses/signed_message_encrypted_signed_assertion.xml.base64 +0 -1
  132. data/test/responses/signed_message_encrypted_unsigned_assertion.xml.base64 +0 -1
  133. data/test/responses/signed_nameid_in_atts.xml +0 -47
  134. data/test/responses/signed_unqual_nameid_in_atts.xml +0 -47
  135. data/test/responses/simple_saml_php.xml +0 -71
  136. data/test/responses/starfield_response.xml.base64 +0 -1
  137. data/test/responses/test_sign.xml +0 -43
  138. data/test/responses/unsigned_encrypted_adfs.xml +0 -23
  139. data/test/responses/unsigned_message_aes128_encrypted_signed_assertion.xml.base64 +0 -1
  140. data/test/responses/unsigned_message_aes192_encrypted_signed_assertion.xml.base64 +0 -1
  141. data/test/responses/unsigned_message_aes256_encrypted_signed_assertion.xml.base64 +0 -1
  142. data/test/responses/unsigned_message_des192_encrypted_signed_assertion.xml.base64 +0 -1
  143. data/test/responses/unsigned_message_encrypted_assertion_without_saml_namespace.xml.base64 +0 -1
  144. data/test/responses/unsigned_message_encrypted_signed_assertion.xml.base64 +0 -1
  145. data/test/responses/unsigned_message_encrypted_unsigned_assertion.xml.base64 +0 -1
  146. data/test/responses/valid_response.xml.base64 +0 -1
  147. data/test/responses/valid_response_without_x509certificate.xml.base64 +0 -1
  148. data/test/saml_message_test.rb +0 -56
  149. data/test/settings_test.rb +0 -301
  150. data/test/slo_logoutrequest_test.rb +0 -448
  151. data/test/slo_logoutresponse_test.rb +0 -185
  152. data/test/test_helper.rb +0 -323
  153. data/test/utils_test.rb +0 -254
  154. data/test/xml_security_test.rb +0 -421
@@ -1,301 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
2
-
3
- require 'onelogin/ruby-saml/settings'
4
-
5
- class SettingsTest < Minitest::Test
6
-
7
- describe "Settings" do
8
- before do
9
- @settings = OneLogin::RubySaml::Settings.new
10
- end
11
-
12
- it "should provide getters and settings" do
13
- accessors = [
14
- :idp_entity_id, :idp_sso_target_url, :idp_slo_target_url,
15
- :idp_cert, :idp_cert_fingerprint, :idp_cert_fingerprint_algorithm, :idp_cert_multi,
16
- :idp_attribute_names, :issuer, :assertion_consumer_service_url, :assertion_consumer_service_binding,
17
- :single_logout_service_url, :single_logout_service_binding,
18
- :sp_name_qualifier, :name_identifier_format, :name_identifier_value,
19
- :sessionindex, :attributes_index, :passive, :force_authn,
20
- :compress_request, :double_quote_xml_attribute_values, :protocol_binding,
21
- :security, :certificate, :private_key,
22
- :authn_context, :authn_context_comparison, :authn_context_decl_ref,
23
- :assertion_consumer_logout_service_url,
24
- :assertion_consumer_logout_service_binding
25
- ]
26
-
27
- accessors.each do |accessor|
28
- value = Kernel.rand
29
- @settings.send("#{accessor}=".to_sym, value)
30
- assert_equal value, @settings.send(accessor)
31
- end
32
-
33
- end
34
-
35
- it "create settings from hash" do
36
- config = {
37
- :assertion_consumer_service_url => "http://app.muda.no/sso",
38
- :issuer => "http://muda.no",
39
- :sp_name_qualifier => "http://sso.muda.no",
40
- :idp_sso_target_url => "http://sso.muda.no/sso",
41
- :idp_slo_target_url => "http://sso.muda.no/slo",
42
- :idp_cert_fingerprint => "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00",
43
- :name_identifier_format => "urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
44
- :attributes_index => 30,
45
- :passive => true,
46
- :protocol_binding => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
47
- }
48
- @settings = OneLogin::RubySaml::Settings.new(config)
49
-
50
- config.each do |k,v|
51
- assert_equal v, @settings.send(k)
52
- end
53
- end
54
-
55
- it "configure attribute service attributes correctly" do
56
- @settings.attribute_consuming_service.configure do
57
- service_name "Test Service"
58
- add_attribute :name => "Name", :name_format => "Name Format", :friendly_name => "Friendly Name"
59
- end
60
-
61
- assert_equal @settings.attribute_consuming_service.configured?, true
62
- assert_equal @settings.attribute_consuming_service.name, "Test Service"
63
- assert_equal @settings.attribute_consuming_service.attributes, [{:name => "Name", :name_format => "Name Format", :friendly_name => "Friendly Name" }]
64
- end
65
-
66
- it "does not modify default security settings" do
67
- settings = OneLogin::RubySaml::Settings.new
68
- settings.security[:authn_requests_signed] = true
69
- settings.security[:embed_sign] = true
70
- settings.security[:digest_method] = XMLSecurity::Document::SHA256
71
- settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA256
72
-
73
- new_settings = OneLogin::RubySaml::Settings.new
74
- assert_equal new_settings.security[:authn_requests_signed], false
75
- assert_equal new_settings.security[:embed_sign], false
76
- assert_equal new_settings.security[:digest_method], XMLSecurity::Document::SHA1
77
- assert_equal new_settings.security[:signature_method], XMLSecurity::Document::RSA_SHA1
78
- end
79
-
80
- describe "#single_logout_service_url" do
81
- it "when single_logout_service_url is nil but assertion_consumer_logout_service_url returns its value" do
82
- @settings.single_logout_service_url = nil
83
- @settings.assertion_consumer_logout_service_url = "http://app.muda.no/sls"
84
-
85
- assert_equal "http://app.muda.no/sls", @settings.single_logout_service_url
86
- end
87
- end
88
-
89
- describe "#single_logout_service_binding" do
90
- it "when single_logout_service_binding is nil but assertion_consumer_logout_service_binding returns its value" do
91
- @settings.single_logout_service_binding = nil
92
- @settings.assertion_consumer_logout_service_binding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
93
-
94
- assert_equal "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect", @settings.single_logout_service_binding
95
- end
96
- end
97
-
98
- describe "#get_idp_cert" do
99
- it "returns nil when the cert is an empty string" do
100
- @settings.idp_cert = ""
101
- assert_nil @settings.get_idp_cert
102
- end
103
-
104
- it "returns nil when the cert is nil" do
105
- @settings.idp_cert = nil
106
- assert_nil @settings.get_idp_cert
107
- end
108
-
109
- it "returns the certificate when it is valid" do
110
- @settings.idp_cert = ruby_saml_cert_text
111
- assert @settings.get_idp_cert.kind_of? OpenSSL::X509::Certificate
112
- end
113
-
114
- it "raises when the certificate is not valid" do
115
- # formatted but invalid cert
116
- @settings.idp_cert = read_certificate("formatted_certificate")
117
- assert_raises(OpenSSL::X509::CertificateError) {
118
- @settings.get_idp_cert
119
- }
120
- end
121
- end
122
-
123
- describe "#get_idp_cert_multi" do
124
- it "returns nil when the value is empty" do
125
- @settings.idp_cert = {}
126
- assert_nil @settings.get_idp_cert_multi
127
- end
128
-
129
- it "returns nil when the idp_cert_multi is nil or empty" do
130
- @settings.idp_cert_multi = nil
131
- assert_nil @settings.get_idp_cert_multi
132
- end
133
-
134
- it "returns partial hash when contains some values" do
135
- empty_multi = {
136
- :signing => [],
137
- :encryption => []
138
- }
139
-
140
- @settings.idp_cert_multi = {
141
- :signing => []
142
- }
143
- assert_equal empty_multi, @settings.get_idp_cert_multi
144
-
145
- @settings.idp_cert_multi = {
146
- :encryption => []
147
- }
148
- assert_equal empty_multi, @settings.get_idp_cert_multi
149
-
150
- @settings.idp_cert_multi = {
151
- :signing => [],
152
- :encryption => []
153
- }
154
- assert_equal empty_multi, @settings.get_idp_cert_multi
155
-
156
- @settings.idp_cert_multi = {
157
- :yyy => [],
158
- :zzz => []
159
- }
160
- assert_equal empty_multi, @settings.get_idp_cert_multi
161
- end
162
-
163
- it "returns the hash with certificates when values were valid" do
164
- certificates = ruby_saml_cert_text
165
- @settings.idp_cert_multi = {
166
- :signing => [ruby_saml_cert_text],
167
- :encryption => [ruby_saml_cert_text],
168
- }
169
-
170
- assert @settings.get_idp_cert_multi.kind_of? Hash
171
- assert @settings.get_idp_cert_multi[:signing].kind_of? Array
172
- assert @settings.get_idp_cert_multi[:encryption].kind_of? Array
173
- assert @settings.get_idp_cert_multi[:signing][0].kind_of? OpenSSL::X509::Certificate
174
- assert @settings.get_idp_cert_multi[:encryption][0].kind_of? OpenSSL::X509::Certificate
175
- end
176
-
177
- it "raises when there is a cert in idp_cert_multi not valid" do
178
- certificate = read_certificate("formatted_certificate")
179
-
180
- @settings.idp_cert_multi = {
181
- :signing => [],
182
- :encryption => []
183
- }
184
- @settings.idp_cert_multi[:signing].push(certificate)
185
- @settings.idp_cert_multi[:encryption].push(certificate)
186
-
187
- assert_raises(OpenSSL::X509::CertificateError) {
188
- @settings.get_idp_cert_multi
189
- }
190
- end
191
- end
192
-
193
- describe "#get_sp_cert" do
194
- it "returns nil when the cert is an empty string" do
195
- @settings.certificate = ""
196
- assert_nil @settings.get_sp_cert
197
- end
198
-
199
- it "returns nil when the cert is nil" do
200
- @settings.certificate = nil
201
- assert_nil @settings.get_sp_cert
202
- end
203
-
204
- it "returns the certificate when it is valid" do
205
- @settings.certificate = ruby_saml_cert_text
206
- assert @settings.get_sp_cert.kind_of? OpenSSL::X509::Certificate
207
- end
208
-
209
- it "raises when the certificate is not valid" do
210
- # formatted but invalid cert
211
- @settings.certificate = read_certificate("formatted_certificate")
212
- assert_raises(OpenSSL::X509::CertificateError) {
213
- @settings.get_sp_cert
214
- }
215
- end
216
-
217
- end
218
-
219
- describe "#get_sp_cert_new" do
220
- it "returns nil when the cert is an empty string" do
221
- @settings.certificate_new = ""
222
- assert_nil @settings.get_sp_cert_new
223
- end
224
-
225
- it "returns nil when the cert is nil" do
226
- @settings.certificate_new = nil
227
- assert_nil @settings.get_sp_cert_new
228
- end
229
-
230
- it "returns the certificate when it is valid" do
231
- @settings.certificate_new = ruby_saml_cert_text
232
- assert @settings.get_sp_cert_new.kind_of? OpenSSL::X509::Certificate
233
- end
234
-
235
- it "raises when the certificate is not valid" do
236
- # formatted but invalid cert
237
- @settings.certificate_new = read_certificate("formatted_certificate")
238
- assert_raises(OpenSSL::X509::CertificateError) {
239
- @settings.get_sp_cert_new
240
- }
241
- end
242
-
243
- end
244
-
245
- describe "#get_sp_key" do
246
- it "returns nil when the private key is an empty string" do
247
- @settings.private_key = ""
248
- assert_nil @settings.get_sp_key
249
- end
250
-
251
- it "returns nil when the private key is nil" do
252
- @settings.private_key = nil
253
- assert_nil @settings.get_sp_key
254
- end
255
-
256
- it "returns the private key when it is valid" do
257
- @settings.private_key = ruby_saml_key_text
258
- assert @settings.get_sp_key.kind_of? OpenSSL::PKey::RSA
259
- end
260
-
261
- it "raises when the private key is not valid" do
262
- # formatted but invalid rsa private key
263
- @settings.private_key = read_certificate("formatted_rsa_private_key")
264
- assert_raises(OpenSSL::PKey::RSAError) {
265
- @settings.get_sp_key
266
- }
267
- end
268
-
269
- end
270
-
271
- describe "#get_fingerprint" do
272
- it "get the fingerprint value when cert and fingerprint in settings are nil" do
273
- @settings.idp_cert_fingerprint = nil
274
- @settings.idp_cert = nil
275
- fingerprint = @settings.get_fingerprint
276
- assert_nil fingerprint
277
- end
278
-
279
- it "get the fingerprint value when there is a cert at the settings" do
280
- @settings.idp_cert_fingerprint = nil
281
- @settings.idp_cert = ruby_saml_cert_text
282
- fingerprint = @settings.get_fingerprint
283
- assert fingerprint.downcase == ruby_saml_cert_fingerprint.downcase
284
- end
285
-
286
- it "get the fingerprint value when there is a fingerprint at the settings" do
287
- @settings.idp_cert_fingerprint = ruby_saml_cert_fingerprint
288
- @settings.idp_cert = nil
289
- fingerprint = @settings.get_fingerprint
290
- assert fingerprint.downcase == ruby_saml_cert_fingerprint.downcase
291
- end
292
-
293
- it "get the fingerprint value when there are cert and fingerprint at the settings" do
294
- @settings.idp_cert_fingerprint = ruby_saml_cert_fingerprint
295
- @settings.idp_cert = ruby_saml_cert_text
296
- fingerprint = @settings.get_fingerprint
297
- assert fingerprint.downcase == ruby_saml_cert_fingerprint.downcase
298
- end
299
- end
300
- end
301
- end