ruby-saml 0.8.10 → 0.8.15

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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -1
  3. data/Rakefile +0 -14
  4. data/lib/onelogin/ruby-saml/authrequest.rb +3 -2
  5. data/lib/onelogin/ruby-saml/logoutrequest.rb +3 -0
  6. data/lib/onelogin/ruby-saml/logoutresponse.rb +1 -24
  7. data/lib/onelogin/ruby-saml/response.rb +206 -20
  8. data/lib/onelogin/ruby-saml/setting_error.rb +6 -0
  9. data/lib/onelogin/ruby-saml/settings.rb +26 -0
  10. data/lib/onelogin/ruby-saml/slo_logoutresponse.rb +3 -2
  11. data/lib/onelogin/ruby-saml/utils.rb +90 -0
  12. data/lib/onelogin/ruby-saml/version.rb +1 -1
  13. data/lib/xml_security.rb +222 -87
  14. data/test/certificates/ruby-saml-2.crt +15 -0
  15. data/test/logoutrequest_test.rb +124 -126
  16. data/test/logoutresponse_test.rb +22 -28
  17. data/test/response_test.rb +348 -129
  18. data/test/responses/adfs_response_xmlns.xml +45 -0
  19. data/test/responses/encrypted_new_attack.xml.base64 +1 -0
  20. data/test/responses/invalids/multiple_signed.xml.base64 +1 -0
  21. data/test/responses/invalids/no_signature.xml.base64 +1 -0
  22. data/test/responses/invalids/response_with_concealed_signed_assertion.xml +51 -0
  23. data/test/responses/invalids/response_with_doubled_signed_assertion.xml +49 -0
  24. data/test/responses/invalids/signature_wrapping_attack.xml.base64 +1 -0
  25. data/test/responses/response_with_concealed_signed_assertion.xml +51 -0
  26. data/test/responses/response_with_doubled_signed_assertion.xml +49 -0
  27. data/test/responses/response_with_signed_assertion_3.xml +30 -0
  28. data/test/responses/response_with_signed_message_and_assertion.xml +34 -0
  29. data/test/responses/response_with_undefined_recipient.xml.base64 +1 -0
  30. data/test/responses/response_wrapped.xml.base64 +150 -0
  31. data/test/responses/valid_response.xml.base64 +1 -0
  32. data/test/responses/valid_response_without_x509certificate.xml.base64 +1 -0
  33. data/test/settings_test.rb +5 -5
  34. data/test/test_helper.rb +110 -41
  35. data/test/utils_test.rb +10 -10
  36. data/test/xml_security_test.rb +359 -68
  37. metadata +38 -5
@@ -0,0 +1,15 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIICVDCCAb2gAwIBAgIBADANBgkqhkiG9w0BAQ0FADBHMQswCQYDVQQGEwJ1czEQ
3
+ MA4GA1UECAwHZXhhbXBsZTEQMA4GA1UECgwHZXhhbXBsZTEUMBIGA1UEAwwLZXhh
4
+ bXBsZS5jb20wHhcNMTcwNDA3MDgzMDAzWhcNMjcwNDA1MDgzMDAzWjBHMQswCQYD
5
+ VQQGEwJ1czEQMA4GA1UECAwHZXhhbXBsZTEQMA4GA1UECgwHZXhhbXBsZTEUMBIG
6
+ A1UEAwwLZXhhbXBsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKhP
7
+ S4/0azxbQekHHewQGKD7Pivr3CDpsrKxY3xlVanxj427OwzOb5KUVzsDEazumt6s
8
+ ZFY8HfidsjXY4EYA4ZzyL7ciIAR5vlAsIYN9nJ4AwVDnN/RjVwj+TN6BqWPLpVIp
9
+ Hc6Dl005HyE0zJnk1DZDn2tQVrIzbD3FhCp7YeotAgMBAAGjUDBOMB0GA1UdDgQW
10
+ BBRYZx4thASfNvR/E7NsCF2IaZ7wIDAfBgNVHSMEGDAWgBRYZx4thASfNvR/E7Ns
11
+ CF2IaZ7wIDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBDQUAA4GBACz4aobx9aG3
12
+ kh+rNyrlgM3K6dYfnKG1/YH5sJCAOvg8kDr0fQAQifH8lFVWumKUMoAe0bFTfwWt
13
+ p/VJ8MprrEJth6PFeZdczpuv+fpLcNj2VmNVJqvQYvS4m36OnBFh1QFZW8UrbFIf
14
+ dtm2nuZ+twSKqfKwjLdqcoX0p39h7Uw/
15
+ -----END CERTIFICATE-----
@@ -1,5 +1,4 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
2
- require 'uuid'
3
2
 
