From 461fce800ac948b846c04ca76a97cc8670926773 Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Wed, 26 Aug 2026 06:58:00 -0500 Subject: [PATCH] Remove test-only Subscriptions method --- .../textsecuregcm/storage/Subscriptions.java | 33 ------------------- .../storage/SubscriptionsTest.java | 33 +++++++++++++++---- 2 files changed, 27 insertions(+), 39 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Subscriptions.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Subscriptions.java index 47cd50d7d..1446d3f3b 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Subscriptions.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Subscriptions.java @@ -30,8 +30,6 @@ import software.amazon.awssdk.services.dynamodb.model.AttributeValue; import software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException; import software.amazon.awssdk.services.dynamodb.model.GetItemRequest; import software.amazon.awssdk.services.dynamodb.model.GetItemResponse; -import software.amazon.awssdk.services.dynamodb.model.QueryRequest; -import software.amazon.awssdk.services.dynamodb.model.QueryResponse; import software.amazon.awssdk.services.dynamodb.model.ReturnValue; import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest; import software.amazon.awssdk.services.dynamodb.model.UpdateItemResponse; @@ -168,37 +166,6 @@ public class Subscriptions { this.client = Objects.requireNonNull(client); } - /** - * Looks in the GSI for a record with the given customer id and returns the user id. - */ - public byte[] getSubscriberUserByProcessorCustomer(ProcessorCustomer processorCustomer) { - QueryRequest query = QueryRequest.builder() - .tableName(table) - .indexName(INDEX_NAME) - .keyConditionExpression("#processor_customer_id = :processor_customer_id") - .projectionExpression("#user") - .expressionAttributeNames(Map.of( - "#processor_customer_id", KEY_PROCESSOR_ID_CUSTOMER_ID, - "#user", KEY_USER)) - .expressionAttributeValues(Map.of( - ":processor_customer_id", b(processorCustomer.toDynamoBytes()))) - .build(); - final QueryResponse queryResponse = client.query(query); - - int count = queryResponse.count(); - if (count == 0) { - return null; - } else if (count > 1) { - logger.error("expected invariant of 1-1 subscriber-customer violated for customer {} ({})", - processorCustomer.customerId(), processorCustomer.processor()); - throw new IllegalStateException( - "expected invariant of 1-1 subscriber-customer violated for customer " + processorCustomer); - } else { - Map result = queryResponse.items().getFirst(); - return result.get(KEY_USER).b().asByteArray(); - } - } - public static class GetResult { public static final GetResult NOT_STORED = new GetResult(Type.NOT_STORED, null); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/SubscriptionsTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/SubscriptionsTest.java index a03174e5d..5c80c53bd 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/SubscriptionsTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/SubscriptionsTest.java @@ -11,11 +11,14 @@ import static org.assertj.core.api.Fail.fail; import static org.whispersystems.textsecuregcm.storage.Subscriptions.GetResult.Type.FOUND; import static org.whispersystems.textsecuregcm.storage.Subscriptions.GetResult.Type.NOT_STORED; import static org.whispersystems.textsecuregcm.storage.Subscriptions.GetResult.Type.PASSWORD_MISMATCH; +import static org.whispersystems.textsecuregcm.util.AttributeValues.b; import jakarta.ws.rs.ClientErrorException; import java.time.Duration; import java.time.Instant; import java.util.Base64; +import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.function.Consumer; import javax.annotation.Nonnull; @@ -29,6 +32,8 @@ import org.whispersystems.textsecuregcm.storage.Subscriptions.Record; import org.whispersystems.textsecuregcm.subscriptions.PaymentProvider; import org.whispersystems.textsecuregcm.subscriptions.ProcessorCustomer; import org.whispersystems.textsecuregcm.util.TestRandomUtil; +import software.amazon.awssdk.services.dynamodb.model.QueryRequest; +import software.amazon.awssdk.services.dynamodb.model.QueryResponse; class SubscriptionsTest { @@ -138,9 +143,8 @@ class SubscriptionsTest { .isInstanceOf(ClientErrorException.class) .satisfies(clientError409Condition); - assertThat(subscriptions.getSubscriberUserByProcessorCustomer( - new ProcessorCustomer(customer, PaymentProvider.STRIPE))) - .isEqualTo(user); + assertThat(getSubscriberUsersByProcessorCustomer(new ProcessorCustomer(customer, PaymentProvider.STRIPE))) + .containsExactly(user); } @Test @@ -154,9 +158,8 @@ class SubscriptionsTest { subscriptions.setProcessorAndCustomerId(userRecord, new ProcessorCustomer(customer, PaymentProvider.STRIPE), subscriptionUpdated); - assertThat(subscriptions.getSubscriberUserByProcessorCustomer( - new ProcessorCustomer(customer, PaymentProvider.STRIPE))) - .isEqualTo(user); + assertThat(getSubscriberUsersByProcessorCustomer(new ProcessorCustomer(customer, PaymentProvider.STRIPE))) + .containsExactly(user); } @Test @@ -372,4 +375,22 @@ class SubscriptionsTest { assertThat(record.currentPeriodEndsAt).isNull(); }; } + + private List getSubscriberUsersByProcessorCustomer(final ProcessorCustomer processorCustomer) { + final QueryResponse queryResponse = DYNAMO_DB_EXTENSION.getDynamoDbClient().query(QueryRequest.builder() + .tableName(Tables.SUBSCRIPTIONS.tableName()) + .indexName(Subscriptions.INDEX_NAME) + .keyConditionExpression("#processor_customer_id = :processor_customer_id") + .projectionExpression("#user") + .expressionAttributeNames(Map.of( + "#processor_customer_id", Subscriptions.KEY_PROCESSOR_ID_CUSTOMER_ID, + "#user", Subscriptions.KEY_USER)) + .expressionAttributeValues(Map.of(":processor_customer_id", b(processorCustomer.toDynamoBytes()))) + .build()); + + return queryResponse.items().stream() + .map(item -> item.get(Subscriptions.KEY_USER).b().asByteArray()) + .toList(); + } + }