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.message;
21
22 import org.apache.ws.security.WSSConfig;
23 import org.apache.ws.security.WSSecurityException;
24 import org.apache.ws.security.common.SOAPUtil;
25 import org.apache.ws.security.components.crypto.CryptoFactory;
26 import org.w3c.dom.Document;
27
28
29
30
31
32
33 public class CertErrorTest extends org.junit.Assert {
34
35 public CertErrorTest() {
36 WSSConfig.init();
37 }
38
39
40
41
42 @org.junit.Test
43 public void testX509Signature() throws Exception {
44 WSSecSignature builder = new WSSecSignature();
45 builder.setUserInfo("bob", "security");
46 Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
47 WSSecHeader secHeader = new WSSecHeader();
48 secHeader.insertSecurityHeader(doc);
49 try {
50 builder.build(doc, CryptoFactory.getInstance(), secHeader);
51 fail("Expected failure on a bad username");
52 } catch (WSSecurityException ex) {
53 String expectedError = "No certificates for user bob were found for signature";
54 assertTrue(ex.getMessage().indexOf(expectedError) != -1);
55 }
56 }
57
58
59
60
61 @org.junit.Test
62 public void testEncryption() throws Exception {
63 WSSecEncrypt builder = new WSSecEncrypt();
64 builder.setUserInfo("alice");
65 Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG);
66 WSSecHeader secHeader = new WSSecHeader();
67 secHeader.insertSecurityHeader(doc);
68 try {
69 builder.build(doc, CryptoFactory.getInstance(), secHeader);
70 fail("Expected failure on a bad username");
71 } catch (WSSecurityException ex) {
72 String expectedError = "No certificates for user alice were found for encryption";
73 assertTrue(ex.getMessage().indexOf(expectedError) != -1);
74 }
75 }
76
77 }