4
3
  class LogoutRequestTest < Minitest::Test
5
4
 
@@ -29,7 +28,7 @@ class LogoutRequestTest < Minitest::Test
29
28
  end
30
29
 
31
30
  it "set sessionindex" do
32
- sessionidx = UUID.new.generate
31
+ sessionidx = random_id
33
32
  settings.sessionindex = sessionidx
34
33
 
35
34
  unauth_url = OneLogin::RubySaml::Logoutrequest.new.create(settings, { :name_id => "there" })
@@ -78,169 +77,168 @@ class LogoutRequestTest < Minitest::Test
78
77
  assert_match %r[ID='#{unauth_req.uuid}'], inflated
79
78
  end
80
79
  end
81
- end
82
80
 
83
- describe "when the settings indicate to sign (embedded) logout request" do
84
81
 
85
- before do
86
- # sign the logout request
87
- settings.security[:logout_requests_signed] = true
88
- settings.security[:embed_sign] = true
89
- settings.certificate = ruby_saml_cert_text
90
- settings.private_key = ruby_saml_key_text
91
- end
82
+ describe "when the settings indicate to sign (embedded) logout request" do
92
83
 
93
- it "doesn't sign through create_xml_document" do
94
- unauth_req = OneLogin::RubySaml::Logoutrequest.new
95
- inflated = unauth_req.create_xml_document(settings).to_s
84
+ before do
85
+ # sign the logout request
86
+ settings.security[:logout_requests_signed] = true
87
+ settings.security[:embed_sign] = true
88
+ settings.certificate = ruby_saml_cert_text
89
+ settings.private_key = ruby_saml_key_text
90
+ end
96
91
 
97
- refute_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
98
- refute_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
99
- refute_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
100
- end
92
+ it "doesn't sign through create_xml_document" do
93
+ unauth_req = OneLogin::RubySaml::Logoutrequest.new
94
+ inflated = unauth_req.create_xml_document(settings).to_s
101
95
 
102
- it "sign unsigned request" do
103
- unauth_req = OneLogin::RubySaml::Logoutrequest.new
104
- unauth_req_doc = unauth_req.create_xml_document(settings)
105
- inflated = unauth_req_doc.to_s
96
+ refute_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
97
+ refute_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
98
+ refute_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
99
+ end
106
100
 
107
- refute_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
108
- refute_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
109
- refute_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
101
+ it "sign unsigned request" do
102
+ unauth_req = OneLogin::RubySaml::Logoutrequest.new
103
+ unauth_req_doc = unauth_req.create_xml_document(settings)
104
+ inflated = unauth_req_doc.to_s
110
105
 
111
- inflated = unauth_req.sign_document(unauth_req_doc, settings).to_s
106
+ refute_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
107
+ refute_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
108
+ refute_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
112
109
 
113
- assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
114
- assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
115
- assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
116
- end
110
+ inflated = unauth_req.sign_document(unauth_req_doc, settings).to_s
117
111
 
118
- it "signs through create_logout_request_xml_doc" do
119
- unauth_req = OneLogin::RubySaml::Logoutrequest.new
120
- inflated = unauth_req.create_logout_request_xml_doc(settings).to_s
112
+ assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
113
+ assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
114
+ assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
115
+ end
121
116
 
122
- assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
123
- assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
124
- assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
125
- end
117
+ it "signs through create_logout_request_xml_doc" do
118
+ unauth_req = OneLogin::RubySaml::Logoutrequest.new
119
+ inflated = unauth_req.create_logout_request_xml_doc(settings).to_s
126
120
 
127
- it "created a signed logout request" do
128
- settings.compress_request = true
121
+ assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
122
+ assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
123
+ assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
124
+ end
129
125
 
130
- unauth_req = OneLogin::RubySaml::Logoutrequest.new
131
- unauth_url = unauth_req.create(settings)
126
+ it "created a signed logout request" do
127
+ settings.compress_request = true
132
128
 
