Skip to content

Commit d0c3857

Browse files
committed
Remove code only used in its own test
1 parent 31bd637 commit d0c3857

File tree

5 files changed

+5
-210
lines changed

5 files changed

+5
-210
lines changed

src/main/java/com/uid2/admin/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.uid2.admin.managers.KeysetManager;
1717
import com.uid2.admin.cloudEncryption.CloudSecretGenerator;
1818
import com.uid2.admin.monitoring.DataStoreMetrics;
19-
import com.uid2.admin.managers.CloudEncryptionKeyManager;
19+
import com.uid2.admin.cloudEncryption.CloudEncryptionKeyManager;
2020
import com.uid2.admin.secret.*;
2121
import com.uid2.admin.store.*;
2222
import com.uid2.admin.store.reader.RotatingAdminKeysetStore;

src/main/java/com/uid2/admin/managers/CloudEncryptionKeyManager.java renamed to src/main/java/com/uid2/admin/cloudEncryption/CloudEncryptionKeyManager.java

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
package com.uid2.admin.managers;
1+
package com.uid2.admin.cloudEncryption;
22

3-
import com.uid2.admin.cloudEncryption.CloudSecretGenerator;
43
import com.uid2.admin.store.writer.CloudEncryptionKeyStoreWriter;
54
import com.uid2.shared.auth.OperatorKey;
65
import com.uid2.shared.model.CloudEncryptionKey;
76
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider;
87
import org.slf4j.Logger;
98
import org.slf4j.LoggerFactory;
109

11-
import java.util.List;
12-
import java.util.Optional;
13-
import java.util.stream.Collectors;
14-
1510
import java.time.Instant;
1611
import java.util.*;
1712

@@ -107,49 +102,6 @@ int getNextKeyId() {
107102
return cloudEncryptionKeys.keySet().stream().max(Integer::compareTo).orElse(0) + 1;
108103
}
109104

