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 SAML1RequestTest : public CxxTest::TestSuite, public SAMLSignatureTestBase {
\r
29 childElementsFile = data_path + "signature/SAML1Request.xml";
\r
30 SAMLSignatureTestBase::setUp();
\r
34 SAMLSignatureTestBase::tearDown();
\r
37 void testSignature() {
\r
38 auto_ptr_XMLCh issueInstant("1970-01-02T01:01:02.100Z");
\r
39 auto_ptr_XMLCh id("ident");
\r
40 auto_ptr_XMLCh method("method");
\r
41 auto_ptr_XMLCh nameid("John Doe");
\r
43 NameIdentifier* n=NameIdentifierBuilder::buildNameIdentifier();
\r
44 n->setName(nameid.get());
\r
45 Subject* subject=SubjectBuilder::buildSubject();
\r
46 subject->setNameIdentifier(n);
\r
48 AuthenticationQuery* query=AuthenticationQueryBuilder::buildAuthenticationQuery();
\r
49 query->setAuthenticationMethod(method.get());
\r
50 query->setSubject(subject);
\r
52 auto_ptr<Request> request(RequestBuilder::buildRequest());
\r
53 request->setRequestID(id.get());
\r
54 request->setIssueInstant(issueInstant.get());
\r
55 request->setAuthenticationQuery(query);
\r
57 // Append a Signature.
\r
58 Signature* sig=SignatureBuilder::buildSignature();
\r
59 request->setSignature(sig);
\r
60 Locker locker(m_resolver);
\r
61 sig->setSigningKey(m_resolver->getKey());
\r
64 KeyInfo* keyInfo=KeyInfoBuilder::buildKeyInfo();
\r
65 X509Data* x509Data=X509DataBuilder::buildX509Data();
\r
66 keyInfo->getX509Datas().push_back(x509Data);
\r
67 for_each(m_resolver->getCertificates().begin(),m_resolver->getCertificates().end(),bind1st(_addcert(),x509Data));
\r
68 sig->setKeyInfo(keyInfo);
\r
70 // Sign while marshalling.
\r
71 vector<Signature*> sigs(1,sig);
\r
72 DOMElement* rootElement = NULL;
\r
74 rootElement=request->marshall((DOMDocument*)NULL,&sigs);
\r
76 catch (XMLToolingException& e) {
\r
82 XMLHelper::serialize(rootElement, buf);
\r
83 istringstream in(buf);
\r
84 DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
\r
85 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
87 assertEquals(expectedChildElementsDOM, b->buildFromDocument(doc));
\r
90 SignatureProfileValidator spv;
\r
91 SignatureValidator sv(new KeyResolver(m_resolver->getKey()));
\r
92 spv.validate(request->getSignature());
\r
93 sv.validate(request->getSignature());
\r
95 catch (XMLToolingException& e) {
\r