1 package civitas.common.capabilityencryption;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.junit.jupiter.api.Assertions.assertThrows;
5 import static org.mockito.Mockito.verify;
6
7 import org.junit.jupiter.api.DisplayName;
8 import org.junit.jupiter.api.Test;
9 import org.mockito.InjectMocks;
10
11 import civitas.common.RandomAwareTestBase;
12 import civitas.common.votersubmission.VoterSubmissionTestData;
13
14 class EncryptCapabilityTest extends RandomAwareTestBase implements VoterSubmissionTestData {
15
16 @InjectMocks
17 EncryptCapability encryptCapability;
18
19 @Test
20 @DisplayName(
21 """
22 creates an encrypted capability
23 - generates a reencrypt factor
24 - encrypts the capability associated with the context using the key and the reencrypt factor
25 """)
26 void test() {
27 assertEquals(
28 ENCRYPT_CAPABILITY_RESULT, encryptCapability.apply(EL_GAMAL_PUBLIC_KEY_E, CAPABILITY_MAP, CONTEXT_0));
29 verify(encryptCapability.generateElGamalReencryptFactor).apply(EL_GAMAL_PARAMETERS);
30 verify(encryptCapability.elGamalEncrypt)
31 .apply(EL_GAMAL_PUBLIC_KEY_E, VOTE_CAPABILITIES.getFirst(), ELGAMAL_REENCRYPT_FACTOR_EPRIME);
32 }
33
34 @Test
35 @DisplayName(
36 "if the capability map misses any needed capability for the vote," + "IllegalArgumentException is thrown")
37 void test4() {
38
39 assertThrows(
40 IllegalArgumentException.class,
41 () -> encryptCapability.apply(EL_GAMAL_PUBLIC_KEY_E, CAPABILITY_MAP, SOMESTRING));
42 }
43 }