| 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 |
|
|
|
|
|
| 70.4% |
Uncovered Elements: 16 (54) |
Complexity: 20 |
Complexity Density: 0.53 |
|
| 16 |
|
public class TestDefaultTrustedApplicationsManager extends TestCase |
| 17 |
|
{ |
| 18 |
|
final CurrentApplication thisApp = new CurrentApplication() |
| 19 |
|
{ |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 20 |
0
|
public EncryptedCertificate encode(String userName)... |
| 21 |
|
{ |
| 22 |
0
|
throw new UnsupportedOperationException(); |
| 23 |
|
} |
| 24 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 25 |
0
|
public String getID()... |
| 26 |
|
{ |
| 27 |
0
|
throw new UnsupportedOperationException(); |
| 28 |
|
} |
| 29 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 30 |
0
|
public PublicKey getPublicKey()... |
| 31 |
|
{ |
| 32 |
0
|
throw new UnsupportedOperationException(); |
| 33 |
|
} |
| 34 |
|
}; |
| 35 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
| 36 |
1
|
public void testSimpleConstructor() throws Exception... |
| 37 |
|
{ |
| 38 |
1
|
final Map appMap = new HashMap(); |
| 39 |
1
|
appMap.put("test", new TrustedApplication() |
| 40 |
|
{ |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 41 |
0
|
public ApplicationCertificate decode(EncryptedCertificate certificate, HttpServletRequest request) throws InvalidCertificateException... |
| 42 |
|
{ |
| 43 |
0
|
throw new UnsupportedOperationException(); |
| 44 |
|
} |
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 46 |
0
|
public String getID()... |
| 47 |
|
{ |
| 48 |
0
|
throw new UnsupportedOperationException(); |
| 49 |
|
} |
| 50 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 51 |
0
|
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 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 64 |
1
|
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 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
| 76 |
1
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
| 89 |
1
|
public void testConstructorEncryptionProvider() throws Exception... |
| 90 |
|
{ |
| 91 |
1
|
final MockKey publicKey = new MockKey(); |
| 92 |
1
|
EncryptionProvider provider = new MockEncryptionProvider() |
| 93 |
|
{ |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 94 |
1
|
public KeyPair generateNewKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException... |
| 95 |
|
{ |
| 96 |
1
|
return new KeyPair(publicKey, new MockKey()); |
| 97 |
|
} |
| 98 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 99 |
1
|
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 |
|
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1
PASS
|
|
| 112 |
1
|
public void testConstructorEncryptionProviderThrowsNoSuchAlgorithmException() throws Exception... |
| 113 |
|
{ |
| 114 |
1
|
EncryptionProvider provider = new MockEncryptionProvider() |
| 115 |
|
{ |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 116 |
1
|
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 |
|
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1
PASS
|
|
| 131 |
1
|
public void testConstructorEncryptionProviderThrowsNoSuchProviderException() throws Exception... |
| 132 |
|
{ |
| 133 |
1
|
EncryptionProvider provider = new MockEncryptionProvider() |
| 134 |
|
{ |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 135 |
1
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 7 |
Complexity Density: 1 |
|
| 151 |
|
class MockEncryptionProvider implements EncryptionProvider |
| 152 |
|
{ |
| 153 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 154 |
0
|
public EncryptedCertificate createEncryptedCertificate(String userName, PrivateKey privateKey, String appId)... |
| 155 |
|
{ |
| 156 |
0
|
throw new UnsupportedOperationException(); |
| 157 |
|
} |
| 158 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 159 |
0
|
public ApplicationCertificate decodeEncryptedCertificate(EncryptedCertificate encCert, PublicKey publicKey, String appId) throws InvalidCertificateException... |
| 160 |
|
{ |
| 161 |
0
|
throw new UnsupportedOperationException(); |
| 162 |
|
} |
| 163 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 164 |
0
|
public KeyPair generateNewKeyPair() throws NoSuchAlgorithmException, NoSuchProviderException... |
| 165 |
|
{ |
| 166 |
0
|
throw new UnsupportedOperationException(); |
| 167 |
|
} |
| 168 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 169 |
0
|
public String generateUID()... |
| 170 |
|
{ |
| 171 |
0
|
throw new UnsupportedOperationException(); |
| 172 |
|
} |
| 173 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 174 |
0
|
public Application getApplicationCertificate(String baseUrl)... |
| 175 |
|
{ |
| 176 |
0
|
throw new UnsupportedOperationException(); |
| 177 |
|
} |
| 178 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 179 |
0
|
public PrivateKey toPrivateKey(byte[] encodedForm) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException... |
| 180 |
|
{ |
| 181 |
0
|
throw new UnsupportedOperationException(); |
| 182 |
|
} |
| 183 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 184 |
0
|
public PublicKey toPublicKey(byte[] encodedForm) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException... |
| 185 |
|
{ |
| 186 |
0
|
throw new UnsupportedOperationException(); |
| 187 |
|
} |
| 188 |
|
} |