View Javadoc

1   /*
2    * $Id: PGPSecurityProviderTestCase.java 20310 2010-11-24 10:40:35Z esteban.robles $
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 java.io.FileInputStream;
16  import java.net.URL;
17  
18  import org.apache.commons.io.IOUtils;
19  
20  public class PGPSecurityProviderTestCase extends AbstractEncryptionStrategyTestCase
21  {
22      private PGPSecurityProvider securityProvider;
23      private Message message;
24  
25      @Override
26      protected void doSetUp() throws Exception
27      {
28          super.doSetUp();
29  
30          securityProvider = new PGPSecurityProvider();
31          securityProvider.setKeyManager(keyManager);
32          securityProvider.initialise();
33  
34          URL url = Thread.currentThread().getContextClassLoader().getResource("./signed.asc");
35          FileInputStream in = new FileInputStream(url.getFile());
36  
37          message = MessageFactory.getMessage(IOUtils.toByteArray(in));
38      }
39  
40      @Override
41      protected void doTearDown() throws Exception
42      {
43          securityProvider = null;
44          message = null;
45          super.doTearDown();
46      }
47  
48      public void testAuthenticate() throws Exception
49      {
50          Authentication auth = new PGPAuthentication("Mule client <mule_client@mule.com>", message);
51          auth = securityProvider.authenticate(auth);
52          assertTrue(auth.isAuthenticated());
53      }
54  }