|
4 | 4 | import com.uid2.shared.encryption.AesGcm; |
5 | 5 | import com.uid2.shared.model.CloudEncryptionKey; |
6 | 6 | import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider; |
| 7 | +import com.uid2.shared.store.scope.EncryptedScope; |
7 | 8 | import io.vertx.core.json.JsonArray; |
8 | 9 | import io.vertx.core.json.JsonObject; |
9 | 10 | import org.junit.jupiter.api.AfterEach; |
@@ -67,6 +68,14 @@ private InputStream getEncryptedStream(String content) { |
67 | 68 | return new ByteArrayInputStream(encryptedContent.getBytes(StandardCharsets.UTF_8)); |
68 | 69 | } |
69 | 70 |
|
| 71 | + @Test |
| 72 | + public void metadataPath() { |
| 73 | + EncryptedRotatingSaltProvider saltsProvider = new EncryptedRotatingSaltProvider( |
| 74 | + cloudStorage, keyProvider, new EncryptedScope(new CloudPath("salts/metadata.json"), 1, true)); |
| 75 | + |
| 76 | + assertEquals("salts/encrypted/1_public/metadata.json", saltsProvider.getMetadataPath()); |
| 77 | + } |
| 78 | + |
70 | 79 | @Test |
71 | 80 | public void loadSaltSingleVersion() throws Exception { |
72 | 81 | final String FIRST_LEVEL_SALT = "first_level_salt_value"; |
@@ -106,13 +115,13 @@ public void loadSaltSingleVersion() throws Exception { |
106 | 115 | "1000006," + effectiveTimeString + ",MtpALOziEJMtPlCQHk6RHALuWvRvRZpCDBmO0xPAia0=\n" + |
107 | 116 | "1000007," + effectiveTimeString + ",7tjv+KXaSztTZHEHULacotHQ7IpGBcw6IymoRLObkT4="; |
108 | 117 |
|
109 | | - when(cloudStorage.download("metadata")) |
| 118 | + when(cloudStorage.download("sites/encrypted/1_public/metadata.json")) |
110 | 119 | .thenReturn(new ByteArrayInputStream(metadataJson.toString().getBytes(StandardCharsets.US_ASCII))); |
111 | 120 | when(cloudStorage.download("salts.txt")) |
112 | 121 | .thenReturn(getEncryptedStream(salts)); |
113 | 122 |
|
114 | 123 | EncryptedRotatingSaltProvider saltsProvider = new EncryptedRotatingSaltProvider( |
115 | | - cloudStorage, "metadata", keyProvider); |
| 124 | + cloudStorage, keyProvider, new EncryptedScope(new CloudPath("sites/metadata.json"), 1, true)); |
116 | 125 |
|
117 | 126 | final JsonObject loadedMetadata = saltsProvider.getMetadata(); |
118 | 127 | saltsProvider.loadContent(loadedMetadata); |
@@ -157,13 +166,13 @@ public void loadSaltSingleVersion1mil() throws Exception { |
157 | 166 | salts.append(i).append(",").append(effectiveTimeString).append(",").append("salt-string").append("\n"); |
158 | 167 | } |
159 | 168 |
|
160 | | - when(cloudStorage.download("metadata")) |
| 169 | + when(cloudStorage.download("sites/encrypted/1_public/metadata.json")) |
161 | 170 | .thenReturn(new ByteArrayInputStream(metadataJson.toString().getBytes(StandardCharsets.US_ASCII))); |
162 | 171 | when(cloudStorage.download("salts.txt")) |
163 | 172 | .thenReturn(getEncryptedStream(salts.toString())); |
164 | 173 |
|
165 | 174 | EncryptedRotatingSaltProvider saltsProvider = new EncryptedRotatingSaltProvider( |
166 | | - cloudStorage, "metadata", keyProvider); |
| 175 | + cloudStorage, keyProvider, new EncryptedScope(new CloudPath("sites/metadata.json"), 1, true)); |
167 | 176 |
|
168 | 177 | final JsonObject loadedMetadata = saltsProvider.getMetadata(); |
169 | 178 | saltsProvider.loadContent(loadedMetadata); |
@@ -235,15 +244,15 @@ public void loadSaltMultipleVersions() throws Exception { |
235 | 244 | "1000006," + effectiveTimeStringV1 + ",MtpALOziEJMtPlCQHk6RHALuWvRvRZpCDBmO0xPAia0=\n" + |
236 | 245 | "1000007," + effectiveTimeStringV1 + ",7tjv+KXaSztTZHEHULacotHQ7IpGBcw6IymoRLObkT4="; |
237 | 246 |
|
238 | | - when(cloudStorage.download("metadata")) |
| 247 | + when(cloudStorage.download("sites/encrypted/1_public/metadata.json")) |
239 | 248 | .thenReturn(new ByteArrayInputStream(metadataJson.toString().getBytes(StandardCharsets.US_ASCII))); |
240 | 249 | when(cloudStorage.download("saltsV1.txt")) |
241 | 250 | .thenReturn(getEncryptedStream(saltsV1)); |
242 | 251 | when(cloudStorage.download("saltsV2.txt")) |
243 | 252 | .thenReturn(getEncryptedStream(saltsV2)); |
244 | 253 |
|
245 | 254 | EncryptedRotatingSaltProvider saltsProvider = new EncryptedRotatingSaltProvider( |
246 | | - cloudStorage, "metadata", keyProvider); |
| 255 | + cloudStorage, keyProvider, new EncryptedScope(new CloudPath("sites/metadata.json"), 1, true)); |
247 | 256 |
|
248 | 257 | final JsonObject loadedMetadata = saltsProvider.getMetadata(); |
249 | 258 | saltsProvider.loadContent(loadedMetadata); |
@@ -317,15 +326,15 @@ public void loadSaltMultipleVersionsExpired() throws Exception { |
317 | 326 | "1000006," + effectiveTimeStringV1 + ",MtpALOziEJMtPlCQHk6RHALuWvRvRZpCDBmO0xPAia0=\n" + |
318 | 327 | "1000007," + effectiveTimeStringV1 + ",7tjv+KXaSztTZHEHULacotHQ7IpGBcw6IymoRLObkT4="; |
319 | 328 |
|
320 | | - when(cloudStorage.download("metadata")) |
| 329 | + when(cloudStorage.download("sites/encrypted/1_public/metadata.json")) |
321 | 330 | .thenReturn(new ByteArrayInputStream(metadataJson.toString().getBytes(StandardCharsets.US_ASCII))); |
322 | 331 | when(cloudStorage.download("saltsV1.txt")) |
323 | 332 | .thenReturn(getEncryptedStream(saltsV1)); |
324 | 333 | when(cloudStorage.download("saltsV2.txt")) |
325 | 334 | .thenReturn(getEncryptedStream(saltsV2)); |
326 | 335 |
|
327 | 336 | EncryptedRotatingSaltProvider saltsProvider = new EncryptedRotatingSaltProvider( |
328 | | - cloudStorage, "metadata", keyProvider); |
| 337 | + cloudStorage, keyProvider, new EncryptedScope(new CloudPath("sites/metadata.json"), 1, true)); |
329 | 338 |
|
330 | 339 | final JsonObject loadedMetadata = saltsProvider.getMetadata(); |
331 | 340 | saltsProvider.loadContent(loadedMetadata); |
|
0 commit comments