110-
// Used in test only
111-
// Creates and uploads a CloudEncryptionKey that activates immediately for a specific sites, for emergency rotation
112-
CloudEncryptionKey createAndAddImmediateCloudEncryptionKey(int siteId) throws Exception {
113-
int newKeyId = getNextKeyId();
114-
long created = Instant.now().getEpochSecond();
115-
CloudEncryptionKey newKey = new CloudEncryptionKey(newKeyId, siteId, created, created, secretGenerator.generate());
116-
addCloudEncryptionKey(newKey);
117-
return newKey;
118-
}
119-
120-
// Used in test only
121-
CloudEncryptionKey getCloudEncryptionKeyByKeyIdentifier(int keyIdentifier) {
122-
return RotatingCloudEncryptionKeyProvider.getAll().get(keyIdentifier);
123-
}
124-
125-
// Used in test only
126-
Optional<CloudEncryptionKey> getCloudEncryptionKeyBySiteId(int siteId) {
127-
return RotatingCloudEncryptionKeyProvider.getAll().values().stream()
128-
.filter(key -> key.getSiteId() == siteId)
129-
.findFirst();
130-
}
131-
132-
// Used in test only
133-
List<CloudEncryptionKey> getAllCloudEncryptionKeysBySiteId(int siteId) {
134-
return RotatingCloudEncryptionKeyProvider.getAll().values().stream()
135-
.filter(key -> key.getSiteId() == siteId)
136-
.collect(Collectors.toList());
137-
}
138-
139-
// Used in test only
140-
Map<Integer, CloudEncryptionKey> getAllCloudEncryptionKeys() {
141-
return RotatingCloudEncryptionKeyProvider.getAll();
142-
}
143-
144-
// Used in test only
145-
boolean doesSiteHaveKeys(int siteId) {
146-
Map<Integer, CloudEncryptionKey> allKeys = RotatingCloudEncryptionKeyProvider.getAll();
147-
if (allKeys == null) {
148-
return false;
149-
}
150-
return allKeys.values().stream().anyMatch(key -> key.getSiteId() == siteId);
151-
}
152-
153105
int countKeysForSite(int siteId) {
154106
Map<Integer, CloudEncryptionKey> allKeys = RotatingCloudEncryptionKeyProvider.getAll();
155107
return (int) allKeys.values().stream().filter(key -> key.getSiteId() == siteId).count();

src/main/java/com/uid2/admin/vertx/service/OperatorKeyService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.fasterxml.jackson.databind.ObjectWriter;
44
import com.uid2.admin.auth.AdminAuthMiddleware;
55
import com.uid2.admin.auth.RevealedKey;
6-
import com.uid2.admin.managers.CloudEncryptionKeyManager;
6+
import com.uid2.admin.cloudEncryption.CloudEncryptionKeyManager;
77
import com.uid2.shared.model.Site;
88
import com.uid2.shared.secret.IKeyGenerator;
99
import com.uid2.admin.store.writer.OperatorKeyStoreWriter;

src/test/java/com/uid2/admin/managers/CloudEncryptionKeyManagerTest.java renamed to src/test/java/com/uid2/admin/cloudEncryption/CloudEncryptionKeyManagerTest.java

Lines changed: 1 addition & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package com.uid2.admin.managers;
1+
package com.uid2.admin.cloudEncryption;
22

3-
import com.uid2.admin.cloudEncryption.CloudSecretGenerator;
43
import com.uid2.admin.store.writer.CloudEncryptionKeyStoreWriter;
54
import com.uid2.shared.auth.OperatorKey;
65
import com.uid2.shared.model.CloudEncryptionKey;
@@ -99,33 +98,6 @@ void testGetNextKeyId() {
9998
assertEquals(2, nextKeyId);
10099
}
101100

102-
@Test
103-
void testGetCloudEncryptionKey() {
104-
CloudEncryptionKey cloudEncryptionKey = new CloudEncryptionKey(1, siteId, 500L, 1500L, "existingSecret1");
105-
Map<Integer, CloudEncryptionKey> existingKeys = new HashMap<>();
106-
existingKeys.put(1, cloudEncryptionKey);
107-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(existingKeys);
108-
109-
CloudEncryptionKey result = cloudEncryptionKeyManager.getCloudEncryptionKeyByKeyIdentifier(1);
110-
111-
assertEquals(cloudEncryptionKey, result);
112-
}
113-
114-
@Test
115-
void testGetAllCloudEncryptionKeys() {
116-
Map<Integer, CloudEncryptionKey> existingKeys = new HashMap<>();
117-
CloudEncryptionKey existingKey1 = new CloudEncryptionKey(1, siteId, 500L, 1500L, "existingSecret1");
118-
CloudEncryptionKey existingKey2 = new CloudEncryptionKey(2, siteId, 600L, 1600L, "existingSecret2");
119-
existingKeys.put(1, existingKey1);
120-
existingKeys.put(2, existingKey2);
121-
122-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(existingKeys);
123-
124-
Map<Integer, CloudEncryptionKey> result = cloudEncryptionKeyManager.getAllCloudEncryptionKeys();
125-
126-
assertEquals(existingKeys, result);
127-
}
128-
129101
@Test
130102
void testAddCloudEncryptionKey() throws Exception {
131103
CloudEncryptionKey cloudEncryptionKey = new CloudEncryptionKey(1, siteId, 1000L, 2000L, "randomKeyString");
@@ -143,135 +115,6 @@ void testAddCloudEncryptionKey() throws Exception {
143115
assertEquals(cloudEncryptionKey, capturedKeys.get(1));
144116
}
145117

146-
@Test
147-
void testGetCloudEncryptionKeyBySiteId() {
148-
CloudEncryptionKey key1 = new CloudEncryptionKey(1, 100, 0, 0, "secret1");
149-
CloudEncryptionKey key2 = new CloudEncryptionKey(2, 200, 0, 0, "secret2");
150-
Map<Integer, CloudEncryptionKey> keys = new HashMap<>();
151-
keys.put(1, key1);
152-
keys.put(2, key2);
153-
154-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(keys);
155-
156-
Optional<CloudEncryptionKey> result = cloudEncryptionKeyManager.getCloudEncryptionKeyBySiteId(100);
157-
assertTrue(result.isPresent());
158-
assertEquals(key1, result.get());
159-
}
160-
161-
@Test
162-
void testGetAllCloudEncryptionKeysBySiteId() {
163-
CloudEncryptionKey key1 = new CloudEncryptionKey(1, 100, 0, 0, "secret1");
164-
CloudEncryptionKey key2 = new CloudEncryptionKey(2, 100, 0, 0, "secret2");
165-
CloudEncryptionKey key3 = new CloudEncryptionKey(3, 200, 0, 0, "secret3");
166-
Map<Integer, CloudEncryptionKey> keys = new HashMap<>();
167-
keys.put(1, key1);
168-
keys.put(2, key2);
169-
keys.put(3, key3);
170-
171-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(keys);
172-
173-
List<CloudEncryptionKey> result = cloudEncryptionKeyManager.getAllCloudEncryptionKeysBySiteId(100);
174-
assertEquals(2, result.size());
175-
assertTrue(result.contains(key1));
176-
assertTrue(result.contains(key2));
177-
}
178-
179-
@Test
180-
void testCreateAndAddImmediateCloudEncryptionKey() throws Exception {
181-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(new HashMap<>());
182-
when(keyGenerator.generate()).thenReturn("generatedSecret");
183-
184-
CloudEncryptionKey newKey = cloudEncryptionKeyManager.createAndAddImmediateCloudEncryptionKey(100);
185-
186-
assertNotNull(newKey);
187-
assertEquals(100, newKey.getSiteId());
188-
assertEquals("generatedSecret", newKey.getSecret());
189-
190-
verify(cloudEncryptionKeyStoreWriter, times(1)).upload(any(Map.class), eq(null));
191-
}
192-
193-
@Test
194-
public void testDoesSiteHaveKeys_SiteHasKeys() {
195-
CloudEncryptionKey cloudEncryptionKey = new CloudEncryptionKey(siteId, siteId, 0L, 0L, "key");
196-
Map<Integer, CloudEncryptionKey> allKeys = new HashMap<>();
197-
allKeys.put(1, cloudEncryptionKey);
198-
199-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(allKeys);
200-
201-
boolean result = cloudEncryptionKeyManager.doesSiteHaveKeys(siteId);
202-
assertTrue(result);
203-
}
204-
205-
@Test
206-
public void testDoesSiteHaveKeys_SiteDoesNotHaveKeys() {
207-
Map<Integer, CloudEncryptionKey> allKeys = new HashMap<>();
208-
209-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(allKeys);
210-
211-
boolean result = cloudEncryptionKeyManager.doesSiteHaveKeys(siteId);
212-
assertFalse(result);
213-
}
214-
215-
@Test
216-
public void testDoesSiteHaveKeys_AllKeysNull() {
217-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(null);
218-
219-
boolean result = cloudEncryptionKeyManager.doesSiteHaveKeys(siteId);
220-
assertFalse(result);
221-
}
222-
223-
@Test
224-
public void testDoesSiteHaveKeys_MultipleKeysDifferentSiteIds() {
225-
CloudEncryptionKey cloudEncryptionKey1 = new CloudEncryptionKey(1, 1, 0L, 0L, "key1");
226-
CloudEncryptionKey cloudEncryptionKey2 = new CloudEncryptionKey(2, 2, 0L, 0L, "key2");
227-
Map<Integer, CloudEncryptionKey> allKeys = new HashMap<>();
228-
allKeys.put(1, cloudEncryptionKey1);
229-
allKeys.put(2, cloudEncryptionKey2);
230-
231-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(allKeys);
232-
233-
assertTrue(cloudEncryptionKeyManager.doesSiteHaveKeys(1));
234-
assertTrue(cloudEncryptionKeyManager.doesSiteHaveKeys(2));
235-
assertFalse(cloudEncryptionKeyManager.doesSiteHaveKeys(3)); // Site ID 3 does not exist
236-
}
237-
238-
@Test
239-
public void testDoesSiteHaveKeys_SameSiteIdMultipleKeys() {
240-
CloudEncryptionKey cloudEncryptionKey1 = new CloudEncryptionKey(siteId, siteId, 0L, 0L, "key1");
241-
CloudEncryptionKey cloudEncryptionKey2 = new CloudEncryptionKey(siteId, siteId, 0L, 0L, "key2");
242-
Map<Integer, CloudEncryptionKey> allKeys = new HashMap<>();
243-
allKeys.put(1, cloudEncryptionKey1);
244-
allKeys.put(2, cloudEncryptionKey2);
245-
246-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(allKeys);
247-
248-
boolean result = cloudEncryptionKeyManager.doesSiteHaveKeys(siteId);
249-
assertTrue(result);
250-
}
251-
252-
@Test
253-
public void testDoesSiteHaveKeys_LargeNumberOfKeys() {
254-
Map<Integer, CloudEncryptionKey> allKeys = new HashMap<>();
255-
for (int i = 1; i <= 1000; i++) {
256-
CloudEncryptionKey cloudEncryptionKey = new CloudEncryptionKey(i, i, 0L, 0L, "key" + i);
257-
allKeys.put(i, cloudEncryptionKey);
258-
}
259-
260-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(allKeys);
261-
262-
for (int i = 1; i <= 1000; i++) {
263-
assertTrue(cloudEncryptionKeyManager.doesSiteHaveKeys(i));
264-
}
265-
assertFalse(cloudEncryptionKeyManager.doesSiteHaveKeys(1001)); // Site ID 1001 does not exist
266-
}
267-
268-
@Test
269-
public void testDoesSiteHaveKeys_EmptyKeys() {
270-
when(cloudEncryptionKeyProvider.getAll()).thenReturn(new HashMap<>());
271-
272-
assertFalse(cloudEncryptionKeyManager.doesSiteHaveKeys(1));
273-
}
274-
275118
@Test
276119
void testCountKeysForSite() {
277120
Map<Integer, CloudEncryptionKey> testKeys = new HashMap<>();

src/test/java/com/uid2/admin/vertx/OperatorKeyServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.fasterxml.jackson.core.type.TypeReference;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.uid2.admin.auth.RevealedKey;
6-
import com.uid2.admin.managers.CloudEncryptionKeyManager;
6+
import com.uid2.admin.cloudEncryption.CloudEncryptionKeyManager;
77
import com.uid2.admin.vertx.service.IService;
88
import com.uid2.admin.vertx.service.OperatorKeyService;
99
import com.uid2.admin.vertx.test.ServiceTestBase;

0 commit comments

Comments
 (0)