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

File BcDigestWithRsaSignerFactoryTest.java

 

Code metrics

0
8
8
1
127
73
8
1
1
8
1

Classes

Class Line # Actions
BcDigestWithRsaSignerFactoryTest 52 8 0% 8 0
1.0100%
 

Contributing tests

This file is covered by 6 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    /*
23    * See the NOTICE file distributed with this work for additional
24    * information regarding copyright ownership.
25    *
26    * This is free software; you can redistribute it and/or modify it
27    * under the terms of the GNU Lesser General Public License as
28    * published by the Free Software Foundation; either version 2.1 of
29    * the License, or (at your option) any later version.
30    *
31    * This software is distributed in the hope that it will be useful,
32    * but WITHOUT ANY WARRANTY; without even the implied warranty of
33    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34    * Lesser General Public License for more details.
35    *
36    * You should have received a copy of the GNU Lesser General Public
37    * License along with this software; if not, write to the Free
38    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
39    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
40    */
41   
42    import org.junit.Before;
43    import org.junit.Rule;
44    import org.junit.Test;
45    import org.xwiki.crypto.internal.asymmetric.keyfactory.BcRSAKeyFactory;
46    import org.xwiki.crypto.internal.encoder.Base64BinaryStringEncoder;
47    import org.xwiki.crypto.signer.SignerFactory;
48    import org.xwiki.test.annotation.ComponentList;
49    import org.xwiki.test.mockito.MockitoComponentMockingRule;
50   
51    @ComponentList({Base64BinaryStringEncoder.class, BcRSAKeyFactory.class})
 
52    public class BcDigestWithRsaSignerFactoryTest extends AbstractRsaSignerFactoryTest
53    {
54    @Rule
55    public final MockitoComponentMockingRule<SignerFactory> mocker =
56    new MockitoComponentMockingRule<SignerFactory>(BcSHA1withRsaSignerFactory.class);
57   
58    @Rule
59    public final MockitoComponentMockingRule<SignerFactory> mockerSha224 =
60    new MockitoComponentMockingRule<SignerFactory>(BcSHA224withRsaSignerFactory.class);
61   
62    @Rule
63    public final MockitoComponentMockingRule<SignerFactory> mockerSha256 =
64    new MockitoComponentMockingRule<SignerFactory>(BcSHA256withRsaSignerFactory.class);
65   
66    @Rule
67    public final MockitoComponentMockingRule<SignerFactory> mockerSha384 =
68    new MockitoComponentMockingRule<SignerFactory>(BcSHA384withRsaSignerFactory.class);
69   
70    @Rule
71    public final MockitoComponentMockingRule<SignerFactory> mockerSha512 =
72    new MockitoComponentMockingRule<SignerFactory>(BcSHA512withRsaSignerFactory.class);
73   
74    @Rule
75    public final MockitoComponentMockingRule<SignerFactory> mockerMD5 =
76    new MockitoComponentMockingRule<SignerFactory>(BcMD5withRsaSignerFactory.class);
77   
 
78  6 toggle @Before
79    public void configure() throws Exception
80    {
81  6 setupTest(mocker);
82    }
83   
 
84  6 toggle private void runTest(MockitoComponentMockingRule<SignerFactory> mocker) throws Exception
85    {
86  6 runTestSignatureVerification(
87    mocker.getComponentUnderTest().getInstance(true, privateKey),
88    mocker.getComponentUnderTest().getInstance(false, publicKey)
89    );
90    }
91   
 
92  1 toggle @Test
93    public void testSha1SignatureVerification() throws Exception
94    {
95  1 runTest(mocker);
96    }
97   
 
98  1 toggle @Test
99    public void testSha224SignatureVerification() throws Exception
100    {
101  1 runTest(mockerSha224);
102    }
103   
 
104  1 toggle @Test
105    public void testSha256SignatureVerification() throws Exception
106    {
107  1 runTest(mockerSha256);
108    }
109   
 
110  1 toggle @Test
111    public void testSha384SignatureVerification() throws Exception
112    {
113  1 runTest(mockerSha384);
114    }
115   
 
116  1 toggle @Test
117    public void testSha512SignatureVerification() throws Exception
118    {
119  1 runTest(mockerSha512);
120    }
121   
 
122  1 toggle @Test
123    public void testMd5SignatureVerification() throws Exception
124    {
125  1 runTest(mockerMD5);
126    }
127    }