1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.ws.security.misc;
21
22 import org.apache.ws.security.WSSecurityEngine;
23 import org.apache.ws.security.WSSecurityException;
24 import org.apache.ws.security.common.SOAPUtil;
25 import org.w3c.dom.Document;
26
27
28
29
30 public class SecurityHeaderTest extends org.junit.Assert {
31 private static final String DUPLICATE_NULL_ACTOR_MSG =
32 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
33 + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "
34 + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
35 + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
36 + "<SOAP-ENV:Header>"
37 + "<wsse:Security SOAP-ENV:mustUnderstand=\"1\" "
38 + "xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
39 + "</wsse:Security>"
40 + "<wsse:Security SOAP-ENV:mustUnderstand=\"1\" "
41 + "xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
42 + "</wsse:Security>"
43 + "</SOAP-ENV:Header>"
44 + "<SOAP-ENV:Body>"
45 + "<add xmlns=\"http://ws.apache.org/counter/counter_port_type\">"
46 + "<value xmlns=\"\">15</value>" + "</add>"
47 + "</SOAP-ENV:Body>\r\n \r\n" + "</SOAP-ENV:Envelope>";
48 private static final String DUPLICATE_ACTOR_MSG =
49 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
50 + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "
51 + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
52 + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
53 + "<SOAP-ENV:Header>"
54 + "<wsse:Security SOAP-ENV:actor=\"user\" SOAP-ENV:mustUnderstand=\"1\" "
55 + "xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
56 + "</wsse:Security>"
57 + "<wsse:Security SOAP-ENV:actor=\"user\" SOAP-ENV:mustUnderstand=\"1\" "
58 + "xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
59 + "</wsse:Security>"
60 + "</SOAP-ENV:Header>"
61 + "<SOAP-ENV:Body>"
62 + "<add xmlns=\"http://ws.apache.org/counter/counter_port_type\">"
63 + "<value xmlns=\"\">15</value>" + "</add>"
64 + "</SOAP-ENV:Body>\r\n \r\n" + "</SOAP-ENV:Envelope>";
65 private static final String TWO_ACTOR_MSG =
66 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
67 + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "
68 + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
69 + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
70 + "<SOAP-ENV:Header>"
71 + "<wsse:Security SOAP-ENV:mustUnderstand=\"1\" "
72 + "xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
73 + "</wsse:Security>"
74 + "<wsse:Security SOAP-ENV:actor=\"user\" SOAP-ENV:mustUnderstand=\"1\" "
75 + "xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
76 + "</wsse:Security>"
77 + "</SOAP-ENV:Header>"
78 + "<SOAP-ENV:Body>"
79 + "<add xmlns=\"http://ws.apache.org/counter/counter_port_type\">"
80 + "<value xmlns=\"\">15</value>" + "</add>"
81 + "</SOAP-ENV:Body>\r\n \r\n" + "</SOAP-ENV:Envelope>";
82
83 private WSSecurityEngine secEngine = new WSSecurityEngine();
84
85
86
87
88 @org.junit.Test
89 public void testDuplicateNullActor() throws Exception {
90 Document doc = SOAPUtil.toSOAPPart(DUPLICATE_NULL_ACTOR_MSG);
91 try {
92 secEngine.processSecurityHeader(doc, null, null, null);
93 fail("Failure expected on a null actor");
94 } catch (WSSecurityException ex) {
95
96 }
97 }
98
99
100
101
102 @org.junit.Test
103 public void testDuplicateActor() throws Exception {
104 Document doc = SOAPUtil.toSOAPPart(DUPLICATE_ACTOR_MSG);
105 try {
106 secEngine.processSecurityHeader(doc, "user", null, null);
107 fail("Failure expected on a duplicate actor");
108 } catch (WSSecurityException ex) {
109
110 }
111 }
112
113
114
115
116 @org.junit.Test
117 public void testTwoActors() throws Exception {
118 Document doc = SOAPUtil.toSOAPPart(TWO_ACTOR_MSG);
119 secEngine.processSecurityHeader(doc, null, null, null);
120
121 secEngine.processSecurityHeader(doc, "user", null, null);
122 }
123 }