Create parser pool interface and move current pool to an implementation of this inter...
[java-idp.git] / tests / edu / internet2 / middleware / shibboleth / idp / AATest.java
1 /*
2  * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
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 package edu.internet2.middleware.shibboleth.idp;
18
19 import java.io.File;
20
21 import edu.internet2.middleware.shibboleth.utils.FileUtils;
22 import edu.internet2.middleware.shibboleth.utils.MockObjectUtils;
23
24 /**
25  * MockObject unit tests for Shibboleth IdP Attribute Authority component
26  * 
27  * @author Will Norris (wnorris@memphis.edu)
28  */
29 public class AATest extends IdpTestCase {
30
31         /**
32          * Initialize request object with default client SSL certificate
33          * 
34          * @param requestFilename
35          *            path to file containing HTTP body for request
36          * @throws Exception
37          */
38         private void initRequest(String requestFilename) throws Exception {
39
40                 initRequest(requestFilename, "data/idp/blackbox/sp.crt");
41         }
42
43         /**
44          * Initialize request object with given client SSL certificate
45          * 
46          * @param requestFilename
47          *            path to file containing HTTP body for request
48          * @param certFilename
49          *            path to file containing client SSL certificate
50          * @throws Exception
51          */
52         private void initRequest(String requestFilename, String certFilename) throws Exception {
53
54                 File requestFile = new File(requestFilename);
55
56                 request.setRemoteAddr("127.0.0.1");
57                 request.setContextPath("/shibboleth-idp");
58                 request.setProtocol("HTTP/1.1");
59                 request.setScheme("https");
60                 request.setServerName("idp.example.org");
61                 request.setServerPort(443);
62
63                 request.setMethod("POST");
64                 request.setRequestURL("https://idp.example.org/shibboleth-idp/AA");
65                 request.setRequestURI("https://idp.example.org/shibboleth-idp/AA");
66                 request.setContentType("text/xml");
67                 request.setHeader("SOAPAction", "http://www.oasis-open.org/committees/security");
68                 request.setContentLength(new Long(requestFile.length()).intValue());
69
70                 request.setBodyContent(FileUtils.readFileToString(requestFile, "utf-8"));
71                 MockObjectUtils.setClientCert(request, certFilename);
72         }
73
74         /**
75          * Basic working Attribute Query
76          * 
77          * @throws Exception
78          */
79         public void testBasicAttrQuery() throws Exception {
80
81                 resetServlet("data/idp/blackbox/conf/standard");
82                 initRequest("data/idp/blackbox/aa/request01.txt");
83
84                 testModule.doPost();
85
86                 assertTrue(responsesAreEqual(FileUtils.readFileToString(new File("data/idp/blackbox/aa/response01.txt"),
87                                 "utf-8"), response.getOutputStreamContent()));
88         }
89
90         /**
91          * Attribute Query with invalid client credentials
92          * 
93          * @throws Exception
94          */
95         public void testAttrQueryWithInvalidCred() throws Exception {
96
97                 resetServlet("data/idp/blackbox/conf/standard");
98                 initRequest("data/idp/blackbox/aa/request01.txt", "data/idp/blackbox/sp-bad.crt");
99
100                 testModule.doPost();
101
102                 assertEquals("Invalid credentials for request.", MockObjectUtils.getSamlStatusMessage(response));
103         }
104
105         /**
106          * Attribute Query with default relying party
107          * 
108          * @throws Exception
109          */
110         public void testAttrQueryWithDefaultRelyingParty() throws Exception {
111
112                 resetServlet("data/idp/blackbox/conf/SPRelyingParty");
113                 initRequest("data/idp/blackbox/aa/request01.txt");
114
115                 testModule.doPost();
116
117                 assertTrue(responsesAreEqual(FileUtils.readFileToString(new File("data/idp/blackbox/aa/response01.txt"),
118                                 "utf-8"), response.getOutputStreamContent()));
119         }
120
121         /**
122          * Attribute Query with SP matched relying party
123          * 
124          * @throws Exception
125          */
126         public void testAttrQueryWithSpMatchedRelyingParty() throws Exception {
127
128                 resetServlet("data/idp/blackbox/conf/SPRelyingParty");
129                 initRequest("data/idp/blackbox/aa/request03.txt");
130
131                 testModule.doPost();
132
133                 assertTrue(responsesAreEqual(FileUtils.readFileToString(new File("data/idp/blackbox/aa/response03.txt"),
134                                 "utf-8"), response.getOutputStreamContent()));
135         }
136
137         /**
138          * Attribute Query with group matched relying party
139          * 
140          * @throws Exception
141          */
142         public void testAttrQueryWithGroupMatchedRelyingParty() throws Exception {
143
144                 resetServlet("data/idp/blackbox/conf/groupRelyingParty");
145                 initRequest("data/idp/blackbox/aa/request04.txt");
146
147                 testModule.doPost();
148
149                 assertTrue(responsesAreEqual(FileUtils.readFileToString(new File("data/idp/blackbox/aa/response04.txt"),
150                                 "utf-8"), response.getOutputStreamContent()));
151         }
152
153         /**
154          * Attribute Query with error pass thru
155          * 
156          * @throws Exception
157          */
158         public void testAttrQueryWithErrorPassThru() throws Exception {
159
160                 resetServlet("data/idp/blackbox/conf/passThruErrors");
161                 initRequest("data/idp/blackbox/aa/request05.txt");
162
163                 testModule.doPost();
164
165                 assertEquals("General error processing request. (wrapped: Name Identifier format not registered.)",
166                                 MockObjectUtils.getSamlStatusMessage(response));
167         }
168
169         /**
170          * Attribute Query with attribute designators. Instead of the IdP returning all attributes allowed for the
171          * requesting SP, the SP specifies specifically which attributes it wants.
172          * 
173          * @throws Exception
174          */
175         public void testAttrQueryWithAttrDesignators() throws Exception {
176
177                 resetServlet("data/idp/blackbox/conf/standard");
178                 initRequest("data/idp/blackbox/aa/request06.txt");
179
180                 testModule.doPost();
181
182                 assertTrue(responsesAreEqual(FileUtils.readFileToString(new File("data/idp/blackbox/aa/response06.txt"),
183                                 "utf-8"), response.getOutputStreamContent()));
184         }
185
186         /**
187          * Attribute Query with unknown name identifier type
188          * 
189          * @throws Exception
190          */
191         public void testAttrQueryWithUnknownNameIdentifierType() throws Exception {
192
193                 resetServlet("data/idp/blackbox/conf/standard");
194                 initRequest("data/idp/blackbox/aa/request05.txt");
195
196                 testModule.doPost();
197
198                 assertEquals("General error processing request.", MockObjectUtils.getSamlStatusMessage(response));
199         }
200
201         /**
202          * Attribute Query with incorrect name identifier
203          * 
204          * @throws Exception
205          */
206         public void testAttrQueryWithIncorrectNameIdentifier() throws Exception {
207
208                 resetServlet("data/idp/blackbox/conf/groupRelyingParty");
209                 initRequest("data/idp/blackbox/aa/request07.txt");
210
211                 testModule.doPost();
212
213                 assertEquals("General error processing request.", MockObjectUtils.getSamlStatusMessage(response));
214         }
215
216         /**
217          * Attribute Query with signed assertions
218          * 
219          * @throws Exception
220          */
221         public void testAttrQueryWithSignedAssertions() throws Exception {
222
223                 resetServlet("data/idp/blackbox/conf/signAssertions");
224                 initRequest("data/idp/blackbox/aa/request01.txt");
225
226                 testModule.doPost();
227
228                 assertTrue(responsesAreEqual(FileUtils.readFileToString(new File("data/idp/blackbox/aa/response08.txt"),
229                                 "utf-8"), response.getOutputStreamContent()));
230         }
231
232         /**
233          * Attribute Query with ARP constraint
234          * 
235          * @throws Exception
236          */
237         public void testAttrQueryWithConstraint() throws Exception {
238
239                 resetServlet("data/idp/blackbox/conf/constraints");
240                 initRequest("data/idp/blackbox/aa/request01.txt");
241
242                 testModule.doPost();
243
244                 assertTrue(responsesAreEqual(FileUtils.readFileToString(new File("data/idp/blackbox/aa/response09.txt"),
245                                 "utf-8"), response.getOutputStreamContent()));
246         }
247
248         /**
249          * Attribute Query with attribute designators and ARP constraint
250          * 
251          * @throws Exception
252          */
253         public void testAttrQueryWithDesignatorsAndConstraint() throws Exception {
254
255                 resetServlet("data/idp/blackbox/conf/constraints");
256                 initRequest("data/idp/blackbox/aa/request06.txt");
257
258                 testModule.doPost();
259
260                 assertTrue(responsesAreEqual(FileUtils.readFileToString(new File("data/idp/blackbox/aa/response06.txt"),
261                                 "utf-8"), response.getOutputStreamContent()));
262         }
263
264 }