ruby-saml 1.7.0 → 1.12.0

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 (153) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +37 -15
  3. data/README.md +119 -23
  4. data/changelog.md +60 -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 +25 -5
  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 +44 -17
  19. data/lib/onelogin/ruby-saml/utils.rb +88 -11
  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 -272
  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 -1527
  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_double_status_code.xml.base64 +0 -1
  109. data/test/responses/response_encrypted_attrs.xml.base64 +0 -1
  110. data/test/responses/response_encrypted_nameid.xml.base64 +0 -1
  111. data/test/responses/response_eval.xml +0 -7
  112. data/test/responses/response_no_cert_and_encrypted_attrs.xml +0 -29
  113. data/test/responses/response_node_text_attack.xml.base64 +0 -1
  114. data/test/responses/response_unsigned_xml_base64 +0 -1
  115. data/test/responses/response_with_ampersands.xml +0 -139
  116. data/test/responses/response_with_ampersands.xml.base64 +0 -93
  117. data/test/responses/response_with_ds_namespace_at_the_root.xml.base64 +0 -1
  118. data/test/responses/response_with_multiple_attribute_statements.xml +0 -72
  119. data/test/responses/response_with_multiple_attribute_values.xml +0 -67
  120. data/test/responses/response_with_retrieval_method.xml +0 -26
  121. data/test/responses/response_with_saml2_namespace.xml.base64 +0 -102
  122. data/test/responses/response_with_signed_assertion.xml.base64 +0 -66
  123. data/test/responses/response_with_signed_assertion_2.xml.base64 +0 -1
  124. data/test/responses/response_with_signed_assertion_3.xml +0 -30
  125. data/test/responses/response_with_signed_message_and_assertion.xml +0 -34
  126. data/test/responses/response_with_undefined_recipient.xml.base64 +0 -1
  127. data/test/responses/response_without_attributes.xml.base64 +0 -79
  128. data/test/responses/response_without_reference_uri.xml.base64 +0 -1
  129. data/test/responses/response_wrapped.xml.base64 +0 -150
  130. data/test/responses/signed_message_encrypted_signed_assertion.xml.base64 +0 -1
  131. data/test/responses/signed_message_encrypted_unsigned_assertion.xml.base64 +0 -1
  132. data/test/responses/signed_nameid_in_atts.xml +0 -47
  133. data/test/responses/signed_unqual_nameid_in_atts.xml +0 -47
  134. data/test/responses/simple_saml_php.xml +0 -71
  135. data/test/responses/starfield_response.xml.base64 +0 -1
  136. data/test/responses/test_sign.xml +0 -43
  137. data/test/responses/unsigned_encrypted_adfs.xml +0 -23
  138. data/test/responses/unsigned_message_aes128_encrypted_signed_assertion.xml.base64 +0 -1
  139. data/test/responses/unsigned_message_aes192_encrypted_signed_assertion.xml.base64 +0 -1
  140. data/test/responses/unsigned_message_aes256_encrypted_signed_assertion.xml.base64 +0 -1
  141. data/test/responses/unsigned_message_des192_encrypted_signed_assertion.xml.base64 +0 -1
  142. data/test/responses/unsigned_message_encrypted_assertion_without_saml_namespace.xml.base64 +0 -1
  143. data/test/responses/unsigned_message_encrypted_signed_assertion.xml.base64 +0 -1
  144. data/test/responses/unsigned_message_encrypted_unsigned_assertion.xml.base64 +0 -1
  145. data/test/responses/valid_response.xml.base64 +0 -1
  146. data/test/responses/valid_response_without_x509certificate.xml.base64 +0 -1
  147. data/test/saml_message_test.rb +0 -56
  148. data/test/settings_test.rb +0 -301
  149. data/test/slo_logoutrequest_test.rb +0 -448
  150. data/test/slo_logoutresponse_test.rb +0 -185
  151. data/test/test_helper.rb +0 -323
  152. data/test/utils_test.rb +0 -217
  153. data/test/xml_security_test.rb +0 -421
