Skip to content

Commit bf9ff09

Browse files
committed
Feedback
1 parent 08dc841 commit bf9ff09

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

src/main/java/com/uid2/admin/store/writer/SaltSerializer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.uid2.shared.model.SaltEntry;
44

55
public class SaltSerializer {
6+
private SaltSerializer() {}
7+
68
public static String toCsv(SaltEntry[] entries) {
79
StringBuilder stringBuilder = new StringBuilder();
810

src/test/java/com/uid2/admin/store/writer/EncryptedSaltStoreWriterTest.java

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.InputStream;
2828
import java.nio.file.Files;
2929
import java.nio.file.Paths;
30+
import java.time.Duration;
3031
import java.time.Instant;
3132
import java.util.*;
3233

@@ -39,6 +40,10 @@
3940
@MockitoSettings(strictness = Strictness.LENIENT)
4041
public class EncryptedSaltStoreWriterTest {
4142
private static final Integer SITE_ID = 1;
43+
private final Instant feb26 = Instant.parse("2025-02-26T22:12:18Z");
44+
private final Instant feb27 = Instant.parse("2025-02-27T22:14:36Z");
45+
private final Instant mar23 = Instant.parse("2025-03-23T14:52:08Z");
46+
private final Instant mar25 = Instant.parse("2025-03-25T14:52:08Z");
4247

4348
@Mock
4449
private FileManager fileManager;
@@ -84,20 +89,22 @@ public void setup() throws Exception {
8489

8590
@Test
8691
public void testUploadNew() throws Exception {
87-
RotatingSaltProvider.SaltSnapshot snapshot = makeSnapshot(
88-
Instant.ofEpochMilli(1740607938167L),
89-
Instant.ofEpochMilli(Instant.now().toEpochMilli() + 90002),
92+
RotatingSaltProvider.SaltSnapshot olderSnapshot = makeSnapshot(
93+
feb26,
94+
Instant.now().plus(Duration.ofSeconds(90)),
9095
100
91-
); // Older snapshot
92-
RotatingSaltProvider.SaltSnapshot snapshot2 = makeSnapshot(
93-
Instant.ofEpochMilli(1740694476392L),
94-
Instant.ofEpochMilli(Instant.now().toEpochMilli() + 130000),
96+
);
97+
98+
RotatingSaltProvider.SaltSnapshot activeSnapshot = makeSnapshot(
99+
feb27,
100+
Instant.now().plus(Duration.ofMinutes(2)),
95101
10
96-
); // Newer active snapshot
102+
);
103+
97104

98105
JsonObject metadata = new JsonObject()
99-
.put("version", 1742770328863L)
100-
.put("generated", 1742770328)
106+
.put("version", mar23.toEpochMilli())
107+
.put("generated", mar23.getEpochSecond())
101108
.put("first_level", "FIRST-LEVEL")
102109
.put("id_prefix", "a")
103110
.put("id_secret", "ID-SECRET");
@@ -113,7 +120,7 @@ public void testUploadNew() throws Exception {
113120
EncryptedSaltStoreWriter encryptedSaltStoreWriter = new EncryptedSaltStoreWriter(config, rotatingSaltProvider,
114121
fileManager, taggableCloudStorage, versionGenerator, storeScope, rotatingCloudEncryptionKeyProvider, SITE_ID);
115122

116-
encryptedSaltStoreWriter.upload(List.of(snapshot,snapshot2), metadata);
123+
encryptedSaltStoreWriter.upload(List.of(olderSnapshot,activeSnapshot), metadata);
117124
verify(fileManager).uploadMetadata(metadataCaptor.capture(), nameCaptor.capture(), locationCaptor.capture());
118125

119126
// Capture the metadata
@@ -124,13 +131,23 @@ public void testUploadNew() throws Exception {
124131
assertEquals(capturedMetadata.getString("id_prefix"), metadata.getValue("id_prefix"));
125132
verify(taggableCloudStorage,times(2)).upload(pathCaptor.capture(), cloudPathCaptor.capture(), any());
126133

127-
assertWrittenFileEquals(pathCaptor.getValue(), snapshot2);
134+
assertWrittenFileEquals(pathCaptor.getValue(), activeSnapshot);
128135
}
129136

130137
@Test
131138
public void testUnencryptedAndEncryptedBehavesTheSame() throws Exception {
132-
RotatingSaltProvider.SaltSnapshot snapshot = makeSnapshot(Instant.ofEpochMilli(1740607938167L), Instant.ofEpochMilli(Instant.now().toEpochMilli() + 90000), 100);
133-
RotatingSaltProvider.SaltSnapshot snapshot2 = makeSnapshot(Instant.ofEpochMilli(1740694476392L), Instant.ofEpochMilli(Instant.now().toEpochMilli() + 130000), 10);
139+
RotatingSaltProvider.SaltSnapshot snapshot = makeSnapshot(
140+
feb26,
141+
Instant.now().plus(Duration.ofSeconds(90)),
142+
100
143+
);
144+
145+
RotatingSaltProvider.SaltSnapshot snapshot2 = makeSnapshot(
146+
feb27,
147+
Instant.now().plus(Duration.ofMinutes(2)),
148+
10
149+
);
150+
134151
List<RotatingSaltProvider.SaltSnapshot> snapshots = List.of(snapshot, snapshot2);
135152

136153
when(rotatingSaltProvider.getMetadata()).thenThrow(new CloudStorageException("The specified key does not exist: AmazonS3Exception: test-core-bucket"));
@@ -153,16 +170,20 @@ public void testUnencryptedAndEncryptedBehavesTheSame() throws Exception {
153170
JsonArray saltsArray = capturedMetadata.getJsonArray("salts");
154171
assertEquals(1, saltsArray.size(), "Salts array should have exactly one entry, as other is removed in newest-effective logic");
155172
JsonObject salt = saltsArray.getJsonObject(0);
156-
assertEquals(1740694476392L, salt.getLong("effective"), "Effective timestamp should match second entry");
173+
assertEquals(
174+
feb27.toEpochMilli(),
175+
salt.getLong("effective"),
176+
"Effective timestamp should match second entry"
177+
);
157178
assertEquals(10, salt.getInteger("size"), "Size should match second entries");
158179

159180
//Now sending snapshot2 to encrypted to verify that does the same.
160181
EncryptedSaltStoreWriter encryptedSaltStoreWriter = new EncryptedSaltStoreWriter(config, rotatingSaltProvider,
161182
fileManager, taggableCloudStorage, versionGenerator, storeScope, rotatingCloudEncryptionKeyProvider, SITE_ID);
162183

163184
JsonObject metadata = new JsonObject()
164-
.put("version", 1742770328863L)
165-
.put("generated", 1742770328)
185+
.put("version", mar25.toEpochMilli())
186+
.put("generated", mar25.getEpochSecond())
166187
.put("first_level", "FIRST-LEVEL")
167188
.put("id_prefix", "a")
168189
.put("id_secret", "ID-SECRET");
@@ -176,7 +197,11 @@ public void testUnencryptedAndEncryptedBehavesTheSame() throws Exception {
176197
saltsArray = capturedMetadata.getJsonArray("salts");
177198
salt = saltsArray.getJsonObject(0);
178199
assertEquals(1, key_id);
179-
assertEquals(1740694476392L, salt.getLong("effective"), "Effective timestamp should match second entry");
200+
assertEquals(
201+
feb27.toEpochMilli(),
202+
salt.getLong("effective"),
203+
"Effective timestamp should match second entry"
204+
);
180205
assertEquals(10, salt.getInteger("size"), "Size should match second entries");
181206
verify(taggableCloudStorage,atLeastOnce()).upload(pathCaptor.capture(), cloudPathCaptor.capture(), any());
182207
}

0 commit comments

Comments
 (0)