133
- inflated = decode_saml_request_payload(unauth_url)
134
- assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
135
- assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
136
- assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
137
- end
129
+ unauth_req = OneLogin::RubySaml::Logoutrequest.new
130
+ unauth_url = unauth_req.create(settings)
131
+
132
+ inflated = decode_saml_request_payload(unauth_url)
133
+ assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], inflated
134
+ assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], inflated
135
+ assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], inflated
136
+ end
138
137
 
139
- it "create a signed logout request with 256 digest and signature method" do
140
- settings.compress_request = false
141
- settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA256
142
- settings.security[:digest_method] = XMLSecurity::Document::SHA256
138
+ it "create a signed logout request with 256 digest and signature method" do
139
+ settings.compress_request = false
140
+ settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA256
141
+ settings.security[:digest_method] = XMLSecurity::Document::SHA256
143
142
 
144
- params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings)
145
- request_xml = Base64.decode64(params["SAMLRequest"])
143
+ params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings)
144
+ request_xml = Base64.decode64(params["SAMLRequest"])
146
145
 
147
- assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], request_xml
148
- assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'/>], request_xml
149
- assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2001/04/xmlenc#sha256'/>], request_xml
150
- end
146
+ assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], request_xml
147
+ assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'/>], request_xml
148
+ assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2001/04/xmlenc#sha256'/>], request_xml
149
+ end
151
150
 
152
- it "create a signed logout request with 512 digest and signature method RSA_SHA384" do
153
- settings.compress_request = false
154
- settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA384
155
- settings.security[:digest_method] = XMLSecurity::Document::SHA512
151
+ it "create a signed logout request with 512 digest and signature method RSA_SHA384" do
152
+ settings.compress_request = false
153
+ settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA384
154
+ settings.security[:digest_method] = XMLSecurity::Document::SHA512
156
155
 
157
- params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings)
158
- request_xml = Base64.decode64(params["SAMLRequest"])
156
+ params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings)
157
+ request_xml = Base64.decode64(params["SAMLRequest"])
159
158
 
160
- assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], request_xml
161
- assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2001/04/xmldsig-more#rsa-sha384'/>], request_xml
162
- assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2001/04/xmlenc#sha512'/>], request_xml
159
+ assert_match %r[<ds:SignatureValue>([a-zA-Z0-9/+=]+)</ds:SignatureValue>], request_xml
160
+ assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2001/04/xmldsig-more#rsa-sha384'/>], request_xml
161
+ assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2001/04/xmlenc#sha512'/>], request_xml
162
+ end
163
163
  end
164
- end
165
164
 
166
- describe "#create_params when the settings indicate to sign the logout request" do
165
+ describe "#create_params when the settings indicate to sign the logout request" do
167
166
 
168
- let(:cert) { OpenSSL::X509::Certificate.new(ruby_saml_cert_text) }
167
+ let(:cert) { OpenSSL::X509::Certificate.new(ruby_saml_cert_text) }
169
168
 
170
- before do
171
- # sign the logout request
172
- settings.security[:logout_requests_signed] = true
173
- settings.security[:embed_sign] = false
174
- settings.certificate = ruby_saml_cert_text
175
- settings.private_key = ruby_saml_key_text
176
- end
169
+ before do
170
+ # sign the logout request
171
+ settings.security[:logout_requests_signed] = true
172
+ settings.security[:embed_sign] = false
173
+ settings.certificate = ruby_saml_cert_text
174
+ settings.private_key = ruby_saml_key_text
175
+ end
177
176
 
178
- it "create a signature parameter with RSA_SHA1 / SHA1 and validate it" do
179
- settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA1
177
+ it "create a signature parameter with RSA_SHA1 / SHA1 and validate it" do
178
+ settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA1
180
179
 
181
- params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings, :RelayState => 'http://example.com')
182
- assert params['SAMLRequest']
183
- assert params[:RelayState]
184
- assert params['Signature']
185
- assert_equal params['SigAlg'], XMLSecurity::Document::RSA_SHA1
180
+ params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings, :RelayState => 'http://example.com')
181
+ assert params['SAMLRequest']
182
+ assert params[:RelayState]
183
+ assert params['Signature']
184
+ assert_equal params['SigAlg'], XMLSecurity::Document::RSA_SHA1
186
185
 
