View Javadoc

1   /*
2    * $Id: PGPSecurityProviderTestCase.java 22387 2011-07-12 03:53:36Z dirk.olmes $
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  import org.junit.Test;
20  
21  import static org.junit.Assert.assertTrue;
22  
23  public class PGPSecurityProviderTestCase extends AbstractEncryptionStrategyTestCase
24  {
25      private PGPSecurityProvider securityProvider;
26      private Message message;
27  
28      @Override
29      protected void doSetUp() throws Exception
30      {
31          super.doSetUp();
32  
33          securityProvider = new PGPSecurityProvider();
34          securityProvider.setKeyManager(keyManager);
35          securityProvider.initialise();
36  
37          URL url = Thread.currentThread().getContextClassLoader().getResource("./signed.asc");
38          FileInputStream in = new FileInputStream(url.getFile());
39  
40          message = MessageFactory.getMessage(IOUtils.toByteArray(in));
41      }
42  
43      @Override
44      protected void doTearDown() throws Exception
45      {
46          securityProvider = null;
47          message = null;
48          super.doTearDown();
49      }
50  
51      @Test
52      public void testAuthenticate() throws Exception
53      {
54          Authentication auth = new PGPAuthentication("Mule client <mule_client@mule.com>", message);
55          auth = securityProvider.authenticate(auth);
56          assertTrue(auth.isAuthenticated());
57      }
58  }