View Javadoc
1   package civitas.common.mix.revelation;
2   
3   import static org.junit.jupiter.api.Assertions.assertTrue;
4   
5   import org.junit.jupiter.api.DisplayName;
6   import org.junit.jupiter.api.Test;
7   import org.mockito.InjectMocks;
8   
9   import civitas.common.RandomAwareTestBase;
10  import civitas.common.mix.capabilitymix.CapabilityMixTestData;
11  import civitas.crypto.ciphertext.ElGamalCiphertextTestData;
12  import civitas.crypto.publickey.ElGamalPublicKeyTestData;
13  
14  class VerifyMixRevelationTest extends RandomAwareTestBase
15  		implements ElGamalPublicKeyTestData, CapabilityMixTestData, ElGamalCiphertextTestData, MixRevelationTestData {
16  
17  	@InjectMocks
18  	VerifyMixRevelation verifyMixRevelation;
19  
20  	@Test
21  	@DisplayName("verifies the mix revelation. For each revelations\n"
22  			+ "- checks that the commitment is the hash of the mapping and the nonce"
23  			+ "- checks that the revelation verifies")
24  	void test() {
25  
26  		assertTrue(verifyMixRevelation.apply(
27  				MIX_REVELATION,
28  				EL_GAMAL_PUBLIC_KEY_EPRIME,
29  				CAPABILITY_MIX_INITIAL,
30  				CAPABILITY_MIX_LEFT,
31  				CAPABILITY_MIX_RIGHT,
32  				MIX_REVELATION_DIRECTIONS));
33  	}
34  
35  	@Test
36  	@DisplayName("fails if verifyMixElementRevelation fails")
37  	void test1() {
38  		verifyMixRevelation.apply(
39  				MIX_REVELATION,
40  				EL_GAMAL_PUBLIC_KEY_E,
41  				CAPABILITY_MIX_INITIAL,
42  				CAPABILITY_MIX_LEFT,
43  				CAPABILITY_MIX_RIGHT,
44  				MIX_REVELATION_DIRECTIONS);
45  	}
46  
47  	@Test
48  	@DisplayName("fails if the hashes do not match")
49  	void test2() {
50  		// hash nonequal
51  		verifyMixRevelation.apply(
52  				MIX_REVELATION,
53  				EL_GAMAL_PUBLIC_KEY_E,
54  				CAPABILITY_MIX_INITIAL,
55  				CAPABILITY_MIX_RIGHT,
56  				CAPABILITY_MIX_LEFT,
57  				MIX_REVELATION_DIRECTIONS);
58  	}
59  
60  	@Test
61  	@DisplayName("fails if a revelation is null")
62  	void test3() {
63  		verifyMixRevelation.apply(
64  				MIX_REVELATION_WITH_NULL_REVELATION,
65  				EL_GAMAL_PUBLIC_KEY_E,
66  				CAPABILITY_MIX_INITIAL,
67  				CAPABILITY_MIX_RIGHT,
68  				CAPABILITY_MIX_LEFT,
69  				MIX_REVELATION_DIRECTIONS);
70  	}
71  
72  	@Test
73  	@DisplayName("fails if the indicator in a revelation does not match the corresponding direction")
74  	void test4() {
75  		verifyMixRevelation.apply(
76  				MIX_REVELATION,
77  				EL_GAMAL_PUBLIC_KEY_E,
78  				CAPABILITY_MIX_INITIAL,
79  				CAPABILITY_MIX_RIGHT,
80  				CAPABILITY_MIX_LEFT,
81  				MIX_REVELATION_DIRECTIONS_BAD);
82  	}
83  
84  	@Test
85  	@DisplayName("fails if the length of indicators in the revelation does not match the length of relevations there")
86  	void test5() {
87  		verifyMixRevelation.apply(
88  				MIX_REVELATION_WITH_BAD_INDICATOR_LENGTH,
89  				EL_GAMAL_PUBLIC_KEY_EPRIME,
90  				CAPABILITY_MIX_INITIAL,
91  				CAPABILITY_MIX_LEFT,
92  				CAPABILITY_MIX_RIGHT,
93  				MIX_REVELATION_DIRECTIONS);
94  	}
95  
96  	@Test
97  	@DisplayName("fails if the length of indicators in the revelation does not match the length of directions")
98  	void test6() {
99  		verifyMixRevelation.apply(
100 				MIX_REVELATION,
101 				EL_GAMAL_PUBLIC_KEY_EPRIME,
102 				CAPABILITY_MIX_INITIAL,
103 				CAPABILITY_MIX_LEFT,
104 				CAPABILITY_MIX_RIGHT,
105 				MIX_REVELATION_DIRECTIONS_SHORT);
106 	}
107 
108 	@Test
109 	@DisplayName("fails if directions is null")
110 	void test7() {
111 		verifyMixRevelation.apply(
112 				MIX_REVELATION,
113 				EL_GAMAL_PUBLIC_KEY_EPRIME,
114 				CAPABILITY_MIX_INITIAL,
115 				CAPABILITY_MIX_LEFT,
116 				CAPABILITY_MIX_RIGHT,
117 				null);
118 	}
119 }