From 9f703166a2dac77dcd74b43c2380b3f766938c50 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Wed, 10 May 2006 19:20:35 +0000 Subject: [PATCH] Finished assertion class and test. --- .cdtproject | 2 +- saml/saml1/core/Assertions.h | 2 + saml/saml1/core/impl/AssertionsImpl.cpp | 24 +++- .../saml1/core/impl/AssertionsSchemaValidators.cpp | 2 + .../data/saml1/core/impl/AssertionWithChildren.xml | Bin 922 -> 1052 bytes samltest/data/saml1/core/impl/singleAssertion.xml | Bin 302 -> 426 bytes samltest/internal.h | 1 + samltest/saml1/core/impl/AssertionTest.h | 147 +++++++++++++++++++++ samltest/samltest.vcproj | 26 ++++ 9 files changed, 200 insertions(+), 4 deletions(-) create mode 100644 samltest/saml1/core/impl/AssertionTest.h diff --git a/.cdtproject b/.cdtproject index abae0c2..419cc0d 100644 --- a/.cdtproject +++ b/.cdtproject @@ -58,7 +58,7 @@ - + diff --git a/saml/saml1/core/Assertions.h b/saml/saml1/core/Assertions.h index eb138ae..e9af40d 100644 --- a/saml/saml1/core/Assertions.h +++ b/saml/saml1/core/Assertions.h @@ -226,6 +226,8 @@ namespace opensaml { DECL_TYPED_CHILDREN(Statement); DECL_TYPED_CHILDREN(SubjectStatement); DECL_TYPED_CHILDREN(AuthenticationStatement); + DECL_TYPED_CHILDREN(AttributeStatement); + DECL_TYPED_CHILDREN(AuthorizationDecisionStatement); DECL_TYPED_FOREIGN_CHILD(Signature,xmlsignature); /** AssertionType local name */ static const XMLCh TYPE_NAME[]; diff --git a/saml/saml1/core/impl/AssertionsImpl.cpp b/saml/saml1/core/impl/AssertionsImpl.cpp index faf6978..0cad8db 100644 --- a/saml/saml1/core/impl/AssertionsImpl.cpp +++ b/saml/saml1/core/impl/AssertionsImpl.cpp @@ -372,6 +372,8 @@ namespace opensaml { public AbstractXMLObjectMarshaller, public AbstractXMLObjectUnmarshaller { + protected: + SubjectStatementImpl() {} public: virtual ~SubjectStatementImpl() {} @@ -509,7 +511,7 @@ namespace opensaml { } AuthenticationStatementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) - : SubjectStatementImpl(nsURI, localName, prefix, schemaType) { + : AbstractXMLObject(nsURI, localName, prefix, schemaType) { init(); } @@ -664,7 +666,7 @@ namespace opensaml { } AuthorizationDecisionStatementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) - : SubjectStatementImpl(nsURI, localName, prefix, schemaType) { + : AbstractXMLObject(nsURI, localName, prefix, schemaType) { init(); } @@ -849,7 +851,7 @@ namespace opensaml { virtual ~AttributeStatementImpl() {} AttributeStatementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) - : SubjectStatementImpl(nsURI, localName, prefix, schemaType) { + : AbstractXMLObject(nsURI, localName, prefix, schemaType) { init(); } @@ -976,6 +978,18 @@ namespace opensaml { getAuthenticationStatements().push_back(authst->cloneAuthenticationStatement()); continue; } + + AttributeStatement* attst=dynamic_cast(*i); + if (attst) { + getAttributeStatements().push_back(attst->cloneAttributeStatement()); + continue; + } + + AuthorizationDecisionStatement* authzst=dynamic_cast(*i); + if (authzst) { + getAuthorizationDecisionStatements().push_back(authzst->cloneAuthorizationDecisionStatement()); + continue; + } SubjectStatement* subst=dynamic_cast(*i); if (subst) { @@ -1021,6 +1035,8 @@ namespace opensaml { IMPL_TYPED_CHILDREN(Statement, m_pos_Signature); IMPL_TYPED_CHILDREN(SubjectStatement, m_pos_Signature); IMPL_TYPED_CHILDREN(AuthenticationStatement, m_pos_Signature); + IMPL_TYPED_CHILDREN(AttributeStatement, m_pos_Signature); + IMPL_TYPED_CHILDREN(AuthorizationDecisionStatement, m_pos_Signature); protected: void marshallAttributes(DOMElement* domElement) const { @@ -1042,6 +1058,8 @@ namespace opensaml { PROC_TYPED_CHILD(Advice,SAMLConstants::SAML1_NS,false); PROC_TYPED_CHILD(Signature,XMLConstants::XMLSIG_NS,false); PROC_TYPED_CHILDREN(AuthenticationStatement,SAMLConstants::SAML1_NS,false); + PROC_TYPED_CHILDREN(AttributeStatement,SAMLConstants::SAML1_NS,false); + PROC_TYPED_CHILDREN(AuthorizationDecisionStatement,SAMLConstants::SAML1_NS,false); PROC_TYPED_CHILDREN(SubjectStatement,SAMLConstants::SAML1_NS,true); PROC_TYPED_CHILDREN(Statement,SAMLConstants::SAML1_NS,true); AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root); diff --git a/saml/saml1/core/impl/AssertionsSchemaValidators.cpp b/saml/saml1/core/impl/AssertionsSchemaValidators.cpp index f789011..2980972 100644 --- a/saml/saml1/core/impl/AssertionsSchemaValidators.cpp +++ b/saml/saml1/core/impl/AssertionsSchemaValidators.cpp @@ -108,6 +108,8 @@ namespace opensaml { XMLOBJECTVALIDATOR_REQUIRE(Assertion,Issuer); XMLOBJECTVALIDATOR_REQUIRE(Assertion,IssueInstant); if (ptr->getAuthenticationStatements().empty() && + ptr->getAttributeStatements().empty() && + ptr->getAuthorizationDecisionStatements().empty() && ptr->getSubjectStatements().empty() && ptr->getStatements().empty()) throw ValidationException("Assertion must have at least one statement."); diff --git a/samltest/data/saml1/core/impl/AssertionWithChildren.xml b/samltest/data/saml1/core/impl/AssertionWithChildren.xml index 85ec2b253414d5688d4f8148574084717db46c30..13e3adb680322b29a332b9bd85f023ed340b43dd 100644 GIT binary patch delta 140 zcmbQmK8It2I%B;fLopDhG88eCFk~|1GvqONGPp3^iY9{PKq?IxEE&uh3>b8Q*bqz_F@%8GR&dgYK@TWr0EAIM9STs$yIF;?j0phu CO%=QV delta 12 TcmbQkF^heJI^*V*jKxd<8=M31 diff --git a/samltest/data/saml1/core/impl/singleAssertion.xml b/samltest/data/saml1/core/impl/singleAssertion.xml index 4c6a67f5d4d2aceab9c96c6cc74dc12e3d86f183..26d6715a7fb7707672938d2302a77f64f81b614d 100644 GIT binary patch delta 140 zcmZ3-w2FCyI%B;fLopDhG88eCFk~|1GvqONGPp3buildFromDocument(doc); } catch (XMLToolingException& e) { + TS_TRACE(typeid(e).name()); TS_TRACE(e.what()); throw; } diff --git a/samltest/saml1/core/impl/AssertionTest.h b/samltest/saml1/core/impl/AssertionTest.h new file mode 100644 index 0000000..1f65eec --- /dev/null +++ b/samltest/saml1/core/impl/AssertionTest.h @@ -0,0 +1,147 @@ +/* + * Copyright 2001-2006 Internet2 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "internal.h" +#include + +using namespace opensaml::saml1; + +class AssertionTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase { + int expectedMinorVersion; + XMLCh* expectedIssuer; + XMLCh* expectedIssueInstant; + XMLCh* expectedID; + +public: + void setUp() { + expectedID=XMLString::transcode("ident"); + expectedMinorVersion=1; + expectedIssueInstant=XMLString::transcode("1970-01-02T01:01:02.100Z"); + expectedIssuer=XMLString::transcode("issuer"); + singleElementFile = data_path + "saml1/core/impl/singleAssertion.xml"; + singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAssertionAttributes.xml"; + childElementsFile = data_path + "saml1/core/impl/AssertionWithChildren.xml"; + SAMLObjectBaseTestCase::setUp(); + } + + void tearDown() { + XMLString::release(&expectedID); + XMLString::release(&expectedIssueInstant); + XMLString::release(&expectedIssuer); + SAMLObjectBaseTestCase::tearDown(); + } + + void testSingleElementUnmarshall() { + auto_ptr xo(unmarshallElement(singleElementFile)); + Assertion& assertion = dynamic_cast(*xo.get()); + TSM_ASSERT("Issuer attribute", assertion.getIssuer()==NULL); + TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant)); + TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID)); + + TSM_ASSERT("Conditions element", assertion.getConditions()==NULL); + TSM_ASSERT("Advice element", assertion.getAdvice()==NULL); + + TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size()); + TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size()); + TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size()); + TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size()); + TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size()); + } + + void testSingleElementOptionalAttributesUnmarshall() { + auto_ptr xo(unmarshallElement(singleElementOptionalAttributesFile)); + Assertion& assertion = dynamic_cast(*xo.get()); + + TSM_ASSERT_SAME_DATA("Issuer attribute", expectedIssuer, assertion.getIssuer(), XMLString::stringLen(expectedIssuer)); + TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant)); + TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID)); + TSM_ASSERT_EQUALS("Issuer expectedMinorVersion", expectedMinorVersion, assertion.getMinorVersion()); + + TSM_ASSERT("Conditions element", assertion.getConditions()==NULL); + TSM_ASSERT("Advice element", assertion.getAdvice()==NULL); + + TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size()); + TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size()); + TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size()); + TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size()); + TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size()); + } + + void testChildElementsUnmarshall() { + auto_ptr xo(unmarshallElement(childElementsFile)); + Assertion& assertion = dynamic_cast(*xo.get()); + + TSM_ASSERT("Issuer attribute", assertion.getIssuer()==NULL); + TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant)); + TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID)); + + TSM_ASSERT("Conditions element null", assertion.getConditions()!=NULL); + TSM_ASSERT("Advice element null", assertion.getAdvice()!=NULL); + + TSM_ASSERT_EQUALS("AuthenticationStatements element count", 2, assertion.getAuthenticationStatements().size()); + TSM_ASSERT_EQUALS("AttributeStatements element count", 3, assertion.getAttributeStatements().size()); + TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 3, assertion.getAuthorizationDecisionStatements().size()); + } + + void testSingleElementMarshall() { + Assertion* assertion=AssertionBuilder::buildAssertion(); + assertion->setAssertionID(expectedID); + assertion->setIssueInstant(expectedIssueInstant); + assertEquals(expectedDOM, assertion); + } + + void testSingleElementOptionalAttributesMarshall() { + Assertion* assertion=AssertionBuilder::buildAssertion(); + assertion->setIssueInstant(expectedIssueInstant); + assertion->setAssertionID(expectedID); + assertion->setIssuer(expectedIssuer); + assertEquals(expectedOptionalAttributesDOM, assertion); + } + + void testChildElementsMarshall() { + Assertion* assertion=AssertionBuilder::buildAssertion(); + assertion->setIssueInstant(expectedIssueInstant); + assertion->setAssertionID(expectedID); + assertion->setConditions(ConditionsBuilder::buildConditions()); + assertion->setAdvice(AdviceBuilder::buildAdvice()); + assertion->getAuthenticationStatements().push_back( + AuthenticationStatementBuilder::buildAuthenticationStatement() + ); + assertion->getAuthorizationDecisionStatements().push_back( + AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement() + ); + assertion->getAttributeStatements().push_back( + AttributeStatementBuilder::buildAttributeStatement() + ); + assertion->getAuthenticationStatements().push_back( + AuthenticationStatementBuilder::buildAuthenticationStatement() + ); + assertion->getAuthorizationDecisionStatements().push_back( + AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement() + ); + assertion->getAttributeStatements().push_back( + AttributeStatementBuilder::buildAttributeStatement() + ); + assertion->getAuthorizationDecisionStatements().push_back( + AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement() + ); + assertion->getAttributeStatements().push_back( + AttributeStatementBuilder::buildAttributeStatement() + ); + assertEquals(expectedChildElementsDOM, assertion); + } + +}; diff --git a/samltest/samltest.vcproj b/samltest/samltest.vcproj index 7e39b7f..5c4b19d 100644 --- a/samltest/samltest.vcproj +++ b/samltest/samltest.vcproj @@ -203,6 +203,10 @@ RelativePath=".\saml1\core\impl\AssertionIDReferenceTest.cpp" > + + @@ -313,6 +317,28 @@ /> + + + + + + + + -- 2.1.4