Clover Coverage Report - Atlassian Trusted Apps(Aggregated)
Coverage timestamp: Tue Jun 9 2009 19:34:44 CDT
45   188   27   1.96
0   162   0.6   11.5
23     1.17  
2    
 
 
  TestDefaultTrustedApplicationsManager       Line # 16 38 20 70.4% 0.7037037
  MockEncryptionProvider       Line # 151 7 7 0% 0.0
 
  (6)
 
1    package com.atlassian.security.auth.trustedapps;
2   
3    import java.security.KeyPair;
4    import java.security.NoSuchAlgorithmException;
5    import java.security.NoSuchProviderException;
6    import java.security.PrivateKey;
7    import java.security.PublicKey;
8    import java.security.spec.InvalidKeySpecException;
9    import java.util.HashMap;
10    import java.util.Map;
11   
12    import javax.servlet.http.HttpServletRequest;
13   
14    import junit.framework.TestCase;
15   
 
16    public class TestDefaultTrustedApplicationsManager extends TestCase
17    {
18    final CurrentApplication thisApp = new CurrentApplication()
19    {
 
20  0 toggle public EncryptedCertificate encode(String userName)
21    {
22  0 throw new UnsupportedOperationException();
23    }
24   
 
25  0 toggle public String getID()
26    {
27  0 throw new UnsupportedOperationException();
28    }
29   
 
30  0 toggle public PublicKey getPublicKey()
31    {
32  0 throw new UnsupportedOperationException();
33    }
34    };
35   
 
36  1 toggle public void testSimpleConstructor() throws Exception
37    {
38  1 final Map appMap = new HashMap();
39  1 appMap.put("test", new TrustedApplication()
40    {
 
41  0 toggle public ApplicationCertificate decode(EncryptedCertificate certificate, HttpServletRequest request) throws InvalidCertificateException
42    {
43  0 throw new UnsupportedOperationException();
44    }
45   
 
46  0 toggle public String getID()
47    {
48  0 throw new UnsupportedOperationException();
49    }
50   
 
51  0 toggle public PublicKey getPublicKey()
52    {
53  0 throw new UnsupportedOperationException();
54    };
55    });
56  1 TrustedApplicationsManager manager = new DefaultTrustedApplicationsManager(thisApp, appMap);
57   
58  1 assertNotNull(manager.getCurrentApplication());
59  1 assertSame(thisApp, manager.getCurrentApplication());
60  1 assertNull(manager.getTrustedApplication("something"));
61  1 assertNotNull(manager.getTrustedApplication("test"));
62    }
63   
 
64  1 toggle public void testSimpleConstructorNullApp() throws Exception
65    {
66  1 try
67    {
68  1 new DefaultTrustedApplicationsManager(null, new HashMap());
69  0 fail("Should have thrown ex");
70    }
71    catch (IllegalArgumentException yay)
72    {
73    }
74    }
75   
 
76  1 toggle public void testSimpleConstructorNullMap() throws Exception
77    {
78   
79  1 try
80    {
81  1 new DefaultTrustedApplicationsManager(thisApp, null);
82  0 fail("Should have thrown ex");
83    }
84    catch (IllegalArgumentException yay)
85    {
86    }
87    }
88   
 
89  1 toggle public void testConstructorEncryptionProvider() throws Exception
90    {
91  1 final MockKey publicKey = new MockKey();
92  1 EncryptionProvider provider = new MockEncryptionProvider()
93    {
 
94  1 toggle public KeyPair generateNewKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException
95    {
96  1 return new KeyPair(publicKey, new MockKey());
97    }
98   
 
99  1 toggle public String generateUID()
100    {
101  1 return "this-is-a-uid";
102    }
103    };
104   
105  1 final TrustedApplicationsManager manager = new DefaultTrustedApplicationsManager(provider);
106  1 assertNotNull(manager.getCurrentApplication());
107  1 assertNotNull(manager.getCurrentApplication().getID());
108  1 assertNotNull(manager.getCurrentApplication().getPublicKey());
109  1 assertSame(publicKey, manager.getCurrentApplication().getPublicKey());
110    }
111   
 
112  1 toggle public void testConstructorEncryptionProviderThrowsNoSuchAlgorithmException() throws Exception
113    {
114  1 EncryptionProvider provider = new MockEncryptionProvider()
115    {
 
116  1 toggle public KeyPair generateNewKeyPair() throws NoSuchAlgorithmException
117    {
118  1 throw new NoSuchAlgorithmException("some-algorithm");
119    }
120    };
121  1 try
122    {
123  1 new DefaultTrustedApplicationsManager(provider);
124  0 fail("error expected");
125    }
126    catch (Error expected)
127    {
128    }
129    }
130   
 
131  1 toggle public void testConstructorEncryptionProviderThrowsNoSuchProviderException() throws Exception
132    {
133  1 EncryptionProvider provider = new MockEncryptionProvider()
134    {
 
135  1 toggle public KeyPair generateNewKeyPair() throws NoSuchProviderException
136    {
137  1 throw new NoSuchProviderException("some-algorithm");
138    }
139    };
140  1 try
141    {
142  1 new DefaultTrustedApplicationsManager(provider);
143  0 fail("error expected");
144    }
145    catch (Error expected)
146    {
147    }
148    }
149    }
150   
 
151    class MockEncryptionProvider implements EncryptionProvider
152    {
153   
 
154  0 toggle public EncryptedCertificate createEncryptedCertificate(String userName, PrivateKey privateKey, String appId)
155    {
156  0 throw new UnsupportedOperationException();
157    }
158   
 
159  0 toggle public ApplicationCertificate decodeEncryptedCertificate(EncryptedCertificate encCert, PublicKey publicKey, String appId) throws InvalidCertificateException
160    {
161  0 throw new UnsupportedOperationException();
162    }
163   
 
164  0 toggle public KeyPair generateNewKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException
165    {
166  0 throw new UnsupportedOperationException();
167    }
168   
 
169  0 toggle public String generateUID()
170    {
171  0 throw new UnsupportedOperationException();
172    }
173   
 
174  0 toggle public Application getApplicationCertificate(String baseUrl)
175    {
176  0 throw new UnsupportedOperationException();
177    }
178   
 
179  0 toggle public PrivateKey toPrivateKey(byte[] encodedForm) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
180    {
181  0 throw new UnsupportedOperationException();
182    }
183   
 
184  0 toggle public PublicKey toPublicKey(byte[] encodedForm) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
185    {
186  0 throw new UnsupportedOperationException();
187    }
188    }