Skip to content

Commit 17e9d56

Browse files
Add/update tests
1 parent 433bce0 commit 17e9d56

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ private void verifyFile(String filelocation, RotatingSaltProvider.SaltSnapshot s
111111
public void testUploadNew() throws Exception {
112112
RotatingSaltProvider.SaltSnapshot snapshot = makeSnapshot(Instant.ofEpochMilli(1740607938167L), Instant.ofEpochMilli(Instant.now().toEpochMilli() + 90002), 100);
113113
RotatingSaltProvider.SaltSnapshot snapshot2 = makeSnapshot(Instant.ofEpochMilli(1740694476392L), Instant.ofEpochMilli(Instant.now().toEpochMilli() + 130000), 10);
114+
JsonObject metadata = new JsonObject()
115+
.put("version", 1742770328863L)
116+
.put("generated", 1742770328)
117+
.put("first_level", "FIRST-LEVEL")
118+
.put("id_prefix", "a")
119+
.put("id_secret", "ID-SECRET");
114120
when(rotatingSaltProvider.getMetadata()).thenThrow(new CloudStorageException("The specified key does not exist: AmazonS3Exception: test-core-bucket"));
115121
when(rotatingSaltProvider.getSnapshots()).thenReturn(null);
116122

@@ -123,18 +129,21 @@ public void testUploadNew() throws Exception {
123129
EncryptedSaltStoreWriter encryptedSaltStoreWriter = new EncryptedSaltStoreWriter(config, rotatingSaltProvider,
124130
fileManager, taggableCloudStorage, versionGenerator, storeScope, rotatingCloudEncryptionKeyProvider, siteId);
125131

126-
encryptedSaltStoreWriter.upload(snapshot);
132+
encryptedSaltStoreWriter.upload(List.of(snapshot), metadata);
127133
verify(fileManager).uploadMetadata(metadataCaptor.capture(), nameCaptor.capture(), locationCaptor.capture());
128134

129135
// Capture the metadata
130136
JsonObject capturedMetadata = metadataCaptor.getValue();
137+
131138
assertEquals(1, capturedMetadata.getJsonArray("salts").size(), "The 'salts' array should contain exactly 1 item");
132-
encryptedSaltStoreWriter.upload(snapshot2);
139+
encryptedSaltStoreWriter.upload(List.of(snapshot2), metadata);
133140

134141
verify(fileManager,times(2)).uploadMetadata(metadataCaptor.capture(), nameCaptor.capture(), locationCaptor.capture());
135142
capturedMetadata = metadataCaptor.getValue();
136-
assertEquals(2, capturedMetadata.getJsonArray("salts").size(), "The 'salts' array should contain 2 items");
137143

144+
assertEquals(2, capturedMetadata.getJsonArray("salts").size(), "The 'salts' array should contain 2 items");
145+
assertEquals(capturedMetadata.getString("first_level"), metadata.getValue("first_level"));
146+
assertEquals(capturedMetadata.getString("id_prefix"), metadata.getValue("id_prefix"));
138147
verify(taggableCloudStorage,times(3)).upload(pathCaptor.capture(), cloudPathCaptor.capture(), any());
139148

140149
verifyFile(pathCaptor.getValue(), snapshot);
@@ -171,7 +180,14 @@ public void testUnencryptedAndEncryptedBehavesTheSame() throws Exception {
171180
EncryptedSaltStoreWriter encryptedSaltStoreWriter = new EncryptedSaltStoreWriter(config, rotatingSaltProvider,
172181
fileManager, taggableCloudStorage, versionGenerator, storeScope, rotatingCloudEncryptionKeyProvider, siteId);
173182

174-
encryptedSaltStoreWriter.upload(snapshot2);
183+
JsonObject metadata = new JsonObject()
184+
.put("version", 1742770328863L)
185+
.put("generated", 1742770328)
186+
.put("first_level", "ZaCQ6O8v3kw76rsQfPNl6C+iKzj5c8X/LjCrJcs1zA8=")
187+
.put("id_prefix", "a")
188+
.put("id_secret", "ZhY2JZNaefrRiu5fURsfcAdgB/da3t9tbeEtfRT5KKU=");
189+
190+
encryptedSaltStoreWriter.upload(List.of(snapshot2), metadata);
175191

176192
verify(fileManager,atLeastOnce()).uploadMetadata(metadataCaptor.capture(), nameCaptor.capture(), locationCaptor.capture());
177193

0 commit comments

Comments
 (0)