1
2
3
4
5
6
7
8
9
10
11 package org.mule.extras.pgp;
12
13 import org.mule.extras.client.MuleClient;
14 import org.mule.tck.FunctionalTestCase;
15 import org.mule.umo.security.UnauthorisedException;
16 import org.mule.util.FileUtils;
17
18 import java.io.FileInputStream;
19 import java.net.URL;
20
21 public class PGPSecurityFilterTestCase extends FunctionalTestCase
22 {
23
24 protected String getConfigResources()
25 {
26 return "test-pgp-encrypt-config.xml";
27 }
28
29 public void testAuthenticationAuthorised() throws Exception
30 {
31 URL url = Thread.currentThread().getContextClassLoader().getResource("./encrypted-signed.asc");
32
33 int length = (int) FileUtils.newFile(url.getFile()).length();
34 byte[] msg = new byte[length];
35
36 FileInputStream in = new FileInputStream(url.getFile());
37 in.read(msg);
38 in.close();
39
40 MuleClient client = new MuleClient();
41 client.send("vm://echo", new String(msg), null);
42 }
43
44 public void testAuthenticationNotAuthorised() throws Exception
45 {
46 try
47 {
48 MuleClient client = new MuleClient();
49 client.send("vm://echo", new String("An unsigned message"), null);
50 fail("The request is not signed");
51 }
52 catch (UnauthorisedException e)
53 {
54
55 }
56 }
57 }