2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <saml/saml2/core/Protocols.h>
21 using namespace opensaml::saml2p;
22 using namespace opensaml::saml2;
24 class SAML2RedirectTest : public CxxTest::TestSuite, public SAMLBindingBaseTestCase {
27 SAMLBindingBaseTestCase::setUp();
31 SAMLBindingBaseTestCase::tearDown();
34 void testSAML2Redirect() {
36 QName idprole(samlconstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
37 SecurityPolicy policy(m_rules2, m_metadata, &idprole, m_trust, false);
39 // Read message to use from file.
40 string path = data_path + "saml2/binding/SAML2Response.xml";
41 ifstream in(path.c_str());
42 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
43 XercesJanitor<DOMDocument> janitor(doc);
44 auto_ptr<Response> toSend(
45 dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
49 CredentialCriteria cc;
\r
50 cc.setUsage(CredentialCriteria::SIGNING_CREDENTIAL);
\r
51 Locker clocker(m_creds);
\r
52 const Credential* cred = m_creds->resolve(&cc);
\r
53 TSM_ASSERT("Retrieved credential was null", cred!=NULL);
\r
55 // Freshen timestamp and ID.
56 toSend->setIssueInstant(time(NULL));
60 auto_ptr<MessageEncoder> encoder(
61 SAMLConfig::getConfig().MessageEncoderManager.newPlugin(samlconstants::SAML20_BINDING_HTTP_REDIRECT, NULL)
63 encoder->encode(*this,toSend.get(),"https://sp.example.org/SAML/SSO","https://sp.example.org/","state",cred);
68 auto_ptr<MessageDecoder> decoder(
69 SAMLConfig::getConfig().MessageDecoderManager.newPlugin(samlconstants::SAML20_BINDING_HTTP_REDIRECT, NULL)
71 Locker locker(m_metadata);
72 auto_ptr<Response> response(dynamic_cast<Response*>(decoder->decode(relayState,*this,policy)));
75 TSM_ASSERT_EQUALS("RelayState was not the expected result.", relayState, "state");
76 TSM_ASSERT("SAML Response not decoded successfully.", response.get());
77 TSM_ASSERT("Message was not verified.", policy.isSecure());
78 auto_ptr_char entityID(policy.getIssuer()->getName());
79 TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
80 TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
84 TSM_ASSERT_THROWS("Did not catch the replay.", decoder->decode(relayState,*this,policy), SecurityPolicyException);
86 catch (XMLToolingException& ex) {