mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-11-30 01:06:50 +00:00
Remove test-only Subscriptions method
This commit is contained in:
1 parent
7f08e8bf4e
commit
461fce800a
2 files changed
+27
-39
No files matched your search
@@ -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<String, AttributeValue> 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);
|
||||
|
||||
+27
-6
@@ -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<byte[]> 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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user