2 * Copyright 2001-2010 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.
18 #include <saml/saml1/core/Assertions.h>
20 using namespace opensaml::saml1;
22 class AuthenticationStatementTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
23 XMLCh* expectedAuthenticationMethod;
24 XMLCh* expectedAuthenticationInstant;
28 expectedAuthenticationInstant=XMLString::transcode("1970-01-02T01:01:02.123Z");
29 expectedAuthenticationMethod=XMLString::transcode("trustme");
30 singleElementFile = data_path + "saml1/core/impl/singleAuthenticationStatement.xml";
31 singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAuthenticationStatementAttributes.xml";
32 childElementsFile = data_path + "saml1/core/impl/AuthenticationStatementWithChildren.xml";
33 SAMLObjectBaseTestCase::setUp();
37 XMLString::release(&expectedAuthenticationInstant);
38 XMLString::release(&expectedAuthenticationMethod);
39 SAMLObjectBaseTestCase::tearDown();
42 void testSingleElementUnmarshall() {
43 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
44 AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());
45 TSM_ASSERT("AuthenticationMethod attribute present", as.getAuthenticationMethod()==nullptr);
46 TSM_ASSERT("AuthenticationInstant attribute present", as.getAuthenticationInstant()==nullptr);
48 TSM_ASSERT("Subject element", as.getSubject()==nullptr);
49 TSM_ASSERT("SubjectLocality element", as.getSubjectLocality()==nullptr);
50 TSM_ASSERT_EQUALS("AuthorityBinding element count", 0, as.getAuthorityBindings().size());
53 void testSingleElementOptionalAttributesUnmarshall() {
54 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
55 AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());
57 assertEquals("AuthenticationMethod attribute", expectedAuthenticationMethod, as.getAuthenticationMethod());
58 assertEquals("AuthenticationInstant attribute", expectedAuthenticationInstant, as.getAuthenticationInstant()->getRawData());
61 void testChildElementsUnmarshall() {
62 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
63 AuthenticationStatement& as1 = dynamic_cast<AuthenticationStatement&>(*xo.get());
64 as1.releaseThisAndChildrenDOM();
65 auto_ptr<AuthenticationStatement> as2(as1.cloneAuthenticationStatement());
66 AuthenticationStatement& as=*as2.get();
68 TSM_ASSERT("Subject element", as.getSubject()!=nullptr);
69 TSM_ASSERT("SubjectLocality element", as.getSubjectLocality()!=nullptr);
71 TSM_ASSERT_EQUALS("AuthorityBinding element count", 2, as.getAuthorityBindings().size());
72 as.getAuthorityBindings().erase(as.getAuthorityBindings().begin());
73 TSM_ASSERT_EQUALS("AuthorityBinding element count", 1, as.getAuthorityBindings().size());
76 void testSingleElementMarshall() {
77 assertEquals(expectedDOM, AuthenticationStatementBuilder::buildAuthenticationStatement());
80 void testSingleElementOptionalAttributesMarshall() {
81 AuthenticationStatement* as=AuthenticationStatementBuilder::buildAuthenticationStatement();
82 as->setAuthenticationInstant(expectedAuthenticationInstant);
83 as->setAuthenticationMethod(expectedAuthenticationMethod);
84 assertEquals(expectedOptionalAttributesDOM, as);
87 void testChildElementsMarshall() {
88 AuthenticationStatement* as=AuthenticationStatementBuilder::buildAuthenticationStatement();
89 as->setSubject(SubjectBuilder::buildSubject());
90 as->setSubjectLocality(SubjectLocalityBuilder::buildSubjectLocality());
91 as->getAuthorityBindings().push_back(AuthorityBindingBuilder::buildAuthorityBinding());
92 as->getAuthorityBindings().push_back(AuthorityBindingBuilder::buildAuthorityBinding());
93 assertEquals(expectedChildElementsDOM, as);