data/test/request_test.rb DELETED
@@ -1,296 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
2
-
3
- require 'onelogin/ruby-saml/authrequest'
4
-
5
- class RequestTest < Minitest::Test
6
-
7
- describe "Authrequest" do
8
- let(:settings) { OneLogin::RubySaml::Settings.new }
9
-
10
- before do
11
- settings.idp_sso_target_url = "http://example.com"
12
- end
13
-
14
- it "create the deflated SAMLRequest URL parameter" do
15
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
16
- assert_match /^http:\/\/example\.com\?SAMLRequest=/, auth_url
17
- payload = CGI.unescape(auth_url.split("=").last)
18
- decoded = Base64.decode64(payload)
19
-
20
- zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
21
- inflated = zstream.inflate(decoded)
22
- zstream.finish
23
- zstream.close
24
-
25
- assert_match /^<samlp:AuthnRequest/, inflated
26
- end
27
-
28
- it "create the deflated SAMLRequest URL parameter including the Destination" do
29
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
30
- payload = CGI.unescape(auth_url.split("=").last)
31
- decoded = Base64.decode64(payload)
32
-
33
- zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
34
- inflated = zstream.inflate(decoded)
35
- zstream.finish
36
- zstream.close
37
-
38
- assert_match /<samlp:AuthnRequest[^<]* Destination='http:\/\/example.com'/, inflated
39
- end
40
-
41
- it "create the SAMLRequest URL parameter without deflating" do
42
- settings.compress_request = false
43
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
44
- assert_match /^http:\/\/example\.com\?SAMLRequest=/, auth_url
45
- payload = CGI.unescape(auth_url.split("=").last)
46
- decoded = Base64.decode64(payload)
47
-
48
- assert_match /^<samlp:AuthnRequest/, decoded
49
- end
50
-
51
- it "create the SAMLRequest URL parameter with IsPassive" do
52
- settings.passive = true
53
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
54
- assert_match /^http:\/\/example\.com\?SAMLRequest=/, auth_url
55
- payload = CGI.unescape(auth_url.split("=").last)
56
- decoded = Base64.decode64(payload)
57
-
58
- zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
59
- inflated = zstream.inflate(decoded)
60
- zstream.finish
61
- zstream.close
62
-
63
- assert_match /<samlp:AuthnRequest[^<]* IsPassive='true'/, inflated
64
- end
65
-
66
- it "create the SAMLRequest URL parameter with ProtocolBinding" do
67
- settings.protocol_binding = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
68
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
69
- assert_match /^http:\/\/example\.com\?SAMLRequest=/, auth_url
70
- payload = CGI.unescape(auth_url.split("=").last)
71
- decoded = Base64.decode64(payload)
72
-
73
- zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
74
- inflated = zstream.inflate(decoded)
75
- zstream.finish
76
- zstream.close
77
-
78
- assert_match /<samlp:AuthnRequest[^<]* ProtocolBinding='urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'/, inflated
79
- end
80
-
81
- it "create the SAMLRequest URL parameter with AttributeConsumingServiceIndex" do
82
- settings.attributes_index = 30
83
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
84
- assert_match /^http:\/\/example\.com\?SAMLRequest=/, auth_url
85
- payload = CGI.unescape(auth_url.split("=").last)
86
- decoded = Base64.decode64(payload)
87
-
88
- zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
89
- inflated = zstream.inflate(decoded)
90
- zstream.finish
91
- zstream.close
92
- assert_match /<samlp:AuthnRequest[^<]* AttributeConsumingServiceIndex='30'/, inflated
93
- end
94
-
95
- it "create the SAMLRequest URL parameter with ForceAuthn" do
96
- settings.force_authn = true
97
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
98
- assert_match /^http:\/\/example\.com\?SAMLRequest=/, auth_url
99
- payload = CGI.unescape(auth_url.split("=").last)
100
- decoded = Base64.decode64(payload)
101
-
102
- zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
103
- inflated = zstream.inflate(decoded)
104
- zstream.finish
105
- zstream.close
106
- assert_match /<samlp:AuthnRequest[^<]* ForceAuthn='true'/, inflated
107
- end
108
-
109
- it "create the SAMLRequest URL parameter with NameID Format" do
110
- settings.name_identifier_format = "urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
111
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
112
- assert_match /^http:\/\/example\.com\?SAMLRequest=/, auth_url
113
- payload = CGI.unescape(auth_url.split("=").last)
114
- decoded = Base64.decode64(payload)
115
- zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
116
- inflated = zstream.inflate(decoded)
117
- zstream.finish
118
- zstream.close
119
-
120
- assert_match /<samlp:NameIDPolicy[^<]* AllowCreate='true'/, inflated
121
- assert_match /<samlp:NameIDPolicy[^<]* Format='urn:oasis:names:tc:SAML:2.0:nameid-format:transient'/, inflated
122
- end
123
-
124
- it "accept extra parameters" do
125
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings, { :hello => "there" })
126
- assert_match /&hello=there$/, auth_url
127
-
128
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings, { :hello => nil })
129
- assert_match /&hello=$/, auth_url
130
- end
131
-
132
- describe "when the target url doesn't contain a query string" do
133
- it "create the SAMLRequest parameter correctly" do
134
-
135
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
136
- assert_match /^http:\/\/example.com\?SAMLRequest/, auth_url
137
- end
138
- end
139
-
140
- describe "when the target url contains a query string" do
141
- it "create the SAMLRequest parameter correctly" do
142
- settings.idp_sso_target_url = "http://example.com?field=value"
143
-
144
- auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
145
- assert_match /^http:\/\/example.com\?field=value&SAMLRequest/, auth_url
146
- end
147
- end
148
-
149
- it "create the saml:AuthnContextClassRef element correctly" do
150
- settings.authn_context = 'secure/name/password/uri'
151
- auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
152
- assert_match /<saml:AuthnContextClassRef>secure\/name\/password\/uri<\/saml:AuthnContextClassRef>/, auth_doc.to_s
153
- end
154
-
155
- it "create multiple saml:AuthnContextClassRef elements correctly" do
156
- settings.authn_context = ['secure/name/password/uri', 'secure/email/password/uri']
157
- auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
158
- assert_match /<saml:AuthnContextClassRef>secure\/name\/password\/uri<\/saml:AuthnContextClassRef>/, auth_doc.to_s
159
- assert_match /<saml:AuthnContextClassRef>secure\/email\/password\/uri<\/saml:AuthnContextClassRef>/, auth_doc.to_s
160
- end
161
-
162
- it "create the saml:AuthnContextClassRef with comparison exact" do
163
- settings.authn_context = 'secure/name/password/uri'
164
- auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
165
- assert_match /<samlp:RequestedAuthnContext[\S ]+Comparison='exact'/, auth_doc.to_s
166
- assert_match /<saml:AuthnContextClassRef>secure\/name\/password\/uri<\/saml:AuthnContextClassRef>/, auth_doc.to_s
167
- end
168
-
169
- it "create the saml:AuthnContextClassRef with comparison minimun" do
170
- settings.authn_context = 'secure/name/password/uri'
171
- settings.authn_context_comparison = 'minimun'
172
- auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
173
- assert_match /<samlp:RequestedAuthnContext[\S ]+Comparison='minimun'/, auth_doc.to_s
174
- assert_match /<saml:AuthnContextClassRef>secure\/name\/password\/uri<\/saml:AuthnContextClassRef>/, auth_doc.to_s
175
- end
176
-
177
- it "create the saml:AuthnContextDeclRef element correctly" do
178
- settings.authn_context_decl_ref = 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport'
179
- auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
180
- assert_match /<saml:AuthnContextDeclRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport<\/saml:AuthnContextDeclRef>/, auth_doc.to_s
181
- end
182
-
183
- describe "#create_params when the settings indicate to sign (embebed) the request" do
184
- before do
185
- settings.compress_request = false
186
- settings.idp_sso_target_url = "http://example.com?field=value"
187
- settings.security[:authn_requests_signed] = true
188
- settings.security[:embed_sign] = true
189
- settings.certificate = ruby_saml_cert_text
190
- settings.private_key = ruby_saml_key_text
191
- end
192
-
193
- it "create a signed request" do
194
- params = OneLogin::RubySaml::Authrequest.new.create_params(settings)
195
- request_xml = Base64.decode64(params["SAMLRequest"])
196
- assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], request_xml
197
- assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], request_xml
198
- end
199
-
200
- it "create a signed request with 256 digest and signature methods" do
201
- settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA256
202
- settings.security[:digest_method] = XMLSecurity::Document::SHA512
203
-
204
- params = OneLogin::RubySaml::Authrequest.new.create_params(settings)
205
-
206
- request_xml = Base64.decode64(params["SAMLRequest"])
207
- assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], request_xml
208
- assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'/>], request_xml
209
- assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2001/04/xmlenc#sha512'/>], request_xml
210
- end
211
- end
212
-
213
- describe "#create_params when the settings indicate to sign the request" do
214
- let(:cert) { OpenSSL::X509::Certificate.new(ruby_saml_cert_text) }
215
-
216
- before do
217
- settings.compress_request = false
218
- settings.idp_sso_target_url = "http://example.com?field=value"
219
- settings.assertion_consumer_service_binding = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST-SimpleSign"
220
- settings.security[:authn_requests_signed] = true
221
- settings.security[:embed_sign] = false
222
- settings.certificate = ruby_saml_cert_text
223
- settings.private_key = ruby_saml_key_text
224
- end
225
-
226
- it "create a signature parameter with RSA_SHA1 and validate it" do
227
- settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA1
228
-
229
- params = OneLogin::RubySaml::Authrequest.new.create_params(settings, :RelayState => 'http://example.com')
230
- assert params['SAMLRequest']
231
- assert params[:RelayState]
232
- assert params['Signature']
233
- assert_equal params['SigAlg'], XMLSecurity::Document::RSA_SHA1
234
-
235
- query_string = "SAMLRequest=#{CGI.escape(params['SAMLRequest'])}"
236
- query_string << "&RelayState=#{CGI.escape(params[:RelayState])}"
237
- query_string << "&SigAlg=#{CGI.escape(params['SigAlg'])}"
238
-
239
- signature_algorithm = XMLSecurity::BaseDocument.new.algorithm(params['SigAlg'])
240
- assert_equal signature_algorithm, OpenSSL::Digest::SHA1
241
-
242
- assert cert.public_key.verify(signature_algorithm.new, Base64.decode64(params['Signature']), query_string)
243
- end
244
-
245
- it "create a signature parameter with RSA_SHA256 and validate it" do
246
- settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA256
247
-
248
- params = OneLogin::RubySaml::Authrequest.new.create_params(settings, :RelayState => 'http://example.com')
249
- assert params['Signature']
250
- assert_equal params['SigAlg'], XMLSecurity::Document::RSA_SHA256
251
-
252
- query_string = "SAMLRequest=#{CGI.escape(params['SAMLRequest'])}"
253
- query_string << "&RelayState=#{CGI.escape(params[:RelayState])}"
254
- query_string << "&SigAlg=#{CGI.escape(params['SigAlg'])}"
255
-
256
- signature_algorithm = XMLSecurity::BaseDocument.new.algorithm(params['SigAlg'])
257
- assert_equal signature_algorithm, OpenSSL::Digest::SHA256
258
- assert cert.public_key.verify(signature_algorithm.new, Base64.decode64(params['Signature']), query_string)
259
- end
260
- end
261
-
262
- it "create the saml:AuthnContextClassRef element correctly" do
263
- settings.authn_context = 'secure/name/password/uri'
264
- auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
265
- assert auth_doc.to_s =~ /<saml:AuthnContextClassRef>secure\/name\/password\/uri<\/saml:AuthnContextClassRef>/
266
- end
267
-
268
- it "create the saml:AuthnContextClassRef with comparison exact" do
269
- settings.authn_context = 'secure/name/password/uri'
270
- auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
271
- assert auth_doc.to_s =~ /<samlp:RequestedAuthnContext[\S ]+Comparison='exact'/
272
- assert auth_doc.to_s =~ /<saml:AuthnContextClassRef>secure\/name\/password\/uri<\/saml:AuthnContextClassRef>/
273
- end
274
-
275
- it "create the saml:AuthnContextClassRef with comparison minimun" do
276
- settings.authn_context = 'secure/name/password/uri'
277
- settings.authn_context_comparison = 'minimun'
278
- auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
279
- assert auth_doc.to_s =~ /<samlp:RequestedAuthnContext[\S ]+Comparison='minimun'/
280
- assert auth_doc.to_s =~ /<saml:AuthnContextClassRef>secure\/name\/password\/uri<\/saml:AuthnContextClassRef>/
281
- end
282
-
283
- it "create the saml:AuthnContextDeclRef element correctly" do
284
- settings.authn_context_decl_ref = 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport'
285
- auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
286
- assert auth_doc.to_s =~ /<saml:AuthnContextDeclRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport<\/saml:AuthnContextDeclRef>/
287
- end
288
-
289
- it "create multiple saml:AuthnContextDeclRef elements correctly " do
290
- settings.authn_context_decl_ref = ['name/password/uri', 'example/decl/ref']
291
- auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
292
- assert auth_doc.to_s =~ /<saml:AuthnContextDeclRef>name\/password\/uri<\/saml:AuthnContextDeclRef>/
293
- assert auth_doc.to_s =~ /<saml:AuthnContextDeclRef>example\/decl\/ref<\/saml:AuthnContextDeclRef>/
294
- end
295
- end
296
- end