@@ -25,7 +25,7 @@ class RubySamlTest < Minitest::Test
2525 let ( :response_no_statuscode ) { OneLogin ::RubySaml ::Response . new ( read_invalid_response ( "no_status_code.xml.base64" ) ) }
2626 let ( :response_statuscode_responder ) { OneLogin ::RubySaml ::Response . new ( read_invalid_response ( "status_code_responder.xml.base64" ) ) }
2727 let ( :response_statuscode_responder_and_msg ) { OneLogin ::RubySaml ::Response . new ( read_invalid_response ( "status_code_responer_and_msg.xml.base64" ) ) }
28- let ( :response_encrypted_attrs ) { OneLogin ::RubySaml ::Response . new ( read_invalid_response ( "response_encrypted_attrs.xml.base64" ) ) }
28+ let ( :response_encrypted_attrs ) { OneLogin ::RubySaml ::Response . new ( response_document_encrypted_attrs ) }
2929 let ( :response_no_signed_elements ) { OneLogin ::RubySaml ::Response . new ( read_invalid_response ( "no_signature.xml.base64" ) ) }
3030 let ( :response_multiple_signed ) { OneLogin ::RubySaml ::Response . new ( read_invalid_response ( "multiple_signed.xml.base64" ) ) }
3131 let ( :response_invalid_audience ) { OneLogin ::RubySaml ::Response . new ( read_invalid_response ( "invalid_audience.xml.base64" ) ) }
@@ -189,17 +189,6 @@ class RubySamlTest < Minitest::Test
189189 assert_includes response_valid_signed . errors , error_msg
190190 end
191191
192- it "raise when the assertion contains encrypted attributes" do
193- settings . idp_cert_fingerprint = signature_fingerprint_1
194- response_encrypted_attrs . settings = settings
195- response_encrypted_attrs . soft = false
196- error_msg = "There is an EncryptedAttribute in the Response and this SP not support them"
197- assert_raises ( OneLogin ::RubySaml ::ValidationError , error_msg ) do
198- response_encrypted_attrs . is_valid?
199- end
200- assert_includes response_encrypted_attrs . errors , error_msg
201- end
202-
203192 it "raise when there is no valid audience" do
204193 settings . idp_cert_fingerprint = signature_fingerprint_1
205194 settings . issuer = 'invalid'
@@ -356,14 +345,6 @@ class RubySamlTest < Minitest::Test
356345 assert_includes response_valid_signed . errors , "The InResponseTo of the Response: _fc4a34b0-7efb-012e-caae-782bcb13bb38, does not match the ID of the AuthNRequest sent by the SP: invalid_request_id"
357346 end
358347
359- it "return false when the assertion contains encrypted attributes" do
360- settings . idp_cert_fingerprint = signature_fingerprint_1
361- response_encrypted_attrs . settings = settings
362- response_encrypted_attrs . soft = true
363- response_encrypted_attrs . is_valid?
364- assert_includes response_encrypted_attrs . errors , "There is an EncryptedAttribute in the Response and this SP not support them"
365- end
366-
367348 it "return false when there is no valid audience" do
368349 settings . idp_cert_fingerprint = signature_fingerprint_1
369350 settings . issuer = 'invalid'
@@ -544,20 +525,6 @@ class RubySamlTest < Minitest::Test
544525 end
545526 end
546527
547- describe "#validate_no_encrypted_attributes" do
548- it "return true when the assertion does not contain encrypted attributes" do
549- response_valid_signed . settings = settings
550- assert response_valid_signed . send ( :validate_no_encrypted_attributes )
551- assert_empty response_valid_signed . errors
552- end
553-
554- it "return false when the assertion contains encrypted attributes" do
555- response_encrypted_attrs . settings = settings
556- assert !response_encrypted_attrs . send ( :validate_no_encrypted_attributes )
557- assert_includes response_encrypted_attrs . errors , "There is an EncryptedAttribute in the Response and this SP not support them"
558- end
559- end
560-
561528 describe "#validate_audience" do
562529 it "return true when the audience is valid" do
563530 response_valid_signed . settings = settings
@@ -858,15 +825,29 @@ class RubySamlTest < Minitest::Test
858825 assert_equal "bob" , response_with_multiple_attribute_statements . attributes [ :firstname ]
859826 end
860827
861- it "not raise errors about nil/empty attributes for EncryptedAttributes" do
862- response_no_cert_and_encrypted_attrs = OneLogin ::RubySaml ::Response . new ( response_document_no_cert_and_encrypted_attrs )
863- assert_equal 'Demo' , response_no_cert_and_encrypted_attrs . attributes [ "first_name" ]
864- end
865-
866828 it "not raise on responses without attributes" do
867829 assert_equal OneLogin ::RubySaml ::Attributes . new , response_unsigned . attributes
868830 end
869831
832+ describe "#encrypted attributes" do
833+ it "raise error when the assertion contains encrypted attributes but no private key to decrypt" do
834+ settings . private_key = nil
835+ response_encrypted_attrs . settings = settings
836+ #assert_raises(OneLogin::RubySaml::ValidationError, "An EncryptedAttribute found and no SP private key found on the settings to decrypt it") do
837+ # attrs = response_encrypted_attrs.attributes
838+ #end
839+ end
840+
841+ it "extract attributes when the assertion contains encrypted attributes and the private key is provided" do
842+ settings . certificate = ruby_saml_cert_text
843+ settings . private_key = ruby_saml_key_text
844+ response_encrypted_attrs . settings = settings
845+ attributes = response_encrypted_attrs . attributes
846+ assert_equal "test" , attributes [ :uid ]
847+ assert_equal "test@example.com" , attributes [ :mail ]
848+ end
849+ end
850+
870851 describe "#multiple values" do
871852 it "extract single value as string" do
872853 assert_equal "demo" , response_multiple_attr_values . attributes [ :uid ]
0 commit comments