7387e340d6239445cc8888a2e9fc380da6f0d78b
[shibboleth/cpp-opensaml.git] / samltest / saml1 / core / impl / AssertionTest.h
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \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
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 #include "internal.h"\r
18 #include <saml/saml1/core/Assertions.h>\r
19 \r
20 using namespace opensaml::saml1;\r
21 \r
22 class AssertionTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
23     int expectedMinorVersion;\r
24     XMLCh* expectedIssuer;\r
25     XMLCh* expectedIssueInstant;\r
26     XMLCh* expectedID;\r
27 \r
28 public:\r
29     void setUp() {\r
30         expectedID=XMLString::transcode("ident");\r
31         expectedMinorVersion=1;\r
32         expectedIssueInstant=XMLString::transcode("1970-01-02T01:01:02.100Z");\r
33         expectedIssuer=XMLString::transcode("issuer");\r
34         singleElementFile = data_path + "saml1/core/impl/singleAssertion.xml";\r
35         singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAssertionAttributes.xml";\r
36         childElementsFile  = data_path + "saml1/core/impl/AssertionWithChildren.xml";    \r
37         SAMLObjectBaseTestCase::setUp();\r
38     }\r
39     \r
40     void tearDown() {\r
41         XMLString::release(&expectedID);\r
42         XMLString::release(&expectedIssueInstant);\r
43         XMLString::release(&expectedIssuer);\r
44         SAMLObjectBaseTestCase::tearDown();\r
45     }\r
46 \r
47     void testSingleElementUnmarshall() {\r
48         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
49         Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());\r
50         TSM_ASSERT("Issuer attribute", assertion.getIssuer()==NULL);\r
51         TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant));\r
52         TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID));\r
53 \r
54         TSM_ASSERT("Conditions element", assertion.getConditions()==NULL);\r
55         TSM_ASSERT("Advice element", assertion.getAdvice()==NULL);\r
56 \r
57         TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());\r
58         TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());\r
59         TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());\r
60         TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());\r
61         TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());\r
62     }\r
63 \r
64     void testSingleElementOptionalAttributesUnmarshall() {\r
65         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));\r
66         Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());\r
67 \r
68         TSM_ASSERT_SAME_DATA("Issuer attribute", expectedIssuer, assertion.getIssuer(), XMLString::stringLen(expectedIssuer));\r
69         TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant));\r
70         TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID));\r
71         TSM_ASSERT_EQUALS("Issuer expectedMinorVersion", expectedMinorVersion, assertion.getMinorVersion().second);\r
72 \r
73         TSM_ASSERT("Conditions element", assertion.getConditions()==NULL);\r
74         TSM_ASSERT("Advice element", assertion.getAdvice()==NULL);\r
75 \r
76         TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());\r
77         TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());\r
78         TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());\r
79         TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());\r
80         TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());\r
81     }\r
82 \r
83     void testChildElementsUnmarshall() {\r
84         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
85         Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());\r
86 \r
87         TSM_ASSERT("Issuer attribute", assertion.getIssuer()==NULL);\r
88         TSM_ASSERT_SAME_DATA("IssueInstant attribute", expectedIssueInstant, assertion.getIssueInstant()->getRawData(), XMLString::stringLen(expectedIssueInstant));\r
89         TSM_ASSERT_SAME_DATA("ID attribute", expectedID, assertion.getAssertionID(), XMLString::stringLen(expectedID));\r
90 \r
91         TSM_ASSERT("Conditions element null", assertion.getConditions()!=NULL);\r
92         TSM_ASSERT("Advice element null", assertion.getAdvice()!=NULL);\r
93 \r
94         TSM_ASSERT_EQUALS("AuthenticationStatements element count", 2, assertion.getAuthenticationStatements().size());\r
95         TSM_ASSERT_EQUALS("AttributeStatements element count", 3, assertion.getAttributeStatements().size());\r
96         TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 3, assertion.getAuthorizationDecisionStatements().size());\r
97     }\r
98 \r
99     void testSingleElementMarshall() {\r
100         Assertion* assertion=AssertionBuilder::buildAssertion();\r
101         assertion->setAssertionID(expectedID);\r
102         assertion->setIssueInstant(expectedIssueInstant);\r
103         assertEquals(expectedDOM, assertion);\r
104     }\r
105 \r
106     void testSingleElementOptionalAttributesMarshall() {\r
107         Assertion* assertion=AssertionBuilder::buildAssertion();\r
108         assertion->setIssueInstant(expectedIssueInstant);\r
109         assertion->setAssertionID(expectedID);\r
110         assertion->setIssuer(expectedIssuer);\r
111         assertEquals(expectedOptionalAttributesDOM, assertion);\r
112     }\r
113 \r
114     void testChildElementsMarshall() {\r
115         Assertion* assertion=AssertionBuilder::buildAssertion();\r
116         assertion->setIssueInstant(expectedIssueInstant);\r
117         assertion->setAssertionID(expectedID);\r
118         assertion->setConditions(ConditionsBuilder::buildConditions());\r
119         assertion->setAdvice(AdviceBuilder::buildAdvice());\r
120         assertion->getAuthenticationStatements().push_back(\r
121             AuthenticationStatementBuilder::buildAuthenticationStatement()\r
122             );\r
123         assertion->getAuthorizationDecisionStatements().push_back(\r
124             AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()\r
125             );\r
126         assertion->getAttributeStatements().push_back(\r
127             AttributeStatementBuilder::buildAttributeStatement()\r
128             );\r
129         assertion->getAuthenticationStatements().push_back(\r
130             AuthenticationStatementBuilder::buildAuthenticationStatement()\r
131             );\r
132         assertion->getAuthorizationDecisionStatements().push_back(\r
133             AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()\r
134             );\r
135         assertion->getAttributeStatements().push_back(\r
136             AttributeStatementBuilder::buildAttributeStatement()\r
137             );\r
138         assertion->getAuthorizationDecisionStatements().push_back(\r
139             AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()\r
140             );\r
141         assertion->getAttributeStatements().push_back(\r
142             AttributeStatementBuilder::buildAttributeStatement()\r
143             );\r
144         assertEquals(expectedChildElementsDOM, assertion);\r
145     }\r
146 \r
147 };\r