|
22 | 22 |
|
23 | 23 | public class CMMHandlerTest {
|
24 | 24 |
|
25 |
| - private static final CryptoAlgorithm SOME_CRYPTO_ALGORITHM = CryptoAlgorithm.ALG_AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384; |
26 |
| - private static final List<KeyBlob> SOME_EDK_LIST = new ArrayList<>(Collections.singletonList(new KeyBlob())); |
27 |
| - private static final CommitmentPolicy SOME_COMMITMENT_POLICY = CommitmentPolicy.RequireEncryptRequireDecrypt; |
| 25 | + private static final CryptoAlgorithm SOME_CRYPTO_ALGORITHM = |
| 26 | + CryptoAlgorithm.ALG_AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384; |
| 27 | + private static final List<KeyBlob> SOME_EDK_LIST = |
| 28 | + new ArrayList<>(Collections.singletonList(new KeyBlob())); |
| 29 | + private static final CommitmentPolicy SOME_COMMITMENT_POLICY = |
| 30 | + CommitmentPolicy.RequireEncryptRequireDecrypt; |
28 | 31 | private static final Map<String, String> SOME_NON_EMPTY_ENCRYPTION_CONTEXT = new HashMap<>();
|
29 | 32 |
|
30 |
| - static {{ |
31 |
| - SOME_NON_EMPTY_ENCRYPTION_CONTEXT.put("SomeKey", "SomeValue"); |
32 |
| - }} |
| 33 | + static { |
| 34 | + { |
| 35 | + SOME_NON_EMPTY_ENCRYPTION_CONTEXT.put("SomeKey", "SomeValue"); |
| 36 | + } |
| 37 | + } |
33 | 38 |
|
34 | 39 | private static final DecryptionMaterialsRequest SOME_DECRYPTION_MATERIALS_REQUEST_NON_EMPTY_EC =
|
35 |
| - DecryptionMaterialsRequest.newBuilder() |
36 |
| - .setAlgorithm(SOME_CRYPTO_ALGORITHM) |
37 |
| - // Given: Request has some non-empty encryption context |
38 |
| - .setEncryptionContext(SOME_NON_EMPTY_ENCRYPTION_CONTEXT) |
39 |
| - .setReproducedEncryptionContext(new HashMap<>()) |
40 |
| - .setEncryptedDataKeys(SOME_EDK_LIST) |
41 |
| - .build(); |
| 40 | + DecryptionMaterialsRequest.newBuilder() |
| 41 | + .setAlgorithm(SOME_CRYPTO_ALGORITHM) |
| 42 | + // Given: Request has some non-empty encryption context |
| 43 | + .setEncryptionContext(SOME_NON_EMPTY_ENCRYPTION_CONTEXT) |
| 44 | + .setReproducedEncryptionContext(new HashMap<>()) |
| 45 | + .setEncryptedDataKeys(SOME_EDK_LIST) |
| 46 | + .build(); |
42 | 47 |
|
43 | 48 | private static final DecryptionMaterialsRequest SOME_DECRYPTION_MATERIALS_REQUEST_EMPTY_EC =
|
44 |
| - DecryptionMaterialsRequest.newBuilder() |
45 |
| - .setAlgorithm(SOME_CRYPTO_ALGORITHM) |
46 |
| - // Given: Request has empty encryption context |
47 |
| - .setEncryptionContext(new HashMap<>()) |
48 |
| - .setReproducedEncryptionContext(new HashMap<>()) |
49 |
| - .setEncryptedDataKeys(SOME_EDK_LIST) |
50 |
| - .build(); |
| 49 | + DecryptionMaterialsRequest.newBuilder() |
| 50 | + .setAlgorithm(SOME_CRYPTO_ALGORITHM) |
| 51 | + // Given: Request has empty encryption context |
| 52 | + .setEncryptionContext(new HashMap<>()) |
| 53 | + .setReproducedEncryptionContext(new HashMap<>()) |
| 54 | + .setEncryptedDataKeys(SOME_EDK_LIST) |
| 55 | + .build(); |
51 | 56 |
|
52 | 57 | @Test
|
53 |
| - public void GIVEN_CMM_does_not_add_encryption_context_AND_request_has_nonempty_encryption_context_WHEN_decryptMaterials_THEN_output_has_nonempty_encryption_context() { |
| 58 | + public void |
| 59 | + GIVEN_CMM_does_not_add_encryption_context_AND_request_has_nonempty_encryption_context_WHEN_decryptMaterials_THEN_output_has_nonempty_encryption_context() { |
54 | 60 | CryptoMaterialsManager anyNativeCMM = mock(CryptoMaterialsManager.class);
|
55 | 61 |
|
56 | 62 | // Given: native CMM does not set an encryptionContext on returned DecryptionMaterials objects
|
57 |
| - DecryptionMaterials someDecryptionMaterialsWithoutEC = DecryptionMaterials.newBuilder() |
58 |
| - .setDataKey(mock(DataKey.class)) |
59 |
| - .setTrailingSignatureKey(mock(PublicKey.class)) |
60 |
| - .setEncryptionContext(new HashMap<>()).build(); |
| 63 | + DecryptionMaterials someDecryptionMaterialsWithoutEC = |
| 64 | + DecryptionMaterials.newBuilder() |
| 65 | + .setDataKey(mock(DataKey.class)) |
| 66 | + .setTrailingSignatureKey(mock(PublicKey.class)) |
| 67 | + .setEncryptionContext(new HashMap<>()) |
| 68 | + .build(); |
61 | 69 | // Given: request with nonempty encryption context
|
62 | 70 | when(anyNativeCMM.decryptMaterials(SOME_DECRYPTION_MATERIALS_REQUEST_NON_EMPTY_EC))
|
63 |
| - .thenReturn(someDecryptionMaterialsWithoutEC); |
| 71 | + .thenReturn(someDecryptionMaterialsWithoutEC); |
64 | 72 |
|
65 | 73 | // When: decryptMaterials
|
66 | 74 | CMMHandler handlerUnderTest = new CMMHandler(anyNativeCMM);
|
67 |
| - DecryptionMaterialsHandler output = handlerUnderTest.decryptMaterials(SOME_DECRYPTION_MATERIALS_REQUEST_NON_EMPTY_EC, |
68 |
| - SOME_COMMITMENT_POLICY); |
| 75 | + DecryptionMaterialsHandler output = |
| 76 | + handlerUnderTest.decryptMaterials( |
| 77 | + SOME_DECRYPTION_MATERIALS_REQUEST_NON_EMPTY_EC, SOME_COMMITMENT_POLICY); |
69 | 78 |
|
70 | 79 | // Then: output DecryptionMaterialsHandler has encryption context
|
71 | 80 | assertEquals(SOME_NON_EMPTY_ENCRYPTION_CONTEXT, output.getEncryptionContext());
|
72 | 81 | }
|
73 | 82 |
|
74 | 83 | @Test
|
75 |
| - public void GIVEN_CMM_does_not_add_encryption_context_AND_request_has_empty_encryption_context_WHEN_decryptMaterials_THEN_output_has_empty_encryption_context() { |
| 84 | + public void |
| 85 | + GIVEN_CMM_does_not_add_encryption_context_AND_request_has_empty_encryption_context_WHEN_decryptMaterials_THEN_output_has_empty_encryption_context() { |
76 | 86 | CryptoMaterialsManager anyNativeCMM = mock(CryptoMaterialsManager.class);
|
77 | 87 |
|
78 | 88 | // Given: native CMM does not set an encryptionContext on returned DecryptionMaterials objects
|
79 |
| - DecryptionMaterials someDecryptionMaterialsWithoutEC = DecryptionMaterials.newBuilder() |
| 89 | + DecryptionMaterials someDecryptionMaterialsWithoutEC = |
| 90 | + DecryptionMaterials.newBuilder() |
80 | 91 | .setDataKey(mock(DataKey.class))
|
81 | 92 | .setTrailingSignatureKey(mock(PublicKey.class))
|
82 |
| - .setEncryptionContext(new HashMap<>()).build(); |
| 93 | + .setEncryptionContext(new HashMap<>()) |
| 94 | + .build(); |
83 | 95 | // Given: request with empty encryption context
|
84 | 96 | when(anyNativeCMM.decryptMaterials(SOME_DECRYPTION_MATERIALS_REQUEST_EMPTY_EC))
|
85 |
| - .thenReturn(someDecryptionMaterialsWithoutEC); |
| 97 | + .thenReturn(someDecryptionMaterialsWithoutEC); |
86 | 98 |
|
87 | 99 | // When: decryptMaterials
|
88 | 100 | CMMHandler handlerUnderTest = new CMMHandler(anyNativeCMM);
|
89 |
| - DecryptionMaterialsHandler output = handlerUnderTest.decryptMaterials(SOME_DECRYPTION_MATERIALS_REQUEST_EMPTY_EC, |
90 |
| - SOME_COMMITMENT_POLICY); |
| 101 | + DecryptionMaterialsHandler output = |
| 102 | + handlerUnderTest.decryptMaterials( |
| 103 | + SOME_DECRYPTION_MATERIALS_REQUEST_EMPTY_EC, SOME_COMMITMENT_POLICY); |
91 | 104 |
|
92 | 105 | // Then: output DecryptionMaterialsHandler has empty encryption context
|
93 | 106 | assertTrue(output.getEncryptionContext().isEmpty());
|
94 | 107 | }
|
95 | 108 |
|
96 | 109 | @Test
|
97 |
| - public void GIVEN_CMM_adds_encryption_context_AND_request_has_nonempty_encryption_context_WHEN_decryptMaterials_THEN_output_has_nonempty_encryption_context() { |
| 110 | + public void |
| 111 | + GIVEN_CMM_adds_encryption_context_AND_request_has_nonempty_encryption_context_WHEN_decryptMaterials_THEN_output_has_nonempty_encryption_context() { |
98 | 112 | CryptoMaterialsManager anyNativeCMM = mock(CryptoMaterialsManager.class);
|
99 | 113 |
|
100 | 114 | // Given: native CMM sets encryptionContext on returned DecryptionMaterials objects
|
101 |
| - DecryptionMaterials someDecryptionMaterialsWithoutEC = DecryptionMaterials.newBuilder() |
| 115 | + DecryptionMaterials someDecryptionMaterialsWithoutEC = |
| 116 | + DecryptionMaterials.newBuilder() |
102 | 117 | .setDataKey(mock(DataKey.class))
|
103 | 118 | .setTrailingSignatureKey(mock(PublicKey.class))
|
104 |
| - .setEncryptionContext(SOME_NON_EMPTY_ENCRYPTION_CONTEXT).build(); |
| 119 | + .setEncryptionContext(SOME_NON_EMPTY_ENCRYPTION_CONTEXT) |
| 120 | + .build(); |
105 | 121 | // Given: request with nonempty encryption context
|
106 | 122 | when(anyNativeCMM.decryptMaterials(SOME_DECRYPTION_MATERIALS_REQUEST_NON_EMPTY_EC))
|
107 |
| - .thenReturn(someDecryptionMaterialsWithoutEC); |
| 123 | + .thenReturn(someDecryptionMaterialsWithoutEC); |
108 | 124 |
|
109 | 125 | // When: decryptMaterials
|
110 | 126 | CMMHandler handlerUnderTest = new CMMHandler(anyNativeCMM);
|
111 |
| - DecryptionMaterialsHandler output = handlerUnderTest.decryptMaterials(SOME_DECRYPTION_MATERIALS_REQUEST_NON_EMPTY_EC, |
112 |
| - SOME_COMMITMENT_POLICY); |
| 127 | + DecryptionMaterialsHandler output = |
| 128 | + handlerUnderTest.decryptMaterials( |
| 129 | + SOME_DECRYPTION_MATERIALS_REQUEST_NON_EMPTY_EC, SOME_COMMITMENT_POLICY); |
113 | 130 |
|
114 | 131 | // Then: output DecryptionMaterialsHandler has nonempty encryption context
|
115 | 132 | assertEquals(SOME_NON_EMPTY_ENCRYPTION_CONTEXT, output.getEncryptionContext());
|
116 | 133 | }
|
117 | 134 |
|
118 | 135 | @Test
|
119 |
| - public void GIVEN_CMM_adds_encryption_context_AND_request_has_empty_encryption_context_WHEN_decryptMaterials_THEN_output_has_empty_encryption_context() { |
| 136 | + public void |
| 137 | + GIVEN_CMM_adds_encryption_context_AND_request_has_empty_encryption_context_WHEN_decryptMaterials_THEN_output_has_empty_encryption_context() { |
120 | 138 | CryptoMaterialsManager anyNativeCMM = mock(CryptoMaterialsManager.class);
|
121 | 139 |
|
122 | 140 | // Given: native CMM sets encryptionContext on returned DecryptionMaterials objects
|
123 |
| - DecryptionMaterials someDecryptionMaterialsWithoutEC = DecryptionMaterials.newBuilder() |
| 141 | + DecryptionMaterials someDecryptionMaterialsWithoutEC = |
| 142 | + DecryptionMaterials.newBuilder() |
124 | 143 | .setDataKey(mock(DataKey.class))
|
125 | 144 | .setTrailingSignatureKey(mock(PublicKey.class))
|
126 |
| - .setEncryptionContext(new HashMap<>()).build(); |
| 145 | + .setEncryptionContext(new HashMap<>()) |
| 146 | + .build(); |
127 | 147 | // Given: request with empty encryption context
|
128 | 148 | when(anyNativeCMM.decryptMaterials(SOME_DECRYPTION_MATERIALS_REQUEST_EMPTY_EC))
|
129 |
| - .thenReturn(someDecryptionMaterialsWithoutEC); |
| 149 | + .thenReturn(someDecryptionMaterialsWithoutEC); |
130 | 150 |
|
131 | 151 | // When: decryptMaterials
|
132 | 152 | CMMHandler handlerUnderTest = new CMMHandler(anyNativeCMM);
|
133 |
| - DecryptionMaterialsHandler output = handlerUnderTest.decryptMaterials(SOME_DECRYPTION_MATERIALS_REQUEST_EMPTY_EC, |
134 |
| - SOME_COMMITMENT_POLICY); |
| 153 | + DecryptionMaterialsHandler output = |
| 154 | + handlerUnderTest.decryptMaterials( |
| 155 | + SOME_DECRYPTION_MATERIALS_REQUEST_EMPTY_EC, SOME_COMMITMENT_POLICY); |
135 | 156 |
|
136 | 157 | // Then: output DecryptionMaterialsHandler has empty encryption context
|
137 | 158 | assertTrue(output.getEncryptionContext().isEmpty());
|
138 | 159 | }
|
139 |
| - |
140 | 160 | }
|
0 commit comments