1   /*
2    * $Id: PGPSecurityFilterTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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              // ignore
55          }
56      }
57  }