2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 #include <saml/saml1/core/Assertions.h>
24 using namespace opensaml::saml1;
26 class AuthenticationStatementTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
27 XMLCh* expectedAuthenticationMethod;
28 XMLCh* expectedAuthenticationInstant;
32 expectedAuthenticationInstant=XMLString::transcode("1970-01-02T01:01:02.123Z");
33 expectedAuthenticationMethod=XMLString::transcode("trustme");
34 singleElementFile = data_path + "saml1/core/impl/singleAuthenticationStatement.xml";
35 singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAuthenticationStatementAttributes.xml";
36 childElementsFile = data_path + "saml1/core/impl/AuthenticationStatementWithChildren.xml";
37 SAMLObjectBaseTestCase::setUp();
41 XMLString::release(&expectedAuthenticationInstant);
42 XMLString::release(&expectedAuthenticationMethod);
43 SAMLObjectBaseTestCase::tearDown();
46 void testSingleElementUnmarshall() {
47 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
48 AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());
49 TSM_ASSERT("AuthenticationMethod attribute present", as.getAuthenticationMethod()==nullptr);
50 TSM_ASSERT("AuthenticationInstant attribute present", as.getAuthenticationInstant()==nullptr);
52 TSM_ASSERT("Subject element", as.getSubject()==nullptr);
53 TSM_ASSERT("SubjectLocality element", as.getSubjectLocality()==nullptr);
54 TSM_ASSERT_EQUALS("AuthorityBinding element count", 0, as.getAuthorityBindings().size());
57 void testSingleElementOptionalAttributesUnmarshall() {
58 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
59 AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());
61 assertEquals("AuthenticationMethod attribute", expectedAuthenticationMethod, as.getAuthenticationMethod());
62 assertEquals("AuthenticationInstant attribute", expectedAuthenticationInstant, as.getAuthenticationInstant()->getRawData());
65 void testChildElementsUnmarshall() {
66 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
67 AuthenticationStatement& as1 = dynamic_cast<AuthenticationStatement&>(*xo.get());
68 as1.releaseThisAndChildrenDOM();
69 auto_ptr<AuthenticationStatement> as2(as1.cloneAuthenticationStatement());
70 AuthenticationStatement& as=*as2.get();
72 TSM_ASSERT("Subject element", as.getSubject()!=nullptr);
73 TSM_ASSERT("SubjectLocality element", as.getSubjectLocality()!=nullptr);
75 TSM_ASSERT_EQUALS("AuthorityBinding element count", 2, as.getAuthorityBindings().size());
76 as.getAuthorityBindings().erase(as.getAuthorityBindings().begin());
77 TSM_ASSERT_EQUALS("AuthorityBinding element count", 1, as.getAuthorityBindings().size());
80 void testSingleElementMarshall() {
81 assertEquals(expectedDOM, AuthenticationStatementBuilder::buildAuthenticationStatement());
84 void testSingleElementOptionalAttributesMarshall() {
85 AuthenticationStatement* as=AuthenticationStatementBuilder::buildAuthenticationStatement();
86 as->setAuthenticationInstant(expectedAuthenticationInstant);
87 as->setAuthenticationMethod(expectedAuthenticationMethod);
88 assertEquals(expectedOptionalAttributesDOM, as);
91 void testChildElementsMarshall() {
92 AuthenticationStatement* as=AuthenticationStatementBuilder::buildAuthenticationStatement();
93 as->setSubject(SubjectBuilder::buildSubject());
94 as->setSubjectLocality(SubjectLocalityBuilder::buildSubjectLocality());
95 as->getAuthorityBindings().push_back(AuthorityBindingBuilder::buildAuthorityBinding());
96 as->getAuthorityBindings().push_back(AuthorityBindingBuilder::buildAuthorityBinding());
97 assertEquals(expectedChildElementsDOM, as);