Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check operator version and provide correct presigned url #136

Merged
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f979d8f
initial code
lizk886 Jul 23, 2024
cfdf76d
merge 3752
lizk886 Jul 24, 2024
5dc6553
tests
lizk886 Jul 24, 2024
cbcf4de
clean up
lizk886 Jul 24, 2024
ad72a7d
fix config
lizk886 Jul 29, 2024
60dcb27
update comapre version
lizk886 Jul 29, 2024
a64746d
remove snapshot
lizk886 Jul 29, 2024
0c81949
return boolean
lizk886 Jul 29, 2024
e18ea80
use regex
lizk886 Jul 29, 2024
395382c
clean up cpomments
lizk886 Jul 29, 2024
85c77e5
clean up
lizk886 Aug 1, 2024
78559a5
pull origion
lizk886 Aug 2, 2024
e64e6f8
fix spacing
lizk886 Aug 2, 2024
15b3719
refactor, put a new parameter in operator info
lizk886 Aug 2, 2024
c0cabe8
clean up
lizk886 Aug 2, 2024
0627853
operator test info
lizk886 Aug 2, 2024
2b9cddf
update tests
lizk886 Aug 2, 2024
eb338d2
update tests
lizk886 Aug 2, 2024
d4212e7
clean ups
lizk886 Aug 2, 2024
8e0af72
clean ups
lizk886 Aug 2, 2024
fd1ef07
defualt value if configs haven't updated yet
lizk886 Aug 2, 2024
b0e2de5
clean up
lizk886 Aug 2, 2024
53f2173
[CI Pipeline] Released Snapshot version: 2.17.1-alpha-35-SNAPSHOT
Aug 2, 2024
ea74e38
[CI Pipeline] Released Snapshot version: 2.17.2-alpha-36-SNAPSHOT
Aug 2, 2024
0baf8ae
[CI Pipeline] Released Snapshot version: 2.17.3-alpha-37-SNAPSHOT
Aug 2, 2024
b59c01a
update configs to extreme big number
lizk886 Aug 2, 2024
721bd5e
Merge branch 'wzh-uid2-3574-check-version-update-presignedurl' of git…
lizk886 Aug 2, 2024
deec8bb
[CI Pipeline] Released Snapshot version: 2.17.4-alpha-39-SNAPSHOT
Aug 2, 2024
c580126
add logger info to check which version it put
lizk886 Aug 5, 2024
99e7fe7
[CI Pipeline] Released Snapshot version: 2.17.5-alpha-40-SNAPSHOT
Aug 5, 2024
727e867
make config item private
lizk886 Aug 6, 2024
0e22d87
Merge branch 'wzh-uid2-3574-check-version-update-presignedurl' of git…
lizk886 Aug 6, 2024
69d5105
combine sperate printlns into 1 log
lizk886 Aug 6, 2024
6963e73
config issue in tests
lizk886 Aug 6, 2024
1e805dc
config issue in tests
lizk886 Aug 6, 2024
305a17d
config issue in tests
lizk886 Aug 6, 2024
92b99f9
config issue in tests
lizk886 Aug 6, 2024
4771169
revert keyacl and key
lizk886 Aug 6, 2024
bde5d9e
updated testcoreverticle
lizk886 Aug 7, 2024
1396829
update, if this is not working then I am not sure what to do
lizk886 Aug 7, 2024
349b3a3
update, if this is not working then I am not sure what to do
lizk886 Aug 7, 2024
4c7247a
test: deplaying the initialization of config number
lizk886 Aug 7, 2024
29c3bb9
update shared only for 3574
lizk886 Aug 7, 2024
d88c3e6
update comments
lizk886 Aug 7, 2024
d8df255
update client
lizk886 Aug 7, 2024
fe7c567
take in operator info
lizk886 Aug 7, 2024
4e5fd45
huge encryption benchmark
lizk886 Aug 7, 2024
b73ba5c
[CI Pipeline] Released Snapshot version: 2.17.6-alpha-42-SNAPSHOT
Aug 7, 2024
18324c1
update site, let it read encrpted/pliantext contents too
lizk886 Aug 7, 2024
23ebe65
Merge branch 'wzh-uid2-3574-check-version-update-presignedurl' of git…
lizk886 Aug 7, 2024
0f985c8
update site, let it read encrpted/pliantext contents too
lizk886 Aug 7, 2024
135867b
update site
lizk886 Aug 7, 2024
6050013
[CI Pipeline] Released Snapshot version: 2.17.7-alpha-43-SNAPSHOT
Aug 7, 2024
4aec426
[CI Pipeline] Released Snapshot version: 2.17.8-alpha-44-SNAPSHOT
Aug 7, 2024
3a5e135
make logger using debig version
lizk886 Aug 9, 2024
2b5736d
Added some more unit tests
cody-constine-ttd Nov 8, 2024
a063759
Small PR comments and upgraded to published shared version
cody-constine-ttd Nov 12, 2024
24bb77e
Merged up to main
cody-constine-ttd Nov 12, 2024
557b4f8
Finished merge
cody-constine-ttd Nov 12, 2024
7bfd915
Finished rename
cody-constine-ttd Nov 18, 2024
2cc2627
Merging up to main
cody-constine-ttd Nov 20, 2024
aba5976
Moving support version to 9999
cody-constine-ttd Nov 22, 2024
3d9a2a3
[CI Pipeline] Released Snapshot version: 2.21.1-alpha-61-SNAPSHOT
Nov 22, 2024
43fd8fc
Merging up to main
cody-constine-ttd Nov 25, 2024
1f4801f
[CI Pipeline] Released Snapshot version: 2.21.8-alpha-63-SNAPSHOT
Nov 25, 2024
fec327f
removing log message that will appear too much
cody-constine-ttd Nov 25, 2024
bd1fa80
updating operator version for workspace
cody-constine-ttd Nov 25, 2024
9f2105e
Fix bad indent
cody-constine-ttd Dec 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion conf/default-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"att_token_enc_key": null,
"att_token_enc_salt": null,
"enforceJwt": false,
"s3_keys_metadata_path": null
"s3_keys_metadata_path": null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not forget to add this in the uid2-operator-deployment repo. Suggest you add that before you merge this

