From e7d1eadf8e8c39f66cf5249ea0f11dda5a3315ec Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Tue, 19 Mar 2024 15:49:45 -0500 Subject: [PATCH] Fix experiments in BackupAuthManager --- .../textsecuregcm/WhisperServerService.java | 2 +- .../textsecuregcm/backup/BackupAuthManager.java | 12 +++++------- .../textsecuregcm/tests/util/ExperimentHelper.java | 11 ++++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index e63801566..46e8feb8a 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -700,7 +700,7 @@ public void run(WhisperServerConfiguration config, Environment environment) thro ServerZkReceiptOperations zkReceiptOperations = new ServerZkReceiptOperations(zkSecretParams); Cdn3BackupCredentialGenerator cdn3BackupCredentialGenerator = new Cdn3BackupCredentialGenerator(config.getTus()); - BackupAuthManager backupAuthManager = new BackupAuthManager(dynamicConfigurationManager, rateLimiters, accountsManager, backupsGenericZkSecretParams, clock); + BackupAuthManager backupAuthManager = new BackupAuthManager(experimentEnrollmentManager, rateLimiters, accountsManager, backupsGenericZkSecretParams, clock); BackupsDb backupsDb = new BackupsDb( dynamoDbAsyncClient, config.getDynamoDbTables().getBackups().getTableName(), diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/backup/BackupAuthManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/backup/BackupAuthManager.java index 1b734a726..5cb3ab99c 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/backup/BackupAuthManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/backup/BackupAuthManager.java @@ -21,6 +21,7 @@ import org.signal.libsignal.zkgroup.backups.BackupAuthCredentialResponse; import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; import org.whispersystems.textsecuregcm.controllers.RateLimitExceededException; +import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager; import org.whispersystems.textsecuregcm.limits.RateLimiters; import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.AccountsManager; @@ -43,19 +44,19 @@ public class BackupAuthManager { final static String BACKUP_EXPERIMENT_NAME = "backup"; final static String BACKUP_MEDIA_EXPERIMENT_NAME = "backupMedia"; - private final DynamicConfigurationManager dynamicConfigurationManager; + private final ExperimentEnrollmentManager experimentEnrollmentManager; private final GenericServerSecretParams serverSecretParams; private final Clock clock; private final RateLimiters rateLimiters; private final AccountsManager accountsManager; public BackupAuthManager( - final DynamicConfigurationManager dynamicConfigurationManager, + final ExperimentEnrollmentManager experimentEnrollmentManager, final RateLimiters rateLimiters, final AccountsManager accountsManager, final GenericServerSecretParams serverSecretParams, final Clock clock) { - this.dynamicConfigurationManager = dynamicConfigurationManager; + this.experimentEnrollmentManager = experimentEnrollmentManager; this.rateLimiters = rateLimiters; this.accountsManager = accountsManager; this.serverSecretParams = serverSecretParams; @@ -157,9 +158,6 @@ private Optional receiptLevel(final Account account) { } private boolean inExperiment(final String experimentName, final Account account) { - return dynamicConfigurationManager.getConfiguration() - .getExperimentEnrollmentConfiguration(experimentName) - .map(config -> config.getEnrolledUuids().contains(account.getUuid())) - .orElse(false); + return this.experimentEnrollmentManager.isEnrolled(account.getUuid(), experimentName); } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/ExperimentHelper.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/ExperimentHelper.java index e88fb86c6..f0e3a9c28 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/ExperimentHelper.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/ExperimentHelper.java @@ -7,6 +7,7 @@ import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicExperimentEnrollmentConfiguration; +import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager; import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager; import java.util.Optional; import java.util.Set; @@ -17,7 +18,7 @@ public class ExperimentHelper { - public static DynamicConfigurationManager withEnrollment( + private static DynamicConfigurationManager withEnrollment( final String experimentName, final Set enrolledUuids, final int enrollmentPercentage) { @@ -31,11 +32,11 @@ public static DynamicConfigurationManager withEnrollment( return dcm; } - public static DynamicConfigurationManager withEnrollment(final String experimentName, final Set enrolledUuids) { - return withEnrollment(experimentName, enrolledUuids, 0); + public static ExperimentEnrollmentManager withEnrollment(final String experimentName, final Set enrolledUuids) { + return new ExperimentEnrollmentManager(withEnrollment(experimentName, enrolledUuids, 0)); } - public static DynamicConfigurationManager withEnrollment(final String experimentName, final UUID enrolledUuid) { - return withEnrollment(experimentName, Set.of(enrolledUuid), 0); + public static ExperimentEnrollmentManager withEnrollment(final String experimentName, final UUID enrolledUuid) { + return new ExperimentEnrollmentManager(withEnrollment(experimentName, Set.of(enrolledUuid), 0)); } }