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.EncryptionStrategy;
10  import org.mule.api.security.SecurityManager;
11  import org.mule.api.security.SecurityProvider;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  
14  import org.junit.Test;
15  
16  import static org.junit.Assert.assertNotNull;
17  import static org.junit.Assert.assertTrue;
18  
19  public class PgpNamespaceHandlerTestCase extends FunctionalTestCase
20  {
21  
22      @Override
23      protected String getConfigResources()
24      {
25          return "pgp-namespace-config.xml";
26      }
27  
28      @Test
29      public void testPgpProvider()
30      {
31          knownProperties(getProvider("pgpSecurityProvider"));
32      }
33      
34      @Test
35      public void testKeyBasedEncryptionStrategy()
36      {
37          knownProperties(getEncryptionStrategy("keyBasedEncryptionStrategy"));
38      }
39  
40      protected SecurityProvider getProvider(String name)
41      {
42          SecurityManager securityManager = muleContext.getSecurityManager();
43          return securityManager.getProvider(name);
44      }
45  
46      protected void knownProperties(SecurityProvider provider)
47      {
48          assertNotNull(provider);
49          assertTrue(provider instanceof PGPSecurityProvider);
50          PGPSecurityProvider pgpProvider = (PGPSecurityProvider) provider;
51          assertNotNull(pgpProvider.getKeyManager());
52          assertTrue(pgpProvider.getKeyManager() instanceof PGPKeyRingImpl);
53      }
54      
55      protected EncryptionStrategy getEncryptionStrategy(String name)
56      {
57          SecurityManager securityManager = muleContext.getSecurityManager();
58          return securityManager.getEncryptionStrategy(name);
59      }
60      
61      protected void knownProperties(EncryptionStrategy encryptionStrategy)
62      {
63          assertNotNull(encryptionStrategy);
64          assertTrue(encryptionStrategy instanceof KeyBasedEncryptionStrategy);
65          KeyBasedEncryptionStrategy keyBased = (KeyBasedEncryptionStrategy) encryptionStrategy;
66          assertNotNull(keyBased.getKeyManager());
67          assertTrue(keyBased.getKeyManager() instanceof PGPKeyRingImpl);
68      }
69  
70  }