2 * Copyright 2001-2005 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #include "binding.h"
\r
19 #include <saml/saml1/core/Protocols.h>
\r
21 using namespace opensaml::saml1p;
\r
22 using namespace opensaml::saml1;
\r
24 class SAML1POSTTest : public CxxTest::TestSuite, public SAMLBindingBaseTestCase {
\r
28 SAMLBindingBaseTestCase::setUp();
\r
33 SAMLBindingBaseTestCase::tearDown();
\r
36 void testSAML1POSTTrusted() {
\r
38 // Read message to use from file.
\r
39 string path = data_path + "saml1/binding/SAML1Response.xml";
\r
40 ifstream in(path.c_str());
\r
41 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
42 XercesJanitor<DOMDocument> janitor(doc);
\r
43 auto_ptr<Response> toSend(
\r
44 dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
\r
48 // Freshen timestamp.
\r
49 toSend->setIssueInstant(time(NULL));
\r
52 auto_ptr<MessageEncoder> encoder(SAMLConfig::getConfig().MessageEncoderManager.newPlugin(SAML1_POST_ENCODER, NULL));
\r
53 encoder->encode(m_fields,toSend.get(),"https://sp.example.org/","state",m_creds);
\r
58 const RoleDescriptor* issuer=NULL;
\r
60 QName idprole(SAMLConstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
\r
61 auto_ptr<MessageDecoder> decoder(SAMLConfig::getConfig().MessageDecoderManager.newPlugin(SAML1_POST_DECODER, NULL));
\r
62 auto_ptr<Response> response(
\r
63 dynamic_cast<Response*>(
\r
64 decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust)
\r
68 // Test the results.
\r
69 TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");
\r
70 TSM_ASSERT("SAML Response not decoded successfully.", response.get());
\r
71 TSM_ASSERT("Message was not verified.", issuer && trusted);
\r
72 auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());
\r
73 TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
\r
74 TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
\r
76 catch (XMLToolingException& ex) {
\r
77 TS_TRACE(ex.what());
\r
82 void testSAML1POSTUntrusted() {
\r
84 // Read message to use from file.
\r
85 string path = data_path + "saml1/binding/SAML1Response.xml";
\r
86 ifstream in(path.c_str());
\r
87 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
88 XercesJanitor<DOMDocument> janitor(doc);
\r
89 auto_ptr<Response> toSend(
\r
90 dynamic_cast<Response*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
\r
94 // Freshen timestamp and clear ID.
\r
95 toSend->setIssueInstant(time(NULL));
\r
96 toSend->setResponseID(NULL);
\r
99 auto_ptr<MessageEncoder> encoder(SAMLConfig::getConfig().MessageEncoderManager.newPlugin(SAML1_POST_ENCODER, NULL));
\r
100 encoder->encode(m_fields,toSend.get(),"https://sp.example.org/","state");
\r
105 const RoleDescriptor* issuer=NULL;
\r
106 bool trusted=false;
\r
107 QName idprole(SAMLConstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
\r
108 auto_ptr<MessageDecoder> decoder(SAMLConfig::getConfig().MessageDecoderManager.newPlugin(SAML1_POST_DECODER, NULL));
\r
109 auto_ptr<Response> response(
\r
110 dynamic_cast<Response*>(
\r
111 decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole)
\r
115 // Test the results.
\r
116 TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");
\r
117 TSM_ASSERT("SAML Response not decoded successfully.", response.get());
\r
118 TSM_ASSERT("Message was verified.", issuer && !trusted);
\r
119 auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());
\r
120 TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
\r
121 TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
\r
123 // Trigger a replay.
\r
124 TSM_ASSERT_THROWS("Did not catch the replay.",
\r
125 decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust),
\r
128 catch (XMLToolingException& ex) {
\r
129 TS_TRACE(ex.what());
\r
134 const char* getMethod() const {
\r
138 const char* getRequestURL() const {
\r
139 return "https://sp.example.org/SAML/POST";
\r
142 const char* getQueryString() const {
\r