1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }