Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / AuthnQuery20Test.h
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include "internal.h"
22 #include <saml/saml2/core/Protocols.h>
23 #include <saml/util/SAMLConstants.h>
24
25 using namespace opensaml::saml2p;
26 using namespace opensaml::saml2;
27
28 class AuthnQuery20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
29     XMLCh* expectedID; 
30     XMLCh* expectedVersion; 
31     XMLCh* expectedConsent; 
32     XMLCh* expectedDestination; 
33     DateTime* expectedIssueInstant; 
34     XMLCh* expectedSessionIndex; 
35
36 public:
37     void setUp() {
38         expectedID = XMLString::transcode("abc123");; 
39         expectedVersion = XMLString::transcode("2.0"); 
40         expectedConsent = XMLString::transcode("urn:string:consent"); 
41         expectedDestination = XMLString::transcode("http://idp.example.org/endpoint"); 
42         expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
43         expectedIssueInstant->parseDateTime();
44         expectedSessionIndex = XMLString::transcode("session12345"); 
45
46         singleElementFile = data_path + "saml2/core/impl/AuthnQuery.xml";
47         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AuthnQueryOptionalAttributes.xml";
48         childElementsFile  = data_path + "saml2/core/impl/AuthnQueryChildElements.xml";    
49         SAMLObjectBaseTestCase::setUp();
50     }
51     
52     void tearDown() {
53         XMLString::release(&expectedID);
54         XMLString::release(&expectedVersion);
55         XMLString::release(&expectedConsent);
56         XMLString::release(&expectedDestination);
57         XMLString::release(&expectedSessionIndex);
58         delete expectedIssueInstant;
59         SAMLObjectBaseTestCase::tearDown();
60     }
61
62     void testSingleElementUnmarshall() {
63         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
64         AuthnQuery* query = dynamic_cast<AuthnQuery*>(xo.get());
65         TS_ASSERT(query!=nullptr);
66         assertEquals("ID attribute", expectedID, query->getID());
67         assertEquals("Version attribute", expectedVersion, query->getVersion());
68         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), query->getIssueInstant()->getEpoch());
69
70         TS_ASSERT(query->getIssuer()==nullptr);
71         TS_ASSERT(query->getSignature()==nullptr);
72         TS_ASSERT(query->getExtensions()==nullptr);
73         TS_ASSERT(query->getSubject()==nullptr);
74         TS_ASSERT(query->getRequestedAuthnContext()==nullptr);
75     }
76
77     void testSingleElementOptionalAttributesUnmarshall() {
78         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
79         AuthnQuery* query = dynamic_cast<AuthnQuery*>(xo.get());
80         TS_ASSERT(query!=nullptr);
81         assertEquals("Consent attribute", expectedConsent, query->getConsent());
82         assertEquals("Destination attribute", expectedDestination, query->getDestination());
83         assertEquals("SessionIndex attribute", expectedSessionIndex, query->getSessionIndex());
84
85         TS_ASSERT(query->getIssuer()==nullptr);
86         TS_ASSERT(query->getSignature()==nullptr);
87         TS_ASSERT(query->getExtensions()==nullptr);
88         TS_ASSERT(query->getSubject()==nullptr);
89         TS_ASSERT(query->getRequestedAuthnContext()==nullptr);
90     }
91
92     void testChildElementsUnmarshall() {
93         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
94         AuthnQuery* query= dynamic_cast<AuthnQuery*>(xo.get());
95         TS_ASSERT(query!=nullptr);
96         TS_ASSERT(query->getIssuer()!=nullptr);
97         TS_ASSERT(query->getSignature()==nullptr);
98         TS_ASSERT(query->getExtensions()==nullptr);
99         TS_ASSERT(query->getSubject()!=nullptr);
100         TS_ASSERT(query->getRequestedAuthnContext()!=nullptr);
101     }
102
103     void testSingleElementMarshall() {
104         AuthnQuery* query=AuthnQueryBuilder::buildAuthnQuery();
105         query->setID(expectedID);
106         query->setIssueInstant(expectedIssueInstant);
107         //query->setVersion(expectedVersion);
108         assertEquals(expectedDOM, query);
109     }
110
111     void testSingleElementOptionalAttributesMarshall() {
112         AuthnQuery* query=AuthnQueryBuilder::buildAuthnQuery();
113         query->setID(expectedID);
114         query->setIssueInstant(expectedIssueInstant);
115         //query->setVersion(expectedVersion);
116         query->setConsent(expectedConsent);
117         query->setDestination(expectedDestination);
118         query->setSessionIndex(expectedSessionIndex);
119         assertEquals(expectedOptionalAttributesDOM, query);
120     }
121
122     void testChildElementsMarshall() {
123         AuthnQuery* query=AuthnQueryBuilder::buildAuthnQuery();
124         query->setID(expectedID);
125         query->setIssueInstant(expectedIssueInstant);
126         // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
127         Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
128         query->addNamespace(*ns);
129         query->setIssuer(IssuerBuilder::buildIssuer());
130         query->setSubject(SubjectBuilder::buildSubject());
131         query->setRequestedAuthnContext(RequestedAuthnContextBuilder::buildRequestedAuthnContext());
132         assertEquals(expectedChildElementsDOM, query);
133         delete ns;
134     }
135
136 };