288baf4994ad5c40612fb17808404c556892a093
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / ManageNameIDRequest20Test.h
1 /*
2  *  Copyright 2001-2006 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "internal.h"
18 #include <saml/saml2/core/Protocols.h>
19 #include <saml/util/SAMLConstants.h>
20
21 using namespace opensaml::saml2p;
22 using namespace opensaml::saml2;
23
24 class ManageNameIDRequest20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
25     XMLCh* expectedID; 
26     XMLCh* expectedVersion; 
27     DateTime* expectedIssueInstant; 
28     XMLCh* expectedConsent; 
29     XMLCh* expectedDestination; 
30
31 public:
32     void setUp() {
33         expectedID = XMLString::transcode("abc123");; 
34         expectedVersion = XMLString::transcode("2.0"); 
35         expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
36         expectedIssueInstant->parseDateTime();
37         expectedConsent = XMLString::transcode("urn:string:consent"); 
38         expectedDestination = XMLString::transcode("http://idp.example.org/endpoint"); 
39
40         singleElementFile = data_path + "saml2/core/impl/ManageNameIDRequest.xml";
41         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ManageNameIDRequestOptionalAttributes.xml";
42         childElementsFile  = data_path + "saml2/core/impl/ManageNameIDRequestChildElements.xml";    
43         SAMLObjectBaseTestCase::setUp();
44     }
45     
46     void tearDown() {
47         XMLString::release(&expectedID);
48         XMLString::release(&expectedVersion);
49         XMLString::release(&expectedConsent);
50         XMLString::release(&expectedDestination);
51         delete expectedIssueInstant;
52         SAMLObjectBaseTestCase::tearDown();
53     }
54
55     void testSingleElementUnmarshall() {
56         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
57         ManageNameIDRequest* request = dynamic_cast<ManageNameIDRequest*>(xo.get());
58         TS_ASSERT(request!=NULL);
59         assertEquals("ID attribute", expectedID, request->getID());
60         assertEquals("Version attribute", expectedVersion, request->getVersion());
61         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), request->getIssueInstant()->getEpoch());
62
63         TS_ASSERT(request->getIssuer()==NULL);
64         TS_ASSERT(request->getSignature()==NULL);
65         TS_ASSERT(request->getExtensions()==NULL);
66         TS_ASSERT(request->getNameID()==NULL);
67         TS_ASSERT(request->getEncryptedID()==NULL);
68         TS_ASSERT(request->getNewID()==NULL);
69         TS_ASSERT(request->getNewEncryptedID()==NULL);
70         TS_ASSERT(request->getTerminate()==NULL);
71     }
72
73     void testSingleElementOptionalAttributesUnmarshall() {
74         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
75         ManageNameIDRequest* request = dynamic_cast<ManageNameIDRequest*>(xo.get());
76         TS_ASSERT(request!=NULL);
77
78         assertEquals("Consent attribute", expectedConsent, request->getConsent());
79         assertEquals("Destination attribute", expectedDestination, request->getDestination());
80
81         TS_ASSERT(request->getIssuer()==NULL);
82         TS_ASSERT(request->getSignature()==NULL);
83         TS_ASSERT(request->getExtensions()==NULL);
84         TS_ASSERT(request->getNameID()==NULL);
85         TS_ASSERT(request->getEncryptedID()==NULL);
86         TS_ASSERT(request->getNewID()==NULL);
87         TS_ASSERT(request->getNewEncryptedID()==NULL);
88         TS_ASSERT(request->getTerminate()==NULL);
89     }
90
91     void testChildElementsUnmarshall() {
92         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
93         ManageNameIDRequest* request= dynamic_cast<ManageNameIDRequest*>(xo.get());
94         TS_ASSERT(request!=NULL);
95         TS_ASSERT(request->getIssuer()!=NULL);
96         TS_ASSERT(request->getSignature()==NULL);
97         TS_ASSERT(request->getExtensions()==NULL);
98         TS_ASSERT(request->getNameID()!=NULL);
99         TS_ASSERT(request->getEncryptedID()==NULL);
100         TS_ASSERT(request->getNewID()!=NULL);
101         TS_ASSERT(request->getNewEncryptedID()==NULL);
102         TS_ASSERT(request->getTerminate()==NULL);
103     }
104
105     void testSingleElementMarshall() {
106         ManageNameIDRequest* request=ManageNameIDRequestBuilder::buildManageNameIDRequest();
107         request->setID(expectedID);
108         request->setIssueInstant(expectedIssueInstant);
109         //request->setVersion(expectedVersion);
110         assertEquals(expectedDOM, request);
111     }
112
113     void testSingleElementOptionalAttributesMarshall() {
114         ManageNameIDRequest* request=ManageNameIDRequestBuilder::buildManageNameIDRequest();
115         request->setID(expectedID);
116         request->setIssueInstant(expectedIssueInstant);
117         //request->setVersion(expectedVersion);
118         request->setConsent(expectedConsent);
119         request->setDestination(expectedDestination);
120         assertEquals(expectedOptionalAttributesDOM, request);
121     }
122
123     void testChildElementsMarshall() {
124         ManageNameIDRequest* request=ManageNameIDRequestBuilder::buildManageNameIDRequest();
125         request->setID(expectedID);
126         request->setIssueInstant(expectedIssueInstant);
127         // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
128         Namespace* ns = new Namespace(opensaml::SAMLConstants::SAML20_NS, opensaml::SAMLConstants::SAML20_PREFIX);
129         request->addNamespace(*ns);
130         request->setIssuer(IssuerBuilder::buildIssuer());
131         request->setNameID(NameIDBuilder::buildNameID());
132         request->setNewID(NewIDBuilder::buildNewID());
133         assertEquals(expectedChildElementsDOM, request);
134         delete ns;
135     }
136
137 };