2 * Copyright 2001-2005 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/saml1/core/Protocols.h>
21 using namespace opensaml::saml1p;
22 using namespace opensaml::saml1;
24 class SAML1POSTTest : public CxxTest::TestSuite, public SAMLBindingBaseTestCase {
28 SAMLBindingBaseTestCase::setUp();
33 SAMLBindingBaseTestCase::tearDown();
36 void testSAML1POSTTrusted() {
38 // Read message to use from file.
39 string path = data_path + "saml1/binding/SAML1Response.xml";
40 ifstream in(path.c_str());
41 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
42 XercesJanitor<DOMDocument> janitor(doc);
43 auto_ptr<Response> toSend(
44 dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
49 toSend->setIssueInstant(time(NULL));
52 auto_ptr<MessageEncoder> encoder(SAMLConfig::getConfig().MessageEncoderManager.newPlugin(SAML1_POST_ENCODER, NULL));
53 encoder->encode(m_fields,toSend.get(),"https://sp.example.org/","state",m_creds);
58 const RoleDescriptor* issuer=NULL;
60 QName idprole(SAMLConstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
61 auto_ptr<MessageDecoder> decoder(SAMLConfig::getConfig().MessageDecoderManager.newPlugin(SAML1_POST_DECODER, NULL));
62 Locker locker(m_metadata);
63 auto_ptr<Response> response(
64 dynamic_cast<Response*>(
65 decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust)
70 TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");
71 TSM_ASSERT("SAML Response not decoded successfully.", response.get());
72 TSM_ASSERT("Message was not verified.", issuer && trusted);
73 auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());
74 TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
75 TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
77 catch (XMLToolingException& ex) {
83 void testSAML1POSTUntrusted() {
85 // Read message to use from file.
86 string path = data_path + "saml1/binding/SAML1Response.xml";
87 ifstream in(path.c_str());
88 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
89 XercesJanitor<DOMDocument> janitor(doc);
90 auto_ptr<Response> toSend(
91 dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
95 // Freshen timestamp and clear ID.
96 toSend->setIssueInstant(time(NULL));
97 toSend->setResponseID(NULL);
100 auto_ptr<MessageEncoder> encoder(SAMLConfig::getConfig().MessageEncoderManager.newPlugin(SAML1_POST_ENCODER, NULL));
101 encoder->encode(m_fields,toSend.get(),"https://sp.example.org/","state");
106 const RoleDescriptor* issuer=NULL;
108 QName idprole(SAMLConstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
109 auto_ptr<MessageDecoder> decoder(SAMLConfig::getConfig().MessageDecoderManager.newPlugin(SAML1_POST_DECODER, NULL));
110 Locker locker(m_metadata);
111 auto_ptr<Response> response(
112 dynamic_cast<Response*>(
113 decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole)
118 TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");
119 TSM_ASSERT("SAML Response not decoded successfully.", response.get());
120 TSM_ASSERT("Message was verified.", issuer && !trusted);
121 auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());
122 TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
123 TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
126 TSM_ASSERT_THROWS("Did not catch the replay.",
127 decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust),
130 catch (XMLToolingException& ex) {
136 const char* getMethod() const {
140 const char* getRequestURL() const {
141 return "https://sp.example.org/SAML/POST";
144 const char* getQueryString() const {