View Javadoc

1   /*
2    * $Id: PGPSecurityProviderTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.module.pgp;
12  
13  import org.mule.api.security.Authentication;
14  
15  import cryptix.message.Message;
16  import cryptix.message.MessageFactory;
17  
18  import java.io.FileInputStream;
19  import java.net.URL;
20  
21  public class PGPSecurityProviderTestCase extends AbstractEncryptionStrategyTestCase
22  {
23      private PGPSecurityProvider securityProvider;
24      private Message message;
25  
26      @Override
27      protected void doSetUp() throws Exception
28      {
29          super.doSetUp();
30  
31          securityProvider = new PGPSecurityProvider();
32          securityProvider.setKeyManager(keyManager);
33          securityProvider.initialise();
34  
35          MessageFactory mf = MessageFactory.getInstance("OpenPGP");
36  
37          URL url = Thread.currentThread().getContextClassLoader().getResource("./signed.asc");
38          FileInputStream in = new FileInputStream(url.getFile());
39  
40          message = (Message)mf.generateMessages(in).iterator().next();
41      }
42  
43      @Override
44      protected void doTearDown() throws Exception
45      {
46          securityProvider = null;
47          message = null;
48          super.doTearDown();
49      }
50  
51      public void testAuthenticate() throws Exception
52      {
53          Authentication auth = new PGPAuthentication("Mule client <mule_client@mule.com>", message);
54          auth = securityProvider.authenticate(auth);
55          assertTrue(auth.isAuthenticated());
56      }
57  }