View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.wss4j.dom.handler;
21  
22  import org.apache.wss4j.dom.WSConstants;
23  import org.apache.wss4j.dom.common.CustomHandler;
24  
25  import org.apache.wss4j.dom.engine.WSSecurityEngineResult;
26  
27  import org.junit.jupiter.api.Test;
28  
29  import static org.junit.jupiter.api.Assertions.assertFalse;
30  import static org.junit.jupiter.api.Assertions.assertTrue;
31  
32  
33  /**
34   * This is a test for WSS-147. A "checkReceiverResultsAnyOrder" method is added to WSHandler
35   * which applications can use if they want.
36   */
37  public class ResultsOrderTest {
38  
39      /**
40       */
41      @Test
42      public void
43      testOrder() throws Exception {
44          CustomHandler handler = new CustomHandler();
45  
46          java.util.List<WSSecurityEngineResult> results = new java.util.ArrayList<>();
47          results.add(
48              new WSSecurityEngineResult(WSConstants.UT)
49          );
50          results.add(
51              new WSSecurityEngineResult(WSConstants.TS)
52          );
53          results.add(
54              new WSSecurityEngineResult(WSConstants.SC)
55          );
56          results.add(
57              new WSSecurityEngineResult(WSConstants.SIGN)
58          );
59  
60          java.util.List<Integer> actions = new java.util.ArrayList<>();
61          actions.add(WSConstants.UT);
62          actions.add(WSConstants.TS);
63          actions.add(WSConstants.SIGN);
64  
65          assertTrue(handler.checkResults(results, actions));
66          assertTrue(handler.checkResultsAnyOrder(results, actions));
67      }
68  
69      /**
70       */
71      @Test
72      public void
73      testReverseOrder() throws Exception {
74          CustomHandler handler = new CustomHandler();
75  
76          java.util.List<WSSecurityEngineResult> results = new java.util.ArrayList<>();
77          results.add(
78              new WSSecurityEngineResult(WSConstants.SIGN)
79          );
80          results.add(
81              new WSSecurityEngineResult(WSConstants.SC)
82          );
83          results.add(
84              new WSSecurityEngineResult(WSConstants.TS)
85          );
86          results.add(
87              new WSSecurityEngineResult(WSConstants.UT)
88          );
89  
90          java.util.List<Integer> actions = new java.util.ArrayList<>();
91          actions.add(WSConstants.UT);
92          actions.add(WSConstants.TS);
93          actions.add(WSConstants.SIGN);
94  
95          assertFalse(handler.checkResults(results, actions));
96          assertTrue(handler.checkResultsAnyOrder(results, actions));
97          assertTrue(results.size() == 4 && actions.size() == 3);
98      }
99  
100     /**
101      */
102     @Test
103     public void
104     testMixedOrder() throws Exception {
105         CustomHandler handler = new CustomHandler();
106 
107         java.util.List<WSSecurityEngineResult> results =
108             new java.util.ArrayList<>();
109         results.add(
110             new WSSecurityEngineResult(WSConstants.TS)
111         );
112         results.add(
113             new WSSecurityEngineResult(WSConstants.SIGN)
114         );
115         results.add(
116             new WSSecurityEngineResult(WSConstants.SC)
117         );
118         results.add(
119             new WSSecurityEngineResult(WSConstants.UT)
120         );
121 
122         java.util.List<Integer> actions = new java.util.ArrayList<>();
123         actions.add(WSConstants.UT);
124         actions.add(WSConstants.TS);
125         actions.add(WSConstants.SIGN);
126 
127         assertFalse(handler.checkResults(results, actions));
128         assertTrue(handler.checkResultsAnyOrder(results, actions));
129         assertFalse(actions.isEmpty());
130     }
131 
132     /**
133      */
134     @Test
135     public void
136     testMixedOrder2() throws Exception {
137         CustomHandler handler = new CustomHandler();
138 
139         java.util.List<WSSecurityEngineResult> results =
140             new java.util.ArrayList<>();
141         results.add(
142             new WSSecurityEngineResult(WSConstants.TS)
143         );
144         results.add(
145             new WSSecurityEngineResult(WSConstants.SIGN)
146         );
147         results.add(
148             new WSSecurityEngineResult(WSConstants.SC)
149         );
150         results.add(
151             new WSSecurityEngineResult(WSConstants.UT)
152         );
153 
154         java.util.List<Integer> actions = new java.util.ArrayList<>();
155         actions.add(WSConstants.SIGN);
156         actions.add(WSConstants.UT);
157         actions.add(WSConstants.TS);
158 
159         assertFalse(handler.checkResults(results, actions));
160         assertTrue(handler.checkResultsAnyOrder(results, actions));
161     }
162 
163     /**
164      */
165     @Test
166     public void
167     testMissingResult() throws Exception {
168         CustomHandler handler = new CustomHandler();
169 
170         java.util.List<WSSecurityEngineResult> results =
171             new java.util.ArrayList<>();
172         results.add(
173             new WSSecurityEngineResult(WSConstants.UT)
174         );
175         results.add(
176             new WSSecurityEngineResult(WSConstants.TS)
177         );
178         results.add(
179             new WSSecurityEngineResult(WSConstants.SC)
180         );
181 
182         java.util.List<Integer> actions = new java.util.ArrayList<>();
183         actions.add(WSConstants.TS);
184         actions.add(WSConstants.UT);
185         actions.add(WSConstants.SIGN);
186 
187         assertFalse(handler.checkResults(results, actions));
188         assertFalse(handler.checkResultsAnyOrder(results, actions));
189     }
190 
191     /**
192      */
193     @Test
194     public void
195     testMissingAction() throws Exception {
196         CustomHandler handler = new CustomHandler();
197 
198         java.util.List<WSSecurityEngineResult> results =
199             new java.util.ArrayList<>();
200         results.add(
201             new WSSecurityEngineResult(WSConstants.UT)
202         );
203         results.add(
204             new WSSecurityEngineResult(WSConstants.TS)
205         );
206         results.add(
207             new WSSecurityEngineResult(WSConstants.SIGN)
208         );
209         results.add(
210             new WSSecurityEngineResult(WSConstants.SC)
211         );
212 
213         java.util.List<Integer> actions = new java.util.ArrayList<>();
214         actions.add(WSConstants.TS);
215         actions.add(WSConstants.UT);
216 
217         assertFalse(handler.checkResults(results, actions));
218         assertFalse(handler.checkResultsAnyOrder(results, actions));
219     }
220 
221     /**
222      */
223     @Test
224     public void
225     testNoResult() throws Exception {
226         CustomHandler handler = new CustomHandler();
227 
228         java.util.List<WSSecurityEngineResult> results =
229             new java.util.ArrayList<>();
230 
231         java.util.List<Integer> actions = new java.util.ArrayList<>();
232         actions.add(WSConstants.TS);
233 
234         assertFalse(handler.checkResults(results, actions));
235         assertFalse(handler.checkResultsAnyOrder(results, actions));
236     }
237 
238     /**
239      */
240     @Test
241     public void
242     testNoAction() throws Exception {
243         CustomHandler handler = new CustomHandler();
244 
245         java.util.List<WSSecurityEngineResult> results =
246             new java.util.ArrayList<>();
247         results.add(
248             new WSSecurityEngineResult(WSConstants.TS)
249         );
250 
251         java.util.List<Integer> actions = new java.util.ArrayList<>();
252 
253         assertFalse(handler.checkResults(results, actions));
254         assertFalse(handler.checkResultsAnyOrder(results, actions));
255     }
256 
257     /**
258      */
259     @Test
260     public void
261     testMultipleIdenticalResults() throws Exception {
262         CustomHandler handler = new CustomHandler();
263 
264         java.util.List<WSSecurityEngineResult> results =
265             new java.util.ArrayList<>();
266         results.add(
267             new WSSecurityEngineResult(WSConstants.ENCR)
268         );
269         results.add(
270             new WSSecurityEngineResult(WSConstants.UT)
271         );
272         results.add(
273             new WSSecurityEngineResult(WSConstants.ENCR)
274         );
275 
276         java.util.List<Integer> actions = new java.util.ArrayList<>();
277         actions.add(WSConstants.ENCR);
278         actions.add(WSConstants.UT);
279         actions.add(WSConstants.UT);
280 
281         assertFalse(handler.checkResults(results, actions));
282         assertFalse(handler.checkResultsAnyOrder(results, actions));
283     }
284 
285 }