Finished assertion class and test.
authorScott Cantor <cantor.2@osu.edu>
Wed, 10 May 2006 19:20:35 +0000 (19:20 +0000)
committerScott Cantor <cantor.2@osu.edu>
Wed, 10 May 2006 19:20:35 +0000 (19:20 +0000)
.cdtproject
saml/saml1/core/Assertions.h
saml/saml1/core/impl/AssertionsImpl.cpp
saml/saml1/core/impl/AssertionsSchemaValidators.cpp
samltest/data/saml1/core/impl/AssertionWithChildren.xml
samltest/data/saml1/core/impl/singleAssertion.xml
samltest/internal.h
samltest/saml1/core/impl/AssertionTest.h [new file with mode: 0644]
samltest/samltest.vcproj

index abae0c2..419cc0d 100644 (file)
@@ -58,7 +58,7 @@
 <pathentry include="C:/xml-security-c-1.2.0/include" kind="inc" path="" system="true"/>\r
 <pathentry include="C:/log4cpp-0.3.5rc1/include" kind="inc" path="" system="true"/>\r
 <pathentry include="C:/cxxtest" kind="inc" path="" system="true"/>\r
-<pathentry excluding="util/|saml1/core/|saml2/core/|saml2/metadata/|saml1/core/impl/" kind="src" path="saml"/>\r
+<pathentry excluding="util/|saml1/|saml1/core/|saml2/|saml2/core/|saml2/metadata/|saml1/core/impl/" kind="src" path="saml"/>\r
 <pathentry kind="out" path=""/>\r
 <pathentry kind="con" path="org.eclipse.cdt.make.core.DISCOVERED_SCANNER_INFO"/>\r
 <pathentry kind="src" path="saml/util"/>\r
index eb138ae..e9af40d 100644 (file)
@@ -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[];
index faf6978..0cad8db 100644 (file)
@@ -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<AttributeStatement*>(*i);
+                        if (attst) {
+                            getAttributeStatements().push_back(attst->cloneAttributeStatement());
+                            continue;
+                        }
+
+                        AuthorizationDecisionStatement* authzst=dynamic_cast<AuthorizationDecisionStatement*>(*i);
+                        if (authzst) {
+                            getAuthorizationDecisionStatements().push_back(authzst->cloneAuthorizationDecisionStatement());
+                            continue;
+                        }
     
                         SubjectStatement* subst=dynamic_cast<SubjectStatement*>(*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);
