1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.signer.internal.factory; |
21 |
|
|
22 |
|
import org.junit.Before; |
23 |
|
import org.junit.Rule; |
24 |
|
import org.junit.Test; |
25 |
|
import org.xwiki.crypto.internal.asymmetric.keyfactory.BcRSAKeyFactory; |
26 |
|
import org.xwiki.crypto.internal.digest.factory.BcSHA1DigestFactory; |
27 |
|
import org.xwiki.crypto.internal.digest.factory.BcSHA224DigestFactory; |
28 |
|
import org.xwiki.crypto.internal.digest.factory.BcSHA256DigestFactory; |
29 |
|
import org.xwiki.crypto.internal.digest.factory.BcSHA384DigestFactory; |
30 |
|
import org.xwiki.crypto.internal.digest.factory.BcSHA512DigestFactory; |
31 |
|
import org.xwiki.crypto.internal.encoder.Base64BinaryStringEncoder; |
32 |
|
import org.xwiki.crypto.signer.Signer; |
33 |
|
import org.xwiki.crypto.signer.SignerFactory; |
34 |
|
import org.xwiki.test.annotation.ComponentList; |
35 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
36 |
|
|
37 |
|
|
38 |
|
@link |
39 |
|
|
40 |
|
@version |
41 |
|
|
42 |
|
@ComponentList({Base64BinaryStringEncoder.class, BcRSAKeyFactory.class, BcSHA1DigestFactory.class, |
43 |
|
BcSHA224DigestFactory.class, BcSHA256DigestFactory.class, BcSHA384DigestFactory.class, |
44 |
|
BcSHA512DigestFactory.class, BcSHA1withRsaSignerFactory.class, BcSHA224withRsaSignerFactory.class, |
45 |
|
BcSHA256withRsaSignerFactory.class, BcSHA384withRsaSignerFactory.class, BcSHA512withRsaSignerFactory.class, |
46 |
|
BcRsaSsaPssSignerFactory.class, BcMD5withRsaSignerFactory.class}) |
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 9 |
Complexity Density: 0.82 |
|
47 |
|
public class DefaultSignerFactoryTest extends AbstractRsaSignerFactoryTest |
48 |
|
{ |
49 |
|
@Rule |
50 |
|
public final MockitoComponentMockingRule<SignerFactory> mocker = |
51 |
|
new MockitoComponentMockingRule<SignerFactory>(DefaultSignerFactory.class); |
52 |
|
|
53 |
|
@Rule |
54 |
|
public final MockitoComponentMockingRule<SignerFactory> mockerPss = |
55 |
|
new MockitoComponentMockingRule<SignerFactory>(BcRsaSsaPssSignerFactory.class); |
56 |
|
|
57 |
|
@Rule |
58 |
|
public final MockitoComponentMockingRule<SignerFactory> mockerSha1 = |
59 |
|
new MockitoComponentMockingRule<SignerFactory>(BcSHA1withRsaSignerFactory.class); |
60 |
|
|
61 |
|
@Rule |
62 |
|
public final MockitoComponentMockingRule<SignerFactory> mockerSha224 = |
63 |
|
new MockitoComponentMockingRule<SignerFactory>(BcSHA224withRsaSignerFactory.class); |
64 |
|
|
65 |
|
@Rule |
66 |
|
public final MockitoComponentMockingRule<SignerFactory> mockerSha256 = |
67 |
|
new MockitoComponentMockingRule<SignerFactory>(BcSHA256withRsaSignerFactory.class); |
68 |
|
|
69 |
|
@Rule |
70 |
|
public final MockitoComponentMockingRule<SignerFactory> mockerSha384 = |
71 |
|
new MockitoComponentMockingRule<SignerFactory>(BcSHA384withRsaSignerFactory.class); |
72 |
|
|
73 |
|
@Rule |
74 |
|
public final MockitoComponentMockingRule<SignerFactory> mockerSha512 = |
75 |
|
new MockitoComponentMockingRule<SignerFactory>(BcSHA512withRsaSignerFactory.class); |
76 |
|
|
77 |
|
@Rule |
78 |
|
public final MockitoComponentMockingRule<SignerFactory> mockerMD5 = |
79 |
|
new MockitoComponentMockingRule<SignerFactory>(BcMD5withRsaSignerFactory.class); |
80 |
|
|
81 |
|
private SignerFactory factory; |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
83 |
7 |
@Before... |
84 |
|
public void configure() throws Exception |
85 |
|
{ |
86 |
7 |
factory = mocker.getComponentUnderTest(); |
87 |
7 |
setupTest(mocker); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
90 |
7 |
private void runTest(MockitoComponentMockingRule<SignerFactory> mocker) throws Exception... |
91 |
|
{ |
92 |
7 |
Signer signer = mocker.getComponentUnderTest().getInstance(true, privateKey); |
93 |
7 |
runTestSignatureVerification( |
94 |
|
signer, |
95 |
|
factory.getInstance(false, publicKey, signer.getEncoded()) |
96 |
|
); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
99 |
1 |
@Test... |
100 |
|
public void testPssSignatureVerification() throws Exception |
101 |
|
{ |
102 |
1 |
runTest(mockerPss); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
105 |
1 |
@Test... |
106 |
|
public void testSha1SignatureVerification() throws Exception |
107 |
|
{ |
108 |
1 |
runTest(mockerSha1); |
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
111 |
1 |
@Test... |
112 |
|
public void testSha224SignatureVerification() throws Exception |
113 |
|
{ |
114 |
1 |
runTest(mockerSha224); |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
117 |
1 |
@Test... |
118 |
|
public void testSha256SignatureVerification() throws Exception |
119 |
|
{ |
120 |
1 |
runTest(mockerSha256); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
123 |
1 |
@Test... |
124 |
|
public void testSha384SignatureVerification() throws Exception |
125 |
|
{ |
126 |
1 |
runTest(mockerSha384); |
127 |
|
} |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
129 |
1 |
@Test... |
130 |
|
public void testSha512SignatureVerification() throws Exception |
131 |
|
{ |
132 |
1 |
runTest(mockerSha512); |
133 |
|
} |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
135 |
1 |
@Test... |
136 |
|
public void testMd5SignatureVerification() throws Exception |
137 |
|
{ |
138 |
1 |
runTest(mockerMD5); |
139 |
|
} |
140 |
|
} |