View Javadoc
1   package civitas.bboard.common;
2   
3   import static org.junit.jupiter.api.Assertions.assertFalse;
4   import static org.junit.jupiter.api.Assertions.assertTrue;
5   import static org.mockito.Mockito.verify;
6   
7   import org.bouncycastle.crypto.CryptoException;
8   import org.junit.jupiter.api.DisplayName;
9   import org.junit.jupiter.api.Test;
10  import org.mockito.InjectMocks;
11  
12  import civitas.common.RandomAwareTestBase;
13  import civitas.common.electoralroll.ElectoralRollCapabilitySharesTestData;
14  import civitas.crypto.rsapublickey.PublicKeyTestData;
15  
16  class VerifyBBPostTest extends RandomAwareTestBase
17  		implements BBPostTestData, ElectoralRollCapabilitySharesTestData, PublicKeyTestData {
18  
19  	@InjectMocks
20  	VerifyBBPost verifyBBPost;
21  
22  	@Test
23  	@DisplayName("verifies if the signature matches the xml form of the message. returns true if it does"
24  			+ "- converts the message to xml" + "- computes the hash of the xml"
25  			+ "- verifies that the signature is the signature of the hash using the key")
26  	void test() throws CryptoException {
27  		assertTrue(verifyBBPost.apply(BBPOST));
28  		verify(verifyBBPost.cryptoHash).apply(ELECTORAL_ROLL_CAPABILITY_SHARES_XML.getBytes());
29  		verify(verifyBBPost.verifyPublicKeySignature).apply(BBPOST.sig, ELECTORAL_ROLL_CAPABILITY_SHARES_XML_HASH);
30  	}
31  
32  	@Test
33  	@DisplayName("if the signature does not verify, returns false")
34  	void test1() throws CryptoException {
35  		assertFalse(verifyBBPost.apply(BBPOST_BAD_SIG));
36  	}
37  }