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.
17 #include "signature/SAMLSignatureTestBase.h"
18 #include <saml/saml1/core/Assertions.h>
22 using namespace opensaml::saml1;
24 class SAML1AssertionTest : public CxxTest::TestSuite, public SAMLSignatureTestBase {
27 childElementsFile = data_path + "signature/SAML1Assertion.xml";
28 SAMLSignatureTestBase::setUp();
32 SAMLSignatureTestBase::tearDown();
35 void testSignature() {
36 auto_ptr_XMLCh issuer("issuer");
37 auto_ptr_XMLCh issueInstant("1970-01-02T01:01:02.100Z");
38 auto_ptr_XMLCh id("ident");
39 auto_ptr_XMLCh method("method");
40 auto_ptr_XMLCh nameid("John Doe");
42 NameIdentifier* n=NameIdentifierBuilder::buildNameIdentifier();
43 n->setName(nameid.get());
44 Subject* subject=SubjectBuilder::buildSubject();
45 subject->setNameIdentifier(n);
47 AuthenticationStatement* statement=AuthenticationStatementBuilder::buildAuthenticationStatement();
48 statement->setAuthenticationInstant(issueInstant.get());
49 statement->setAuthenticationMethod(method.get());
50 statement->setSubject(subject);
52 auto_ptr<Assertion> assertion(AssertionBuilder::buildAssertion());
53 assertion->setAssertionID(id.get());
54 assertion->setIssueInstant(issueInstant.get());
55 assertion->setIssuer(issuer.get());
56 assertion->getAuthenticationStatements().push_back(statement);
58 // Append a Signature.
59 Signature* sig=SignatureBuilder::buildSignature();
60 assertion->setSignature(sig);
61 Locker locker(m_resolver);
62 sig->setSigningKey(m_resolver->getKey());
65 KeyInfo* keyInfo=KeyInfoBuilder::buildKeyInfo();
66 X509Data* x509Data=X509DataBuilder::buildX509Data();
67 keyInfo->getX509Datas().push_back(x509Data);
68 for_each(m_resolver->getCertificates().begin(),m_resolver->getCertificates().end(),bind1st(_addcert(),x509Data));
69 sig->setKeyInfo(keyInfo);
71 // Sign while marshalling.
72 vector<Signature*> sigs(1,sig);
73 DOMElement* rootElement = NULL;
75 rootElement=assertion->marshall((DOMDocument*)NULL,&sigs);
77 catch (XMLToolingException& e) {
83 XMLHelper::serialize(rootElement, buf);
84 istringstream in(buf);
85 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
86 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
88 auto_ptr<XMLObject> assertion2(b->buildFromDocument(doc));
89 assertEquals("Unmarshalled assertion does not match", expectedChildElementsDOM, assertion2.get(), false);
92 SignatureProfileValidator spv;
93 SignatureValidator sv(new KeyResolver(m_resolver->getKey()));
94 spv.validate(dynamic_cast<Assertion*>(assertion2.get())->getSignature());
95 sv.validate(dynamic_cast<Assertion*>(assertion2.get())->getSignature());
97 catch (XMLToolingException& e) {