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/binding/ArtifactMap.h>
20 #include <saml/saml1/core/Assertions.h>
21 #include <saml/saml1/core/Protocols.h>
22 #include <saml/saml1/binding/SAMLArtifactType0001.h>
23 #include <xmltooling/validation/ValidatorSuite.h>
25 using namespace opensaml::saml1p;
26 using namespace opensaml::saml1;
28 class SAML1ArtifactTest : public CxxTest::TestSuite,
29 public SAMLBindingBaseTestCase, public MessageEncoder::ArtifactGenerator, public MessageDecoder::ArtifactResolver {
32 SAMLBindingBaseTestCase::setUp();
36 SAMLBindingBaseTestCase::tearDown();
39 void testSAML1Artifact() {
41 // Read message to use from file.
42 string path = data_path + "saml1/binding/SAML1Assertion.xml";
43 ifstream in(path.c_str());
44 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
45 XercesJanitor<DOMDocument> janitor(doc);
46 auto_ptr<Assertion> toSend(
47 dynamic_cast<Assertion*>(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(),true))
52 auto_ptr<MessageEncoder> encoder(
53 SAMLConfig::getConfig().MessageEncoderManager.newPlugin(SAMLConstants::SAML1_PROFILE_BROWSER_ARTIFACT, NULL)
55 encoder->setArtifactGenerator(this);
56 encoder->encode(*this,toSend.get(),"https://sp.example.org/SAML/Artifact","https://sp.example.org/","state",m_creds);
61 const RoleDescriptor* issuer=NULL;
63 QName idprole(SAMLConstants::SAML20MD_NS, IDPSSODescriptor::LOCAL_NAME);
64 auto_ptr<MessageDecoder> decoder(
65 SAMLConfig::getConfig().MessageDecoderManager.newPlugin(SAMLConstants::SAML1_PROFILE_BROWSER_ARTIFACT, NULL)
67 decoder->setArtifactResolver(this);
68 Locker locker(m_metadata);
69 auto_ptr<Response> response(
70 dynamic_cast<Response*>(
71 decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust)
76 TSM_ASSERT_EQUALS("TARGET was not the expected result.", relayState, "state");
77 TSM_ASSERT("SAML Response not decoded successfully.", response.get());
78 TSM_ASSERT("Message was not verified.", issuer && trusted);
79 auto_ptr_char entityID(dynamic_cast<const EntityDescriptor*>(issuer->getParent())->getEntityID());
80 TSM_ASSERT("Issuer was not expected.", !strcmp(entityID.get(),"https://idp.example.org/"));
81 TSM_ASSERT_EQUALS("Assertion count was not correct.", response->getAssertions().size(), 1);
84 TSM_ASSERT_THROWS("Did not catch the replay.",
85 decoder->decode(relayState,issuer,trusted,*this,m_metadata,&idprole,m_trust),
88 catch (XMLToolingException& ex) {
94 SAMLArtifact* generateSAML1Artifact(const char* relyingParty) const {
95 return new SAMLArtifactType0001(SAMLConfig::getConfig().hashSHA1("https://idp.example.org/"));
98 saml2p::SAML2Artifact* generateSAML2Artifact(const char* relyingParty) const {
99 throw BindingException("Not implemented.");
104 const vector<SAMLArtifact*>& artifacts,
105 const IDPSSODescriptor& idpDescriptor,
106 const X509TrustEngine* trustEngine=NULL
108 TSM_ASSERT_EQUALS("Too many artifacts.", artifacts.size(), 1);
109 XMLObject* xmlObject =
110 SAMLConfig::getConfig().getArtifactMap()->retrieveContent(artifacts.front(), "https://sp.example.org/");
111 Assertion* assertion = dynamic_cast<Assertion*>(xmlObject);
112 TSM_ASSERT("Not an assertion.", assertion!=NULL);
113 auto_ptr<Response> response(ResponseBuilder::buildResponse());
114 response->getAssertions().push_back(assertion);
115 Status* status = StatusBuilder::buildStatus();
116 response->setStatus(status);
117 StatusCode* sc = StatusCodeBuilder::buildStatusCode();
118 status->setStatusCode(sc);
119 sc->setValue(&StatusCode::SUCCESS);
120 response->marshall();
121 SchemaValidators.validate(response.get());
122 authenticated = true;
123 return response.release();
126 saml2p::ArtifactResponse* resolve(
128 const saml2p::SAML2Artifact& artifact,
129 const SSODescriptorType& ssoDescriptor,
130 const X509TrustEngine* trustEngine=NULL
132 throw BindingException("Not implemented.");