View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.pgp;
8   
9   import org.mule.api.security.Authentication;
10  
11  import java.io.FileInputStream;
12  import java.net.URL;
13  
14  import org.apache.commons.io.IOUtils;
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertTrue;
18  
19  public class PGPSecurityProviderTestCase extends AbstractEncryptionStrategyTestCase
20  {
21      private PGPSecurityProvider securityProvider;
22      private Message message;
23  
24      @Override
25      protected void doSetUp() throws Exception
26      {
27          super.doSetUp();
28  
29          securityProvider = new PGPSecurityProvider();
30          securityProvider.setKeyManager(keyManager);
31          securityProvider.initialise();
32  
33          URL url = Thread.currentThread().getContextClassLoader().getResource("./signed.asc");
34          FileInputStream in = new FileInputStream(url.getFile());
35  
36          message = MessageFactory.getMessage(IOUtils.toByteArray(in));
37      }
38  
39      @Override
40      protected void doTearDown() throws Exception
41      {
42          securityProvider = null;
43          message = null;
44          super.doTearDown();
45      }
46  
47      @Test
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  }