Skip to content

Commit b9f29ed

Browse files
Have the scope resolve the metadata path instead
1 parent 9f9b37b commit b9f29ed

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/main/java/com/uid2/shared/store/EncryptedRotatingSaltProvider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.uid2.shared.store;
22

3+
import com.uid2.shared.Const;
34
import com.uid2.shared.cloud.DownloadCloudStorage;
45
import com.uid2.shared.model.SaltEntry;
56
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider;
7+
import com.uid2.shared.store.scope.StoreScope;
68

79
import java.io.IOException;
810
import java.io.InputStream;
@@ -13,8 +15,8 @@
1315
public class EncryptedRotatingSaltProvider extends RotatingSaltProvider {
1416
private final RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider;
1517

16-
public EncryptedRotatingSaltProvider(DownloadCloudStorage fileStreamProvider, String metadataPath, RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider) {
17-
super(fileStreamProvider, metadataPath);
18+
public EncryptedRotatingSaltProvider(DownloadCloudStorage fileStreamProvider, RotatingCloudEncryptionKeyProvider cloudEncryptionKeyProvider, StoreScope scope) {
19+
super(fileStreamProvider, scope.getMetadataPath().toString());
1820
this.cloudEncryptionKeyProvider = cloudEncryptionKeyProvider;
1921
}
2022

src/test/java/com/uid2/shared/store/EncryptedRotatingSaltProviderTest.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.uid2.shared.encryption.AesGcm;
55
import com.uid2.shared.model.CloudEncryptionKey;
66
import com.uid2.shared.store.reader.RotatingCloudEncryptionKeyProvider;
7+
import com.uid2.shared.store.scope.EncryptedScope;
78
import io.vertx.core.json.JsonArray;
89
import io.vertx.core.json.JsonObject;
910
import org.junit.jupiter.api.AfterEach;
@@ -67,6 +68,14 @@ private InputStream getEncryptedStream(String content) {
6768
return new ByteArrayInputStream(encryptedContent.getBytes(StandardCharsets.UTF_8));
6869
}
6970

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+
7079
@Test
7180
public void loadSaltSingleVersion() throws Exception {
7281
final String FIRST_LEVEL_SALT = "first_level_salt_value";
@@ -106,13 +115,13 @@ public void loadSaltSingleVersion() throws Exception {
106115
"1000006," + effectiveTimeString + ",MtpALOziEJMtPlCQHk6RHALuWvRvRZpCDBmO0xPAia0=\n" +
107116
"1000007," + effectiveTimeString + ",7tjv+KXaSztTZHEHULacotHQ7IpGBcw6IymoRLObkT4=";
108117

109-
when(cloudStorage.download("metadata"))
118+
when(cloudStorage.download("sites/encrypted/1_public/metadata.json"))
110119
.thenReturn(new ByteArrayInputStream(metadataJson.toString().getBytes(StandardCharsets.US_ASCII)));
111120
when(cloudStorage.download("salts.txt"))
112121
.thenReturn(getEncryptedStream(salts));
113122

114123
EncryptedRotatingSaltProvider saltsProvider = new EncryptedRotatingSaltProvider(
115-
cloudStorage, "metadata", keyProvider);
124+
cloudStorage, keyProvider, new EncryptedScope(new CloudPath("sites/metadata.json"), 1, true));
116125

117126
final JsonObject loadedMetadata = saltsProvider.getMetadata();
118127
saltsProvider.loadContent(loadedMetadata);
@@ -157,13 +166,13 @@ public void loadSaltSingleVersion1mil() throws Exception {
157166
salts.append(i).append(",").append(effectiveTimeString).append(",").append("salt-string").append("\n");
158167
}
159168

160-
when(cloudStorage.download("metadata"))
169+
when(cloudStorage.download("sites/encrypted/1_public/metadata.json"))
161170
.thenReturn(new ByteArrayInputStream(metadataJson.toString().getBytes(StandardCharsets.US_ASCII)));
162171
when(cloudStorage.download("salts.txt"))
163172
.thenReturn(getEncryptedStream(salts.toString()));
164173

165174
EncryptedRotatingSaltProvider saltsProvider = new EncryptedRotatingSaltProvider(
166-
cloudStorage, "metadata", keyProvider);
175+
cloudStorage, keyProvider, new EncryptedScope(new CloudPath("sites/metadata.json"), 1, true));
167176

168177
final JsonObject loadedMetadata = saltsProvider.getMetadata();
169178
saltsProvider.loadContent(loadedMetadata);
@@ -235,15 +244,15 @@ public void loadSaltMultipleVersions() throws Exception {
235244
"1000006," + effectiveTimeStringV1 + ",MtpALOziEJMtPlCQHk6RHALuWvRvRZpCDBmO0xPAia0=\n" +
236245
"1000007," + effectiveTimeStringV1 + ",7tjv+KXaSztTZHEHULacotHQ7IpGBcw6IymoRLObkT4=";
237246

238-
when(cloudStorage.download("metadata"))
247+
when(cloudStorage.download("sites/encrypted/1_public/metadata.json"))
239248
.thenReturn(new ByteArrayInputStream(metadataJson.toString().getBytes(StandardCharsets.US_ASCII)));
240249
when(cloudStorage.download("saltsV1.txt"))
241250
.thenReturn(getEncryptedStream(saltsV1));
242251
when(cloudStorage.download("saltsV2.txt"))
243252
.thenReturn(getEncryptedStream(saltsV2));
244253

245254
EncryptedRotatingSaltProvider saltsProvider = new EncryptedRotatingSaltProvider(
246-
cloudStorage, "metadata", keyProvider);
255+
cloudStorage, keyProvider, new EncryptedScope(new CloudPath("sites/metadata.json"), 1, true));
247256

248257
final JsonObject loadedMetadata = saltsProvider.getMetadata();
249258
saltsProvider.loadContent(loadedMetadata);
@@ -317,15 +326,15 @@ public void loadSaltMultipleVersionsExpired() throws Exception {
317326
"1000006," + effectiveTimeStringV1 + ",MtpALOziEJMtPlCQHk6RHALuWvRvRZpCDBmO0xPAia0=\n" +
318327
"1000007," + effectiveTimeStringV1 + ",7tjv+KXaSztTZHEHULacotHQ7IpGBcw6IymoRLObkT4=";
319328

320-
when(cloudStorage.download("metadata"))
329+
when(cloudStorage.download("sites/encrypted/1_public/metadata.json"))
321330
.thenReturn(new ByteArrayInputStream(metadataJson.toString().getBytes(StandardCharsets.US_ASCII)));
322331
when(cloudStorage.download("saltsV1.txt"))
323332
.thenReturn(getEncryptedStream(saltsV1));
324333
when(cloudStorage.download("saltsV2.txt"))
325334
.thenReturn(getEncryptedStream(saltsV2));
326335

327336
EncryptedRotatingSaltProvider saltsProvider = new EncryptedRotatingSaltProvider(
328-
cloudStorage, "metadata", keyProvider);
337+
cloudStorage, keyProvider, new EncryptedScope(new CloudPath("sites/metadata.json"), 1, true));
329338

330339
final JsonObject loadedMetadata = saltsProvider.getMetadata();
331340
saltsProvider.loadContent(loadedMetadata);

0 commit comments

Comments
 (0)