index f789011..2980972 100644 (file)
@@ -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.");
index 85ec2b2..13e3adb 100644 (file)
Binary files a/samltest/data/saml1/core/impl/AssertionWithChildren.xml and b/samltest/data/saml1/core/impl/AssertionWithChildren.xml differ
index 4c6a67f..26d6715 100644 (file)
Binary files a/samltest/data/saml1/core/impl/singleAssertion.xml and b/samltest/data/saml1/core/impl/singleAssertion.xml differ
index 251b3c1..1c97b69 100644 (file)
@@ -64,6 +64,7 @@ protected:
             return b->buildFromDocument(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 (file)
index 0000000..1f65eec
--- /dev/null
@@ -0,0 +1,147 @@
+/*\r
+ *  Copyright 2001-2006 Internet2\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include "internal.h"\r
+#include <saml/saml1/core/Assertions.h>\r
+\r
+using namespace opensaml::saml1;\r
+\r
+class AssertionTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
+    int expectedMinorVersion;\r
+    XMLCh* expectedIssuer;\r
+    XMLCh* expectedIssueInstant;\r
+    XMLCh* expectedID;\r
+\r
+public:\r
+    void setUp() {\r
+        expectedID=XMLString::transcode("ident");\r
+        expectedMinorVersion=1;\r
+        expectedIssueInstant=XMLString::transcode("1970-01-02T01:01:02.100Z");\r
+        expectedIssuer=XMLString::transcode("issuer");\r
+        singleElementFile = data_path + "saml1/core/impl/singleAssertion.xml";\r
+        singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAssertionAttributes.xml";\r
+        childElementsFile  = data_path + "saml1/core/impl/AssertionWithChildren.xml";    \r
+        SAMLObjectBaseTestCase::setUp();\r
+    }\r
+    \r
+    void tearDown() {\r
+        XMLString::release(&expectedID);\r
+        XMLString::release(&expectedIssueInstant);\r
+        XMLString::release(&expectedIssuer);\r
+        SAMLObjectBaseTestCase::tearDown();\r
+    }\r
+\r
+    void testSingleElementUnmarshall() {\r
+        auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
+        Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());\r
+        TSM_ASSERT("Issuer attribute", assertion.getIssuer()==NULL);\r
+        TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant));\r
+        TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID));\r
+\r
+        TSM_ASSERT("Conditions element", assertion.getConditions()==NULL);\r
+        TSM_ASSERT("Advice element", assertion.getAdvice()==NULL);\r
+\r
+        TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());\r
+        TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());\r
+        TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());\r
+        TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());\r
+        TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());\r
+    }\r
+\r
+    void testSingleElementOptionalAttributesUnmarshall() {\r
+        auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));\r
+        Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());\r
+\r
+        TSM_ASSERT_SAME_DATA("Issuer attribute", expectedIssuer, assertion.getIssuer(), XMLString::stringLen(expectedIssuer));\r
+        TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant));\r
+        TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID));\r
+        TSM_ASSERT_EQUALS("Issuer expectedMinorVersion", expectedMinorVersion, assertion.getMinorVersion());\r
+\r
+        TSM_ASSERT("Conditions element", assertion.getConditions()==NULL);\r
+        TSM_ASSERT("Advice element", assertion.getAdvice()==NULL);\r
+\r
+        TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());\r
+        TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());\r
+        TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());\r
+        TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());\r
+        TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());\r
+    }\r
+\r
+    void testChildElementsUnmarshall() {\r
+        auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
+        Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());\r
+\r
+        TSM_ASSERT("Issuer attribute", assertion.getIssuer()==NULL);\r
+        TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant));\r
+        TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID));\r
+\r
+        TSM_ASSERT("Conditions element null", assertion.getConditions()!=NULL);\r
+        TSM_ASSERT("Advice element null", assertion.getAdvice()!=NULL);\r
+\r
+        TSM_ASSERT_EQUALS("AuthenticationStatements element count", 2, assertion.getAuthenticationStatements().size());\r
+        TSM_ASSERT_EQUALS("AttributeStatements element count", 3, assertion.getAttributeStatements().size());\r
+        TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 3, assertion.getAuthorizationDecisionStatements().size());\r
+    }\r
+\r
+    void testSingleElementMarshall() {\r
+        Assertion* assertion=AssertionBuilder::buildAssertion();\r
+        assertion->setAssertionID(expectedID);\r
+        assertion->setIssueInstant(expectedIssueInstant);\r
+        assertEquals(expectedDOM, assertion);\r
+    }\r
+\r
+    void testSingleElementOptionalAttributesMarshall() {\r
+        Assertion* assertion=AssertionBuilder::buildAssertion();\r
+        assertion->setIssueInstant(expectedIssueInstant);\r
+        assertion->setAssertionID(expectedID);\r
+        assertion->setIssuer(expectedIssuer);\r
+        assertEquals(expectedOptionalAttributesDOM, assertion);\r
+    }\r
+\r
+    void testChildElementsMarshall() {\r
+        Assertion* assertion=AssertionBuilder::buildAssertion();\r
+        assertion->setIssueInstant(expectedIssueInstant);\r
+        assertion->setAssertionID(expectedID);\r
+        assertion->setConditions(ConditionsBuilder::buildConditions());\r
+        assertion->setAdvice(AdviceBuilder::buildAdvice());\r
+        assertion->getAuthenticationStatements().push_back(\r
+            AuthenticationStatementBuilder::buildAuthenticationStatement()\r
+            );\r
+        assertion->getAuthorizationDecisionStatements().push_back(\r
+            AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()\r
+            );\r
+        assertion->getAttributeStatements().push_back(\r
+            AttributeStatementBuilder::buildAttributeStatement()\r
+            );\r
+        assertion->getAuthenticationStatements().push_back(\r
+            AuthenticationStatementBuilder::buildAuthenticationStatement()\r
+            );\r
+        assertion->getAuthorizationDecisionStatements().push_back(\r
+            AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()\r
+            );\r
+        assertion->getAttributeStatements().push_back(\r
+            AttributeStatementBuilder::buildAttributeStatement()\r
+            );\r
+        assertion->getAuthorizationDecisionStatements().push_back(\r
+            AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()\r
+            );\r
+        assertion->getAttributeStatements().push_back(\r
+            AttributeStatementBuilder::buildAttributeStatement()\r
+            );\r
+        assertEquals(expectedChildElementsDOM, assertion);\r
+    }\r
+\r
+};\r
index 7e39b7f..5c4b19d 100644 (file)
                                                        RelativePath=".\saml1\core\impl\AssertionIDReferenceTest.cpp"\r
                                                        >\r
                                                </File>\r
+                                               <File\r
+                                                       RelativePath=".\saml1\core\impl\AssertionTest.cpp"\r
+                                                       >\r
+                                               </File>\r
                                        </Filter>\r
                                </Filter>\r
                        </Filter>\r
                                                                />\r
                                                        </FileConfiguration>\r
                                                </File>\r
+                                               <File\r
+                                                       RelativePath=".\saml1\core\impl\AssertionTest.h"\r
+                                                       >\r
+                                                       <FileConfiguration\r
+                                                               Name="Debug|Win32"\r
+                                                               >\r
+                                                               <Tool\r
+                                                                       Name="VCCustomBuildTool"\r
+                                                                       CommandLine="\perl\bin\perl.exe -w \cxxtest\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o &quot;$(InputDir)$(InputName)&quot;.cpp &quot;$(InputPath)&quot;"\r
+                                                                       Outputs="&quot;$(InputDir)$(InputName)&quot;.cpp"\r
+                                                               />\r
+                                                       </FileConfiguration>\r
+                                                       <FileConfiguration\r
+                                                               Name="Release|Win32"\r
+                                                               >\r
+                                                               <Tool\r
+                                                                       Name="VCCustomBuildTool"\r
+                                                                       CommandLine="\perl\bin\perl.exe -w \cxxtest\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o &quot;$(InputDir)$(InputName)&quot;.cpp &quot;$(InputPath)&quot;"\r
+                                                                       Outputs="&quot;$(InputDir)$(InputName)&quot;.cpp"\r
+                                                               />\r
+                                                       </FileConfiguration>\r
+                                               </File>\r
                                        </Filter>\r
                                </Filter>\r
                        </Filter>\r