"encryption_support_version": "5"
}
3 changes: 2 additions & 1 deletion conf/integ-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"keyset_keys_metadata_path": "uid2/keyset_keys/metadata.json",
"salts_metadata_path": "uid2/salts/metadata.json",
"enforceJwt": false,
"s3_keys_metadata_path": "uid2/s3encryption_keys/metadata.json"
"s3_keys_metadata_path": "uid2/s3encryption_keys/metadata.json",
"encryption_support_version": "5"
}
3 changes: 2 additions & 1 deletion conf/local-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"att_token_enc_salt": "<salt-for-attestation-token>",
"provide_private_site_data": true,
"enforceJwt": false,
"s3_keys_metadata_path": "/com.uid2.core/test/s3encryption_keys/metadata.json"
"s3_keys_metadata_path": "/com.uid2.core/test/s3encryption_keys/metadata.json",
"encryption_support_version": "5"
}
3 changes: 2 additions & 1 deletion conf/local-e2e-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"aws_kms_jwt_signing_public_keys": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmvwB41qI5Fe41PDbXqcX5uOvSvfKh8l9QV0O3M+NsB4lKqQEP0t1hfoiXTpOgKz1ArYxHsQ2LeXifX4uwEbYJFlpVM+tyQkTWQjBOw6fsLYK2Xk4X2ylNXUUf7x3SDiOVxyvTh3OZW9kqrDBN9JxSoraNLyfw0hhW0SHpfs699SehgbQ7QWep/gVlKRLIz0XAXaZNw24s79ORcQlrCE6YD0PgQmpI/dK5xMML82n6y3qcTlywlGaU7OGIMdD+CTXA3BcOkgXeqZTXNaX1u6jCTa1lvAczun6avp5VZ4TFiuPo+y4rJ3GU+14cyT5NckEcaTKSvd86UdwK5Id9tl3bQIDAQAB",
"core_public_url": "http://localhost:8088",
"optout_url": "http://localhost:8081",
"s3_keys_metadata_path": "s3encryption_keys/metadata.json"
"s3_keys_metadata_path": "s3encryption_keys/metadata.json",
"encryption_support_version": "5"
}
3 changes: 2 additions & 1 deletion conf/local-e2e-docker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
"aws_kms_jwt_signing_public_keys": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmvwB41qI5Fe41PDbXqcX5uOvSvfKh8l9QV0O3M+NsB4lKqQEP0t1hfoiXTpOgKz1ArYxHsQ2LeXifX4uwEbYJFlpVM+tyQkTWQjBOw6fsLYK2Xk4X2ylNXUUf7x3SDiOVxyvTh3OZW9kqrDBN9JxSoraNLyfw0hhW0SHpfs699SehgbQ7QWep/gVlKRLIz0XAXaZNw24s79ORcQlrCE6YD0PgQmpI/dK5xMML82n6y3qcTlywlGaU7OGIMdD+CTXA3BcOkgXeqZTXNaX1u6jCTa1lvAczun6avp5VZ4TFiuPo+y4rJ3GU+14cyT5NckEcaTKSvd86UdwK5Id9tl3bQIDAQAB",
"core_public_url": "http://core:8088",
"optout_url": "http://optout:8081",
"s3_keys_metadata_path": "s3encryption_keys/metadata.json"
"s3_keys_metadata_path": "s3encryption_keys/metadata.json",
"encryption_support_version": "5"
}
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.uid2</groupId>
<artifactId>uid2-core</artifactId>
<version>2.17.0</version>
<version>2.17.8-alpha-44-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -24,7 +24,7 @@
<vertx.verticle>com.uid2.core.vertx.CoreVerticle</vertx.verticle>
<launcher.class>io.vertx.core.Launcher</launcher.class>