187
- query_string = "SAMLRequest=#{CGI.escape(params['SAMLRequest'])}"
188
- query_string << "&RelayState=#{CGI.escape(params[:RelayState])}"
189
- query_string << "&SigAlg=#{CGI.escape(params['SigAlg'])}"
186
+ query_string = "SAMLRequest=#{CGI.escape(params['SAMLRequest'])}"
187
+ query_string << "&RelayState=#{CGI.escape(params[:RelayState])}"
188
+ query_string << "&SigAlg=#{CGI.escape(params['SigAlg'])}"
190
189
 
191
- signature_algorithm = XMLSecurity::BaseDocument.new.algorithm(params['SigAlg'])
192
- assert_equal signature_algorithm, OpenSSL::Digest::SHA1
193
- assert cert.public_key.verify(signature_algorithm.new, Base64.decode64(params['Signature']), query_string)
194
- end
190
+ signature_algorithm = XMLSecurity::BaseDocument.new.algorithm(params['SigAlg'])
191
+ assert_equal signature_algorithm, OpenSSL::Digest::SHA1
192
+ assert cert.public_key.verify(signature_algorithm.new, Base64.decode64(params['Signature']), query_string)
193
+ end
195
194
 
196
- it "create a signature parameter with RSA_SHA256 / SHA256 and validate it" do
197
- settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA256
195
+ it "create a signature parameter with RSA_SHA256 / SHA256 and validate it" do
196
+ settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA256
198
197
 
199
- params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings, :RelayState => 'http://example.com')
200
- assert params['Signature']
201
- assert_equal params['SigAlg'], XMLSecurity::Document::RSA_SHA256
198
+ params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings, :RelayState => 'http://example.com')
199
+ assert params['Signature']
200
+ assert_equal params['SigAlg'], XMLSecurity::Document::RSA_SHA256
202
201
 
203
- query_string = "SAMLRequest=#{CGI.escape(params['SAMLRequest'])}"
204
- query_string << "&RelayState=#{CGI.escape(params[:RelayState])}"
205
- query_string << "&SigAlg=#{CGI.escape(params['SigAlg'])}"
202
+ query_string = "SAMLRequest=#{CGI.escape(params['SAMLRequest'])}"
203
+ query_string << "&RelayState=#{CGI.escape(params[:RelayState])}"
204
+ query_string << "&SigAlg=#{CGI.escape(params['SigAlg'])}"
206
205
 
207
- signature_algorithm = XMLSecurity::BaseDocument.new.algorithm(params['SigAlg'])
208
- assert_equal signature_algorithm, OpenSSL::Digest::SHA256
209
- assert cert.public_key.verify(signature_algorithm.new, Base64.decode64(params['Signature']), query_string)
210
- end
206
+ signature_algorithm = XMLSecurity::BaseDocument.new.algorithm(params['SigAlg'])
207
+ assert_equal signature_algorithm, OpenSSL::Digest::SHA256
208
+ assert cert.public_key.verify(signature_algorithm.new, Base64.decode64(params['Signature']), query_string)
209
+ end
211
210
 
212
- it "create a signature parameter with RSA_SHA384 / SHA384 and validate it" do
213
- settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA384
211
+ it "create a signature parameter with RSA_SHA384 / SHA384 and validate it" do
212
+ settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA384
214
213
 
215
- params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings, :RelayState => 'http://example.com')
216
- assert params['Signature']
217
- assert_equal params['SigAlg'], XMLSecurity::Document::RSA_SHA384
214
+ params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings, :RelayState => 'http://example.com')
215
+ assert params['Signature']
216
+ assert_equal params['SigAlg'], XMLSecurity::Document::RSA_SHA384
218
217
 
219
- query_string = "SAMLRequest=#{CGI.escape(params['SAMLRequest'])}"
220
- query_string << "&RelayState=#{CGI.escape(params[:RelayState])}"
221
- query_string << "&SigAlg=#{CGI.escape(params['SigAlg'])}"
218
+ query_string = "SAMLRequest=#{CGI.escape(params['SAMLRequest'])}"
219
+ query_string << "&RelayState=#{CGI.escape(params[:RelayState])}"
220
+ query_string << "&SigAlg=#{CGI.escape(params['SigAlg'])}"
222
221
 
