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.util;
21  
22  import java.util.List;
23  
24  import org.apache.wss4j.common.ConfigurationConstants;
25  import org.apache.wss4j.dom.WSConstants;
26  import org.apache.wss4j.dom.engine.WSSConfig;
27  import org.apache.wss4j.dom.handler.HandlerAction;
28  import org.junit.jupiter.api.Test;
29  
30  import static org.junit.jupiter.api.Assertions.assertEquals;
31  
32  
33  public class WSSecurityUtilTest {
34  
35      @Test
36      public void testNewEncryptionAction() throws Exception {
37          String action = ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.ENCRYPTION;
38          List<Integer> decodeActions = WSSecurityUtil.decodeAction(action);
39          assertEquals(2, decodeActions.size());
40          assertEquals(WSConstants.SIGN, decodeActions.get(0));
41          assertEquals(WSConstants.ENCR, decodeActions.get(1));
42      }
43  
44      @Test
45      public void testNewEncryptionHandlerAction() throws Exception {
46          String action = ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.ENCRYPTION;
47          List<HandlerAction> decodeActions = WSSecurityUtil.decodeHandlerAction(action, WSSConfig.getNewInstance());
48          assertEquals(2, decodeActions.size());
49          assertEquals(WSConstants.SIGN, decodeActions.get(0).getAction());
50          assertEquals(WSConstants.ENCR, decodeActions.get(1).getAction());
51      }
52  
53      @Test
54      public void testDeprecatedEncryptionAction() throws Exception {
55          String action = ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.ENCRYPT;
56          List<Integer> decodeActions = WSSecurityUtil.decodeAction(action);
57          assertEquals(2, decodeActions.size());
58          assertEquals(WSConstants.SIGN, decodeActions.get(0));
59          assertEquals(WSConstants.ENCR, decodeActions.get(1));
60      }
61  
62      @Test
63      public void testDeprecatedEncryptionHandlerAction() throws Exception {
64          String action = ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.ENCRYPT;
65          List<HandlerAction> decodeActions = WSSecurityUtil.decodeHandlerAction(action, WSSConfig.getNewInstance());
66          assertEquals(2, decodeActions.size());
67          assertEquals(WSConstants.SIGN, decodeActions.get(0).getAction());
68          assertEquals(WSConstants.ENCR, decodeActions.get(1).getAction());
69      }
70  
71      @Test
72      public void testNewEncryptionDerivedAction() throws Exception {
73          String action = ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.ENCRYPTION_DERIVED;
74          List<Integer> decodeActions = WSSecurityUtil.decodeAction(action);
75          assertEquals(2, decodeActions.size());
76          assertEquals(WSConstants.SIGN, decodeActions.get(0));
77          assertEquals(WSConstants.DKT_ENCR, decodeActions.get(1));
78      }
79  
80      @Test
81      public void testNewEncryptionHandlerDerivedAction() throws Exception {
82          String action = ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.ENCRYPTION_DERIVED;
83          List<HandlerAction> decodeActions = WSSecurityUtil.decodeHandlerAction(action, WSSConfig.getNewInstance());
84          assertEquals(2, decodeActions.size());
85          assertEquals(WSConstants.SIGN, decodeActions.get(0).getAction());
86          assertEquals(WSConstants.DKT_ENCR, decodeActions.get(1).getAction());
87      }
88  
89      @Test
90      public void testDeprecatedEncryptionDerivedAction() throws Exception {
91          String action = ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.ENCRYPT_DERIVED;
92          List<Integer> decodeActions = WSSecurityUtil.decodeAction(action);
93          assertEquals(2, decodeActions.size());
94          assertEquals(WSConstants.SIGN, decodeActions.get(0));
95          assertEquals(WSConstants.DKT_ENCR, decodeActions.get(1));
96      }
97  
98      @Test
99      public void testDeprecatedEncryptionHandlerDerivedAction() throws Exception {
100         String action = ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.ENCRYPT_DERIVED;
101         List<HandlerAction> decodeActions = WSSecurityUtil.decodeHandlerAction(action, WSSConfig.getNewInstance());
102         assertEquals(2, decodeActions.size());
103         assertEquals(WSConstants.SIGN, decodeActions.get(0).getAction());
104         assertEquals(WSConstants.DKT_ENCR, decodeActions.get(1).getAction());
105     }
106 }