X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=samltest%2Fsaml2%2Fbinding%2FSAML2POSTTest.h;h=f03fbcec663915480c7f25d97d82c682bd2c6913;hb=5cd3da8d9bd792f4a24372ab8e6d24b8409df41a;hp=4737679fb3019296d893edc31d69ef7b82c6dc1e;hpb=6b5c75d27994ca1f9d450a81576a1bde4873edf3;p=shibboleth%2Fcpp-opensaml.git diff --git a/samltest/saml2/binding/SAML2POSTTest.h b/samltest/saml2/binding/SAML2POSTTest.h index 4737679..f03fbce 100644 --- a/samltest/saml2/binding/SAML2POSTTest.h +++ b/samltest/saml2/binding/SAML2POSTTest.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005 Internet2 + * Copyright 2001-2007 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,8 @@ public: void testSAML2POST() { try { QName idprole(samlconstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME); - SecurityPolicy policy(m_rules2, m_metadata, &idprole, m_trust); + SecurityPolicy policy(m_metadata, &idprole, m_trust, false); + policy.getRules().assign(m_rules.begin(), m_rules.end()); // Read message to use from file. string path = data_path + "saml2/binding/SAML2Response.xml"; @@ -46,6 +47,12 @@ public: ); janitor.release(); + CredentialCriteria cc; + cc.setUsage(Credential::SIGNING_CREDENTIAL); + Locker clocker(m_creds); + const Credential* cred = m_creds->resolve(&cc); + TSM_ASSERT("Retrieved credential was null", cred!=NULL); + // Freshen timestamp and ID. toSend->setIssueInstant(time(NULL)); toSend->setID(NULL); @@ -61,31 +68,41 @@ public: encoder_config->getDocumentElement()->setAttributeNS(NULL,lit2.get(),lit3.get()); auto_ptr encoder( SAMLConfig::getConfig().MessageEncoderManager.newPlugin( - samlconstants::SAML20_BINDING_HTTP_POST, encoder_config->getDocumentElement() + samlconstants::SAML20_BINDING_HTTP_POST, pair(encoder_config->getDocumentElement(), NULL) ) ); - encoder->encode(*this,toSend.get(),"https://sp.example.org/SAML/SSO","https://sp.example.org/","state",m_creds); + Locker locker(m_metadata); + encoder->encode( + *this, + toSend.get(), + "https://sp.example.org/SAML/SSO", + m_metadata->getEntityDescriptor(MetadataProvider::Criteria("https://sp.example.org/")).first, + "state", + NULL, + cred + ); toSend.release(); // Decode message. string relayState; auto_ptr decoder( - SAMLConfig::getConfig().MessageDecoderManager.newPlugin(samlconstants::SAML20_BINDING_HTTP_POST, NULL) + SAMLConfig::getConfig().MessageDecoderManager.newPlugin( + samlconstants::SAML20_BINDING_HTTP_POST, pair(NULL,NULL) + ) ); - Locker locker(m_metadata); auto_ptr response(dynamic_cast(decoder->decode(relayState,*this,policy))); // Test the results. TSM_ASSERT_EQUALS("RelayState was not the expected result.", relayState, "state"); TSM_ASSERT("SAML Response not decoded successfully.", response.get()); - TSM_ASSERT("Message was not verified.", policy.isSecure()); + TSM_ASSERT("Message was not verified.", policy.isAuthenticated()); auto_ptr_char entityID(policy.getIssuer()->getName()); TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/")); TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1); // Trigger a replay. policy.reset(); - TSM_ASSERT_THROWS("Did not catch the replay.", decoder->decode(relayState,*this,policy), BindingException); + TSM_ASSERT_THROWS("Did not catch the replay.", decoder->decode(relayState,*this,policy), SecurityPolicyException); } catch (XMLToolingException& ex) { TS_TRACE(ex.what()); @@ -96,7 +113,8 @@ public: void testSAML2POSTSimpleSign() { try { QName idprole(samlconstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME); - SecurityPolicy policy(m_rules2, m_metadata, &idprole, m_trust); + SecurityPolicy policy(m_metadata, &idprole, m_trust, false); + policy.getRules().assign(m_rules.begin(), m_rules.end()); // Read message to use from file. string path = data_path + "saml2/binding/SAML2Response.xml"; @@ -108,6 +126,12 @@ public: ); janitor.release(); + CredentialCriteria cc; + cc.setUsage(Credential::SIGNING_CREDENTIAL); + Locker clocker(m_creds); + const Credential* cred = m_creds->resolve(&cc); + TSM_ASSERT("Retrieved credential was null", cred!=NULL); + // Freshen timestamp and ID. toSend->setIssueInstant(time(NULL)); toSend->setID(NULL); @@ -123,31 +147,41 @@ public: encoder_config->getDocumentElement()->setAttributeNS(NULL,lit2.get(),lit3.get()); auto_ptr encoder( SAMLConfig::getConfig().MessageEncoderManager.newPlugin( - samlconstants::SAML20_BINDING_HTTP_POST_SIMPLESIGN, encoder_config->getDocumentElement() + samlconstants::SAML20_BINDING_HTTP_POST_SIMPLESIGN, pair(encoder_config->getDocumentElement(),NULL) ) ); - encoder->encode(*this,toSend.get(),"https://sp.example.org/SAML/SSO","https://sp.example.org/","state",m_creds); + Locker locker(m_metadata); + encoder->encode( + *this, + toSend.get(), + "https://sp.example.org/SAML/SSO", + m_metadata->getEntityDescriptor(MetadataProvider::Criteria("https://sp.example.org/")).first, + "state", + NULL, + cred + ); toSend.release(); // Decode message. string relayState; auto_ptr decoder( - SAMLConfig::getConfig().MessageDecoderManager.newPlugin(samlconstants::SAML20_BINDING_HTTP_POST_SIMPLESIGN, NULL) + SAMLConfig::getConfig().MessageDecoderManager.newPlugin( + samlconstants::SAML20_BINDING_HTTP_POST_SIMPLESIGN, pair(NULL,NULL) + ) ); - Locker locker(m_metadata); auto_ptr response(dynamic_cast(decoder->decode(relayState,*this,policy))); // Test the results. TSM_ASSERT_EQUALS("RelayState was not the expected result.", relayState, "state"); TSM_ASSERT("SAML Response not decoded successfully.", response.get()); - TSM_ASSERT("Message was not verified.", policy.isSecure()); + TSM_ASSERT("Message was not verified.", policy.isAuthenticated()); auto_ptr_char entityID(policy.getIssuer()->getName()); TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/")); TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1); // Trigger a replay. policy.reset(); - TSM_ASSERT_THROWS("Did not catch the replay.", decoder->decode(relayState,*this,policy), BindingException); + TSM_ASSERT_THROWS("Did not catch the replay.", decoder->decode(relayState,*this,policy), SecurityPolicyException); } catch (XMLToolingException& ex) { TS_TRACE(ex.what());