223
- signature_algorithm = XMLSecurity::BaseDocument.new.algorithm(params['SigAlg'])
224
- assert_equal signature_algorithm, OpenSSL::Digest::SHA384
225
- assert cert.public_key.verify(signature_algorithm.new, Base64.decode64(params['Signature']), query_string)
226
- end
222
+ signature_algorithm = XMLSecurity::BaseDocument.new.algorithm(params['SigAlg'])
223
+ assert_equal signature_algorithm, OpenSSL::Digest::SHA384
224
+ assert cert.public_key.verify(signature_algorithm.new, Base64.decode64(params['Signature']), query_string)
225
+ end
227
226
 
228
- it "create a signature parameter with RSA_SHA512 / SHA512 and validate it" do
229
- settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA512
227
+ it "create a signature parameter with RSA_SHA512 / SHA512 and validate it" do
228
+ settings.security[:signature_method] = XMLSecurity::Document::RSA_SHA512
230
229
 
231
- params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings, :RelayState => 'http://example.com')
232
- assert params['Signature']
233
- assert_equal params['SigAlg'], XMLSecurity::Document::RSA_SHA512
230
+ params = OneLogin::RubySaml::Logoutrequest.new.create_params(settings, :RelayState => 'http://example.com')
231
+ assert params['Signature']
232
+ assert_equal params['SigAlg'], XMLSecurity::Document::RSA_SHA512
234
233
 
235
- query_string = "SAMLRequest=#{CGI.escape(params['SAMLRequest'])}"
236
- query_string << "&RelayState=#{CGI.escape(params[:RelayState])}"
237
- query_string << "&SigAlg=#{CGI.escape(params['SigAlg'])}"
234
+ query_string = "SAMLRequest=#{CGI.escape(params['SAMLRequest'])}"
235
+ query_string << "&RelayState=#{CGI.escape(params[:RelayState])}"
236
+ query_string << "&SigAlg=#{CGI.escape(params['SigAlg'])}"
238
237
 
239
- signature_algorithm = XMLSecurity::BaseDocument.new.algorithm(params['SigAlg'])
240
- assert_equal signature_algorithm, OpenSSL::Digest::SHA512
241
- assert cert.public_key.verify(signature_algorithm.new, Base64.decode64(params['Signature']), query_string)
238
+ signature_algorithm = XMLSecurity::BaseDocument.new.algorithm(params['SigAlg'])
239
+ assert_equal signature_algorithm, OpenSSL::Digest::SHA512
240
+ assert cert.public_key.verify(signature_algorithm.new, Base64.decode64(params['Signature']), query_string)
241
+ end
242
242
  end
243
-
244
243
  end
245
-
246
244
  end
@@ -1,27 +1,27 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
2
- require 'rexml/document'
3
- require 'responses/logoutresponse_fixtures'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "responses/logoutresponse_fixtures"))
4
3
 
5
- class LogoutResponseTest < Test::Unit::TestCase
4
+ class LogoutResponseTest < Minitest::Test
6
5
 
7
- context "Logoutresponse" do
8
- context "#new" do
9
- should "raise an exception when response is initialized with nil" do
6
+ describe "Logoutresponse" do
7
+
8
+ describe "#new" do
9
+ it "raise an exception when response is initialized with nil" do
10
10
  assert_raises(ArgumentError) { OneLogin::RubySaml::Logoutresponse.new(nil) }
11
11
  end
12
- should "default to empty settings" do
12
+ it "default to empty settings" do
13
13
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new( valid_response)
14
14
  assert logoutresponse.settings.nil?
15
15
  end
16
- should "accept constructor-injected settings" do
16
+ it "accept constructor-injected settings" do
17
17
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(valid_response, settings)
18
18
  assert !logoutresponse.settings.nil?
19
19
  end
20
- should "accept constructor-injected options" do
20
+ it "accept constructor-injected options" do
21
21
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(valid_response, nil, { :foo => :bar} )
22
22
  assert !logoutresponse.options.empty?
23
23
  end
24
- should "support base64 encoded responses" do
24
+ it "support base64 encoded responses" do
25
25
  expected_response = valid_response
26
26
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(Base64.encode64(expected_response), settings)
27
27
 
