test/response_test.rb in ruby-saml-0.5.3 vs test/response_test.rb in ruby-saml-0.6.0

- old
+ new

@@ -25,10 +25,16 @@ assert !response.name_id.nil? response = Onelogin::Saml::Response.new(response_document_3) assert !response.name_id.nil? end + should "default to raw input when a response is not Base64 encoded" do + decoded = Base64.decode64(response_document_2) + response = Onelogin::Saml::Response.new(decoded) + assert response.document + end + context "Assertion" do should "only retreive an assertion with an ID that matches the signature's reference URI" do response = Onelogin::Saml::Response.new(wrapped_response_2) response.stubs(:conditions).returns(nil) settings = Onelogin::Saml::Settings.new @@ -87,18 +93,38 @@ response.settings = settings assert response.is_valid? assert response.name_id == "test@onelogin.com" end + should "support dynamic namespace resolution on signature elements" do + response = Onelogin::Saml::Response.new(fixture("no_signature_ns.xml")) + response.stubs(:conditions).returns(nil) + settings = Onelogin::Saml::Settings.new + response.settings = settings + settings.idp_cert_fingerprint = "28:74:9B:E8:1F:E8:10:9C:A8:7C:A9:C3:E3:C5:01:6C:92:1C:B4:BA" + XMLSecurity::SignedDocument.any_instance.expects(:validate_doc).returns(true) + assert response.validate! + end + should "validate ADFS assertions" do - response = Onelogin::Saml::Response.new(fixture(:adfs_response)) + response = Onelogin::Saml::Response.new(fixture(:adfs_response_sha256)) response.stubs(:conditions).returns(nil) settings = Onelogin::Saml::Settings.new settings.idp_cert_fingerprint = "28:74:9B:E8:1F:E8:10:9C:A8:7C:A9:C3:E3:C5:01:6C:92:1C:B4:BA" response.settings = settings assert response.validate! end + + should "validate SAML 2.0 XML structure" do + resp_xml = Base64.decode64(response_document_4).gsub(/emailAddress/,'test') + response = Onelogin::Saml::Response.new(Base64.encode64(resp_xml)) + response.stubs(:conditions).returns(nil) + settings = Onelogin::Saml::Settings.new + settings.idp_cert_fingerprint = signature_fingerprint_1 + response.settings = settings + assert_raises(Onelogin::Saml::ValidationError, 'Digest mismatch'){ response.validate! } + end end context "#name_id" do should "extract the value of the name id element" do response = Onelogin::Saml::Response.new(response_document) @@ -169,12 +195,24 @@ assert response.session_expires_at.nil? end end context "#issuer" do - should "return the issuer of the assertion" do + should "return the issuer inside the response assertion" do + response = Onelogin::Saml::Response.new(response_document) + assert_equal "https://app.onelogin.com/saml/metadata/13590", response.issuer + end + + should "return the issuer inside the response" do response = Onelogin::Saml::Response.new(response_document_2) assert_equal "wibble", response.issuer + end + end + + context "#success" do + should "find a status code that says success" do + response = Onelogin::Saml::Response.new(response_document) + response.success? end end end end