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 "signature/SAMLSignatureTestBase.h"
\r
19 #include <saml/saml1/core/Protocols.h>
\r
23 using namespace opensaml::saml1p;
\r
24 using namespace opensaml::saml1;
\r
26 class SAML1ResponseTest : public CxxTest::TestSuite, public SAMLSignatureTestBase {
\r
29 childElementsFile = data_path + "signature/SAML1Response.xml";
\r
30 SAMLSignatureTestBase::setUp();
\r
34 SAMLSignatureTestBase::tearDown();
\r
37 void testSignature() {
\r
38 auto_ptr_XMLCh issuer("issuer");
\r
39 auto_ptr_XMLCh issueInstant("1970-01-02T01:01:02.100Z");
\r
40 auto_ptr_XMLCh aid("aident");
\r
41 auto_ptr_XMLCh rid("rident");
\r
42 auto_ptr_XMLCh method("method");
\r
43 auto_ptr_XMLCh nameid("John Doe");
\r
45 NameIdentifier* n=NameIdentifierBuilder::buildNameIdentifier();
\r
46 n->setName(nameid.get());
\r
47 Subject* subject=SubjectBuilder::buildSubject();
\r
48 subject->setNameIdentifier(n);
\r
50 AuthenticationStatement* statement=AuthenticationStatementBuilder::buildAuthenticationStatement();
\r
51 statement->setAuthenticationInstant(issueInstant.get());
\r
52 statement->setAuthenticationMethod(method.get());
\r
53 statement->setSubject(subject);
\r
55 Assertion* assertion=AssertionBuilder::buildAssertion();
\r
56 assertion->setAssertionID(aid.get());
\r
57 assertion->setIssueInstant(issueInstant.get());
\r
58 assertion->setIssuer(issuer.get());
\r
59 assertion->getAuthenticationStatements().push_back(statement);
\r
61 // Append a Signature.
\r
62 assertion->setSignature(SignatureBuilder::buildSignature());
\r
63 assertion->getSignature()->setSigningKey(m_key->clone());
\r
66 KeyInfo* keyInfo=KeyInfoBuilder::buildKeyInfo();
\r
67 X509Data* x509Data=X509DataBuilder::buildX509Data();
\r
68 keyInfo->getX509Datas().push_back(x509Data);
\r
69 for_each(m_certs.begin(),m_certs.end(),bind1st(_addcert(),x509Data));
\r
70 assertion->getSignature()->setKeyInfo(keyInfo);
\r
72 // Sign assertion while marshalling.
\r
73 vector<Signature*> sigs(1,assertion->getSignature());
\r
74 DOMElement* rootElement = NULL;
\r
76 rootElement=assertion->marshall((DOMDocument*)NULL,&sigs);
\r
78 catch (XMLToolingException& e) {
\r
84 StatusCode* sc=StatusCodeBuilder::buildStatusCode();
\r
85 sc->setValue(&StatusCode::SUCCESS);
\r
86 Status* status=StatusBuilder::buildStatus();
\r
87 status->setStatusCode(sc);
\r
89 auto_ptr<Response> response(ResponseBuilder::buildResponse());
\r
90 response->setResponseID(rid.get());
\r
91 response->setIssueInstant(issueInstant.get());
\r
92 response->setStatus(status);
\r
93 response->getAssertions().push_back(assertion);
\r
94 response->setSignature(SignatureBuilder::buildSignature());
\r
95 response->getSignature()->setSigningKey(m_key->clone());
\r
96 response->getSignature()->setKeyInfo(keyInfo->cloneKeyInfo());
\r
98 // Sign response while marshalling.
\r
100 sigs.push_back(response->getSignature());
\r
101 rootElement = NULL;
\r
103 rootElement=response->marshall((DOMDocument*)NULL,&sigs);
\r
105 catch (XMLToolingException& e) {
\r
106 TS_TRACE(e.what());
\r
111 XMLHelper::serialize(rootElement, buf);
\r
112 istringstream in(buf);
\r
113 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
114 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
116 assertEquals(expectedChildElementsDOM, b->buildFromDocument(doc));
\r
119 SignatureProfileValidator spv;
\r
120 spv.validate(assertion->getSignature());
\r
121 spv.validate(response->getSignature());
\r
123 SignatureValidator sv(new KeyResolver(m_key->clone()));
\r
124 sv.validate(assertion->getSignature());
\r
125 sv.validate(response->getSignature());
\r
127 catch (XMLToolingException& e) {
\r
128 TS_TRACE(e.what());
\r