1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.signer.internal.factory

File DefaultSignerFactoryTest.java

 

Code metrics

0
11
9
1
140
97
9
0.82
1.22
9
1

Classes

Class Line # Actions
DefaultSignerFactoryTest 47 11 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 7 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Unit tests for {@link DefaultSignerFactory}.
39    *
40    * @version $Id: b9aaf9c3258bd4ed87d3cafd8d37b9944c55dd21 $
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})
 
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   
 
83  7 toggle @Before
84    public void configure() throws Exception
85    {
86  7 factory = mocker.getComponentUnderTest();
87  7 setupTest(mocker);
88    }
89   
 
90  7 toggle 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   
 
99  1 toggle @Test
100    public void testPssSignatureVerification() throws Exception
101    {
102  1 runTest(mockerPss);
103    }
104   
 
105  1 toggle @Test
106    public void testSha1SignatureVerification() throws Exception
107    {
108  1 runTest(mockerSha1);
109    }
110   
 
111  1 toggle @Test
112    public void testSha224SignatureVerification() throws Exception
113    {
114  1 runTest(mockerSha224);
115    }
116   
 
117  1 toggle @Test
118    public void testSha256SignatureVerification() throws Exception
119    {
120  1 runTest(mockerSha256);
121    }
122   
 
123  1 toggle @Test
124    public void testSha384SignatureVerification() throws Exception
125    {
126  1 runTest(mockerSha384);
127    }
128   
 
129  1 toggle @Test
130    public void testSha512SignatureVerification() throws Exception
131    {
132  1 runTest(mockerSha512);
133    }
134   
 
135  1 toggle @Test
136    public void testMd5SignatureVerification() throws Exception
137    {
138  1 runTest(mockerMD5);
139    }
140    }