2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
23 #include <saml/saml1/core/Protocols.h>
25 using namespace opensaml::saml1p;
26 using namespace opensaml::saml1;
28 class SAML1POSTTest : public CxxTest::TestSuite, public SAMLBindingBaseTestCase {
31 SAMLBindingBaseTestCase::setUp();
35 SAMLBindingBaseTestCase::tearDown();
38 void testSAML1POST() {
40 xmltooling::QName idprole(samlconstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
41 SecurityPolicy policy(m_metadata.get(), &idprole, m_trust.get(), false);
42 policy.getRules().assign(m_rules.begin(), m_rules.end());
44 // Read message to use from file.
45 string path = data_path + "saml1/binding/SAML1Response.xml";
46 ifstream in(path.c_str());
47 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
48 XercesJanitor<DOMDocument> janitor(doc);
49 auto_ptr<Response> toSend(
50 dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
54 CredentialCriteria cc;
55 cc.setUsage(Credential::SIGNING_CREDENTIAL);
56 Locker clocker(m_creds.get());
57 const Credential* cred = m_creds->resolve(&cc);
58 TSM_ASSERT("Retrieved credential was null", cred!=nullptr);
60 // Freshen timestamp and ID.
61 toSend->setIssueInstant(time(nullptr));
62 toSend->setResponseID(nullptr);
65 auto_ptr_XMLCh lit1("MessageEncoder");
66 auto_ptr_XMLCh lit2("template");
67 path = data_path + "binding/template.html";
68 auto_ptr_XMLCh lit3(path.c_str());
69 DOMDocument* encoder_config = XMLToolingConfig::getConfig().getParser().newDocument();
70 XercesJanitor<DOMDocument> janitor2(encoder_config);
71 encoder_config->appendChild(encoder_config->createElementNS(nullptr,lit1.get()));
72 encoder_config->getDocumentElement()->setAttributeNS(nullptr,lit2.get(),lit3.get());
73 boost::scoped_ptr<MessageEncoder> encoder(
74 SAMLConfig::getConfig().MessageEncoderManager.newPlugin(
75 samlconstants::SAML1_PROFILE_BROWSER_POST, pair<const DOMElement*,const XMLCh*>(encoder_config->getDocumentElement(),nullptr)
79 Locker locker(m_metadata.get());
83 "https://sp.example.org/SAML/SSO",
84 m_metadata->getEntityDescriptor(MetadataProvider::Criteria("https://sp.example.org/")).first,
93 boost::scoped_ptr<MessageDecoder> decoder(
94 SAMLConfig::getConfig().MessageDecoderManager.newPlugin(
95 samlconstants::SAML1_PROFILE_BROWSER_POST, pair<const DOMElement*,const XMLCh*>(nullptr,nullptr)
98 boost::scoped_ptr<Response> response(dynamic_cast<Response*>(decoder->decode(relayState,*this,policy)));
101 TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");
102 TSM_ASSERT("SAML Response not decoded successfully.", response.get());
103 TSM_ASSERT("Message was not verified.", policy.isAuthenticated());
104 auto_ptr_char entityID(policy.getIssuer()->getName());
105 TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
106 TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
110 TSM_ASSERT_THROWS("Did not catch the replay.", decoder->decode(relayState,*this,policy), SecurityPolicyException);
112 catch (XMLToolingException& ex) {