@@ -29,8 +29,8 @@ class LogoutResponseTest < Test::Unit::TestCase
29
29
  end
30
30
  end
31
31
 
32
- context "#validate" do
33
- should "validate the response" do
32
+ describe "#validate" do
33
+ it "validate the response" do
34
34
  in_relation_to_request_id = random_id
35
35
 
36
36
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(valid_response({:uuid => in_relation_to_request_id}), settings)
@@ -43,7 +43,7 @@ class LogoutResponseTest < Test::Unit::TestCase
43
43
  assert logoutresponse.success?
44
44
  end
45
45
 
46
- should "invalidate responses with wrong id when given option :matches_uuid" do
46
+ it "invalidate responses with wrong id when given option :matches_uuid" do
47
47
 
48
48
  expected_request_id = "_some_other_expected_uuid"
49
49
  opts = { :matches_request_id => expected_request_id}
@@ -51,10 +51,10 @@ class LogoutResponseTest < Test::Unit::TestCase
51
51
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(valid_response, settings, opts)
52
52
 
53
53
  assert !logoutresponse.validate
54
- assert_not_equal expected_request_id, logoutresponse.in_response_to
54
+ assert expected_request_id != logoutresponse.in_response_to
55
55
  end
56
56
 
57
- should "invalidate responses with wrong request status" do
57
+ it "invalidate responses with wrong request status" do
58
58
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(unsuccessful_response, settings)
59
59
 
60
60
  assert !logoutresponse.validate
@@ -62,8 +62,8 @@ class LogoutResponseTest < Test::Unit::TestCase
62
62
  end
63
63
  end
64
64
 
65
- context "#validate!" do
66
- should "validates good responses" do
65
+ describe "#validate!" do
66
+ it "validates good responses" do
67
67
  in_relation_to_request_id = random_id
68
68
 
69
69
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(valid_response({:uuid => in_relation_to_request_id}), settings)
@@ -71,7 +71,7 @@ class LogoutResponseTest < Test::Unit::TestCase
71
71
  logoutresponse.validate!
72
72
  end
73
73
 
74
- should "raises validation error when matching for wrong request id" do
74
+ it "raises validation error when matching for wrong request id" do
75
75
 
76
76
  expected_request_id = "_some_other_expected_id"
77
77
  opts = { :matches_request_id => expected_request_id}
@@ -81,19 +81,19 @@ class LogoutResponseTest < Test::Unit::TestCase
81
81
  assert_raises(OneLogin::RubySaml::ValidationError) { logoutresponse.validate! }
82
82
  end
83
83
 
84
- should "raise validation error for wrong request status" do
84
+ it "raise validation error for wrong request status" do
85
85
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(unsuccessful_response, settings)
86
86
 
87
87
  assert_raises(OneLogin::RubySaml::ValidationError) { logoutresponse.validate! }
88
88
  end
89
89
 
90
- should "raise validation error when in bad state" do
90
+ it "raise validation error when in bad state" do
91
91
  # no settings
92
92
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(unsuccessful_response)
93
93
  assert_raises(OneLogin::RubySaml::ValidationError) { logoutresponse.validate! }
94
94
  end
95
95
 
96
- should "raise validation error when in lack of sp_entity_id setting" do
96
+ it "raise validation error when in lack of sp_entity_id setting" do
97
97
  bad_settings = settings
98
98
  bad_settings.issuer = nil
99
99
  bad_settings.sp_entity_id = nil
@@ -101,7 +101,7 @@ class LogoutResponseTest < Test::Unit::TestCase
101
101
  assert_raises(OneLogin::RubySaml::ValidationError) { logoutresponse.validate! }
102
102
  end
103
103
 
104
- should "raise error for invalid xml" do
104
+ it "raise error for invalid xml" do
105
105
  logoutresponse = OneLogin::RubySaml::Logoutresponse.new(invalid_xml_response, settings)
106
106
 
107
107
  assert_raises(OneLogin::RubySaml::ValidationError) { logoutresponse.validate! }
@@ -109,10 +109,4 @@ class LogoutResponseTest < Test::Unit::TestCase
109
109
  end
110
110
 
111
111
  end
112
-
113
- # logoutresponse fixtures
114
- def random_id
115
- "_#{UUID.new.generate}"
116
- end
117
-
118
112
  end