<uid2-shared.version>7.17.0</uid2-shared.version>
<uid2-shared.version>7.17.8-alpha-140-SNAPSHOT</uid2-shared.version>
<image.version>${project.version}</image.version>
</properties>

Expand Down Expand Up @@ -109,6 +109,11 @@
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does byte-buddy do?

<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.17</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-micrometer-metrics</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ClientMetadataProvider implements IClientMetadataProvider {

@Override
public String getMetadata(OperatorInfo info) throws Exception {
String pathname = getMetadataPathName(info.getOperatorType(), info.getSiteId(), SecretStore.Global.get(ClientsMetadataPathName));
String pathname = getMetadataPathName(info, SecretStore.Global.get(ClientsMetadataPathName));
String original = readToEndAsString(metadataStreamProvider.download(pathname));
JsonObject main = (JsonObject) Json.decodeValue(original);
JsonObject obj = main.getJsonObject("client_keys");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.uid2.core.service;

import com.uid2.core.util.OperatorInfo;

public interface ISiteMetadataProvider {
String getMetadata() throws Exception;
String getMetadata(OperatorInfo info) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public KeysetKeysMetadataProvider(ICloudStorage cloudStorage) {

@Override
public String getMetadata(OperatorInfo info) throws Exception {
String pathname = getMetadataPathName(info.getOperatorType(), info.getSiteId(), SecretStore.Global.get(Const.Config.KeysetKeysMetadataPathProp));
String pathname = getMetadataPathName(info, SecretStore.Global.get(Const.Config.KeysetKeysMetadataPathProp));
String original = readToEndAsString(metadataStreamProvider.download(pathname));
JsonObject main = (JsonObject) Json.decodeValue(original);
JsonObject obj = main.getJsonObject("keyset_keys");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public KeysetMetadataProvider(ICloudStorage cloudStorage) {

@Override
public String getMetadata(OperatorInfo info) throws Exception {
String pathname = getMetadataPathName(info.getOperatorType(), info.getSiteId(), SecretStore.Global.get(Const.Config.KeysetsMetadataPathProp));
String pathname = getMetadataPathName(info, SecretStore.Global.get(Const.Config.KeysetsMetadataPathProp));
String original = readToEndAsString(metadataStreamProvider.download(pathname));
JsonObject main = (JsonObject) Json.decodeValue(original);
JsonObject obj = main.getJsonObject("keysets");
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/uid2/core/service/SiteMetadataProvider.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.uid2.core.service;

import com.uid2.core.model.SecretStore;
import com.uid2.core.util.OperatorInfo;
import com.uid2.shared.Const;
import com.uid2.shared.cloud.ICloudStorage;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.scope.GlobalScope;
Expand All @@ -11,6 +13,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;

import static com.uid2.core.util.MetadataHelper.getMetadataPathName;
import static com.uid2.core.util.MetadataHelper.readToEndAsString;

public class SiteMetadataProvider implements ISiteMetadataProvider {
Expand All @@ -22,8 +25,8 @@ public SiteMetadataProvider(ICloudStorage cloudStorage) {
this.metadataStreamProvider = this.downloadUrlGenerator = cloudStorage;
}
@Override
public String getMetadata() throws Exception {
String pathname = new GlobalScope(new CloudPath(SecretStore.Global.get(SiteMetadataPathName))).getMetadataPath().toString();
public String getMetadata(OperatorInfo info) throws Exception {
String pathname = getMetadataPathName(info, SecretStore.Global.get(SiteMetadataPathName));
String original = readToEndAsString(metadataStreamProvider.download(pathname));
JsonObject main = (JsonObject) Json.decodeValue(original);
JsonObject obj = main.getJsonObject("sites");
Expand Down
36 changes: 27 additions & 9 deletions src/main/java/com/uid2/core/util/MetadataHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.uid2.shared.auth.OperatorType;
import com.uid2.shared.auth.Role;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.scope.EncryptedScope;
import com.uid2.shared.store.scope.GlobalScope;
import com.uid2.shared.store.scope.SiteScope;
import com.uid2.shared.store.scope.StoreScope;
Expand All @@ -22,17 +23,34 @@ public static String getSiteSpecificMetadataPathName(int siteId, String metadata
return SiteSpecificDataSubDirPath +siteId + metadataPathName;
}

public static String getMetadataPathName(OperatorType operatorType, int siteId, String metadataPathName)
{
public static String getMetadataPathName(OperatorType operatorType, int siteId, String metadataPathName) {
lizk886 marked this conversation as resolved.
Show resolved Hide resolved
return getMetadataPathName(operatorType, siteId, metadataPathName, false);
}

public static String getMetadataPathName(OperatorInfo info, String metadataPathName) {
return getMetadataPathName(info.getOperatorType(), info.getSiteId(), metadataPathName, info.getSupportsEncryption());
}


public static String getMetadataPathName(OperatorType operatorType, int siteId, String metadataPathName, Boolean canDecrypt) {
cody-constine-ttd marked this conversation as resolved.
Show resolved Hide resolved
StoreScope store;
Boolean providePrivateSiteData = ConfigStore.Global.getBoolean("provide_private_site_data");
if (operatorType == OperatorType.PUBLIC || (providePrivateSiteData == null || !providePrivateSiteData.booleanValue()))
{
store = new GlobalScope(new CloudPath(metadataPathName));
}
else //PRIVATE
{
store = new SiteScope(new CloudPath(metadataPathName), siteId);
if (canDecrypt) { // Check if decryption is possible
if (operatorType == OperatorType.PUBLIC ) //siteId_public folder
{
store = new EncryptedScope(new CloudPath(metadataPathName), siteId, true);
} else //siteId_private folder
{
store = new EncryptedScope(new CloudPath(metadataPathName), siteId, false);
}
} else {
if (operatorType == OperatorType.PUBLIC || (providePrivateSiteData == null || !providePrivateSiteData.booleanValue()))
{
store = new GlobalScope(new CloudPath(metadataPathName));
} else //PRIVATE
{
store = new SiteScope(new CloudPath(metadataPathName), siteId);
}
}
return store.getMetadataPath().toString();
}
Expand Down
73 changes: 71 additions & 2 deletions src/main/java/com/uid2/core/util/OperatorInfo.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package com.uid2.core.util;
import com.uid2.core.Const;
import com.uid2.shared.auth.IAuthorizable;
import com.uid2.shared.auth.OperatorKey;
import com.uid2.shared.auth.OperatorType;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.ext.web.RoutingContext;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.uid2.core.model.ConfigStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.uid2.shared.Const.Config.encryptionSupportVersion;
import static com.uid2.shared.Const.Http.AppVersionHeader;
import static com.uid2.shared.middleware.AuthMiddleware.API_CLIENT_PROP;

/**
Expand All @@ -13,6 +23,9 @@
public class OperatorInfo {
private final OperatorType operatorType;
private final int siteId;
private final boolean supportsEncryption;

static Logger logger = LoggerFactory.getLogger(OperatorInfo.class);

public OperatorType getOperatorType() {
return operatorType;
Expand All @@ -22,17 +35,73 @@ public int getSiteId() {
return siteId;
}

public OperatorInfo(OperatorType operatorType, int siteId) {
public boolean getSupportsEncryption() {return supportsEncryption;}

public OperatorInfo(OperatorType operatorType, int siteId, boolean supportsEncryption) {
this.operatorType = operatorType;
this.siteId = siteId;
this.supportsEncryption = supportsEncryption;
}

public static OperatorInfo getOperatorInfo(RoutingContext rc) throws Exception {
IAuthorizable profile = (IAuthorizable) rc.data().get(API_CLIENT_PROP);
if (profile instanceof OperatorKey) {
OperatorKey operatorKey = (OperatorKey) profile;
return new OperatorInfo(operatorKey.getOperatorType(), operatorKey.getSiteId());
return new OperatorInfo(operatorKey.getOperatorType(), operatorKey.getSiteId(), supportsEncryption(rc));
}
throw new Exception("Cannot determine the operator type and site id from the profile");
}

static boolean supportsEncryption(RoutingContext rc) {
String appVersion = rc.request().getHeader(AppVersionHeader);
if (appVersion == null) {
logger.warn("AppVersion header is missing.");
return false;
}
String[] versions = appVersion.split(";");
for (String version : versions) {
if (version.startsWith("uid2-operator=")) {
String operatorVersion = version.substring("uid2-operator=".length());
boolean isSupported = isVersionGreaterOrEqual(operatorVersion, ConfigStore.Global.getOrDefault(encryptionSupportVersion, "9999"));
logger.debug("Operator version: {}, {}",
operatorVersion, isSupported ? "Supports encryption" : "Does not support encryption");
return isSupported;
}
}
logger.warn("No operator version found in AppVersion header.");
return false;
}

/*
Returns if the version of a semvar v1 is greater or equal to v2
*/
static boolean isVersionGreaterOrEqual(String v1, String v2) {
Pattern pattern = Pattern.compile("(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?");
Matcher m1 = pattern.matcher(v1);
Matcher m2 = pattern.matcher(v2);

int[] parts1 = extractParts(m1);
int[] parts2 = extractParts(m2);

for (int i = 0; i < Math.max(parts1.length, parts2.length); i++) {
int p1 = i < parts1.length ? parts1[i] : 0;
int p2 = i < parts2.length ? parts2[i] : 0;
if (p1 != p2) {
return p1 > p2;
}
}

return true;
}

private static int[] extractParts(Matcher matcher) {
int[] parts = new int[3];
if (matcher.find()) {
for (int i = 1; i <= 3; i++) {
String group = matcher.group(i);
parts[i - 1] = group != null ? Integer.parseInt(group) : 0;
}
}
return parts;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/uid2/core/vertx/CoreVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private void handleSiteRefresh(RoutingContext rc) {
return;
}
rc.response().putHeader(HttpHeaders.CONTENT_TYPE, "application/json")
.end(siteMetadataProvider.getMetadata());
.end(siteMetadataProvider.getMetadata(info));
} catch (Exception e) {
logger.warn("exception in handleSiteRefresh: " + e.getMessage(), e);
Error("error", 500, rc, "error processing sites refresh");
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/com.uid2.core/test/operators/operators.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
[
{
"key": "UID2-O-L-999-dp9Dt0.JVoGpynN4J8nMA7FxmzsavxJa8B9H74y9xdEE=",
"name": "Special",
"contact": "Special",
"protocol": "trusted",
"created": 1701210253,
"disabled": false,
"roles": [
"OPERATOR",
"OPTOUT"
],
"site_id": 999,
"operator_type": "PUBLIC",
"key_hash": "rTD7MpJn5/j4G6N+Ph659F4FGtiJy7MLNtfVA7XUdu6cYC9ok6EwGeI2upyDOvxvPkOCUn7HBKay8ubPQmRc0A==",
"key_salt": "ZpqdDFksFeWx/ouPAoWi39TVuGrSGwijfCN4f0pAl2Y=",
"key_id": "UID2-O-L-999-dp9Dt"
},
{
"key": "test-partner-key",
"name": "[email protected]",
Expand Down
67 changes: 67 additions & 0 deletions src/test/java/com/uid2/core/util/TestMetadataHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.uid2.core.util;

import com.uid2.core.model.ConfigStore;
import com.uid2.shared.auth.OperatorType;
import io.vertx.core.json.JsonObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;


public class TestMetadataHelper {

@Mock
private OperatorInfo operatorInfo;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
ConfigStore.Global.load(new JsonObject().put("provide_private_site_data", true));
}

@Test
void testGetMetadataPathNameDecryptPublic() {
when(operatorInfo.getOperatorType()).thenReturn(OperatorType.PUBLIC);
when(operatorInfo.getSiteId()).thenReturn(42);
when(operatorInfo.getSupportsEncryption()).thenReturn(true);

String result = MetadataHelper.getMetadataPathName(operatorInfo, "s3://test-bucket/folder/");
assertEquals("s3://test-bucket/encrypted/42_public/folder", result);
}

@Test
void testGetMetadataPathNameDecryptPrivate() {
when(operatorInfo.getOperatorType()).thenReturn(OperatorType.PRIVATE);
when(operatorInfo.getSiteId()).thenReturn(42);
when(operatorInfo.getSupportsEncryption()).thenReturn(true);

String result = MetadataHelper.getMetadataPathName(operatorInfo, "s3://test-bucket/folder/");
assertEquals("s3://test-bucket/encrypted/42_private/folder", result);
}


@Test
void testGetMetadataPathNamePublic() {
when(operatorInfo.getOperatorType()).thenReturn(OperatorType.PUBLIC);
when(operatorInfo.getSiteId()).thenReturn(42);
when(operatorInfo.getSupportsEncryption()).thenReturn(false);

String result = MetadataHelper.getMetadataPathName(operatorInfo, "s3://test-bucket/folder/");
assertEquals("s3://test-bucket/folder", result);
}


@Test
void testGetMetadataPathNamePrivate() {
when(operatorInfo.getOperatorType()).thenReturn(OperatorType.PRIVATE);
when(operatorInfo.getSiteId()).thenReturn(42);
when(operatorInfo.getSupportsEncryption()).thenReturn(false);

String result = MetadataHelper.getMetadataPathName(operatorInfo, "s3://test-bucket/folder/");
assertEquals("s3://test-bucket/site/42/folder", result);
}
}
Loading