mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-11-30 00:56:50 +00:00
Use singular “credential” when appropriate
This commit is contained in:
1 parent
740116e1fd
commit
87ca4578b3
17 files changed
+149
-150
No files matched your search
+7
-7
@@ -313,7 +313,7 @@ public class OneTimeDonationController {
|
||||
return new ConfirmPayPalBoostResponse(chargeSuccessDetails.paymentId());
|
||||
}
|
||||
|
||||
public static class CreateBoostReceiptCredentialsRequest {
|
||||
public static class CreateBoostReceiptCredentialRequest {
|
||||
|
||||
/**
|
||||
* a payment ID from {@link #processor}
|
||||
@@ -327,10 +327,10 @@ public class OneTimeDonationController {
|
||||
public PaymentProvider processor = PaymentProvider.STRIPE;
|
||||
}
|
||||
|
||||
public record CreateBoostReceiptCredentialsSuccessResponse(byte[] receiptCredentialResponse) {
|
||||
public record CreateBoostReceiptCredentialSuccessResponse(byte[] receiptCredentialResponse) {
|
||||
}
|
||||
|
||||
public record CreateBoostReceiptCredentialsErrorResponse(
|
||||
public record CreateBoostReceiptCredentialErrorResponse(
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) ChargeFailure chargeFailure) {}
|
||||
|
||||
@POST
|
||||
@@ -338,9 +338,9 @@ public class OneTimeDonationController {
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@ManagedAsync
|
||||
public Response createBoostReceiptCredentials(
|
||||
public Response createBoostReceiptCredential(
|
||||
@Auth final Optional<AuthenticatedDevice> authenticatedAccount,
|
||||
@NotNull @Valid final CreateBoostReceiptCredentialsRequest request,
|
||||
@NotNull @Valid final CreateBoostReceiptCredentialRequest request,
|
||||
@HeaderParam(HttpHeaders.USER_AGENT) final String userAgent) throws IOException {
|
||||
|
||||
if (authenticatedAccount.isPresent()) {
|
||||
@@ -363,7 +363,7 @@ public class OneTimeDonationController {
|
||||
}
|
||||
if (paymentDetails.status() != PaymentStatus.SUCCEEDED) {
|
||||
throw new WebApplicationException(Response.status(Response.Status.PAYMENT_REQUIRED)
|
||||
.entity(new CreateBoostReceiptCredentialsErrorResponse(paymentDetails.chargeFailure())).build());
|
||||
.entity(new CreateBoostReceiptCredentialErrorResponse(paymentDetails.chargeFailure())).build());
|
||||
}
|
||||
|
||||
// The payment was successful, try to issue the receipt credential
|
||||
@@ -406,7 +406,7 @@ public class OneTimeDonationController {
|
||||
UserAgentTagUtil.getPlatformTag(userAgent)))
|
||||
.increment();
|
||||
return Response.ok(
|
||||
new CreateBoostReceiptCredentialsSuccessResponse(receiptCredentialResponse.serialize()))
|
||||
new CreateBoostReceiptCredentialSuccessResponse(receiptCredentialResponse.serialize()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -688,12 +688,12 @@ public class SubscriptionController {
|
||||
.orElseGet(() -> new GetSubscriptionInformationResponse(null, null));
|
||||
}
|
||||
|
||||
public record GetReceiptCredentialsRequest(
|
||||
public record GetReceiptCredentialRequest(
|
||||
@Schema(description = "A ReceiptCredentialRequest encoded in standard base64 with padding")
|
||||
@NotEmpty byte[] receiptCredentialRequest) {
|
||||
}
|
||||
|
||||
public record GetReceiptCredentialsResponse(
|
||||
public record GetReceiptCredentialResponse(
|
||||
@Schema(description = "A ReceiptCredentialResponse encoded in standard base64 with padding")
|
||||
@NotEmpty byte[] receiptCredentialResponse) {
|
||||
}
|
||||
@@ -711,7 +711,7 @@ public class SubscriptionController {
|
||||
invoice. Clients SHOULD retry requests at this endpoint with the same ReceiptCredentialRequest value until
|
||||
receiving a response. After receiving a response, clients should then compute the ReceiptCredentialPresentation
|
||||
and redeem it at the receipt redemption endpoint. Once the first attempt is made there, the same
|
||||
ReceiptCredentialRequest MUST NOT be used again to request receipt credentials.
|
||||
ReceiptCredentialRequest MUST NOT be used again to request a receipt credential.
|
||||
|
||||
Note that you may in fact redeem TWO or more invoices for the same ReceiptCredentialRequest while retrying this
|
||||
operation if a later invoice gets paid while you are retrying. However, the returned receipt is always for the
|
||||
@@ -747,14 +747,14 @@ public class SubscriptionController {
|
||||
name = "Retry-After",
|
||||
description = "If present, a positive integer indicating the number of seconds before a subsequent attempt could succeed"))
|
||||
@ManagedAsync
|
||||
public Response createSubscriptionReceiptCredentials(
|
||||
public Response createSubscriptionReceiptCredential(
|
||||
@Auth Optional<AuthenticatedDevice> authenticatedAccount,
|
||||
@HeaderParam(HttpHeaders.USER_AGENT) final String userAgent,
|
||||
@PathParam("subscriberId") String subscriberId,
|
||||
@NotNull @Valid GetReceiptCredentialsRequest request) throws SubscriptionException, RateLimitExceededException {
|
||||
@NotNull @Valid GetReceiptCredentialRequest request) throws SubscriptionException, RateLimitExceededException {
|
||||
SubscriberCredentials subscriberCredentials = SubscriberCredentials.process(authenticatedAccount, subscriberId, clock);
|
||||
try {
|
||||
final SubscriptionManager.ReceiptResult receiptCredential = subscriptionManager.createReceiptCredentials(
|
||||
final SubscriptionManager.ReceiptResult receiptCredential = subscriptionManager.createReceiptCredential(
|
||||
subscriberCredentials, request.receiptCredentialRequest(),
|
||||
r -> SubscriptionsUtil.receiptExpirationWithGracePeriod(subscriptionConfiguration, r),
|
||||
userAgent);
|
||||
@@ -770,7 +770,7 @@ public class SubscriptionController {
|
||||
.toLowerCase(Locale.ROOT)),
|
||||
UserAgentTagUtil.getPlatformTag(userAgent)))
|
||||
.increment();
|
||||
return Response.ok(new GetReceiptCredentialsResponse(receiptCredentialResponse.serialize())).build();
|
||||
return Response.ok(new GetReceiptCredentialResponse(receiptCredentialResponse.serialize())).build();
|
||||
} catch (SubscriptionReceiptRequestedForOpenPaymentException e) {
|
||||
return Response.noContent().build();
|
||||
}
|
||||
|
||||
+10
-10
@@ -25,8 +25,8 @@ import org.signal.chat.purchase.AmountAboveSepaLimitError;
|
||||
import org.signal.chat.purchase.AmountBelowMinimumError;
|
||||
import org.signal.chat.purchase.ConfirmPayPalBoostRequest;
|
||||
import org.signal.chat.purchase.ConfirmPayPalBoostResponse;
|
||||
import org.signal.chat.purchase.CreateBoostReceiptCredentialsRequest;
|
||||
import org.signal.chat.purchase.CreateBoostReceiptCredentialsResponse;
|
||||
import org.signal.chat.purchase.CreateBoostReceiptCredentialRequest;
|
||||
import org.signal.chat.purchase.CreateBoostReceiptCredentialResponse;
|
||||
import org.signal.chat.purchase.CreateBoostRequest;
|
||||
import org.signal.chat.purchase.CreateBoostResponse;
|
||||
import org.signal.chat.purchase.CreatePayPalBoostRequest;
|
||||
@@ -261,8 +261,8 @@ public class OneTimeDonationsGrpcService extends SimpleOneTimeDonationsGrpc.OneT
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreateBoostReceiptCredentialsResponse createBoostReceiptCredentials(
|
||||
final CreateBoostReceiptCredentialsRequest request) throws IOException {
|
||||
public CreateBoostReceiptCredentialResponse createBoostReceiptCredential(
|
||||
final CreateBoostReceiptCredentialRequest request) throws IOException {
|
||||
|
||||
final PaymentProvider processor = PaymentProvider.fromProto(request.getProcessor())
|
||||
.orElseThrow(() -> GrpcExceptions.fieldViolation("processor", "Unsupported payment processor"));
|
||||
@@ -274,12 +274,12 @@ public class OneTimeDonationsGrpcService extends SimpleOneTimeDonationsGrpc.OneT
|
||||
};
|
||||
|
||||
if (maybePaymentDetails.isEmpty()) {
|
||||
return CreateBoostReceiptCredentialsResponse.newBuilder()
|
||||
return CreateBoostReceiptCredentialResponse.newBuilder()
|
||||
.setPaymentNotFound(NotFound.getDefaultInstance()).build();
|
||||
}
|
||||
final PaymentDetails paymentDetails = maybePaymentDetails.get();
|
||||
if (paymentDetails.status() == PaymentStatus.PROCESSING) {
|
||||
return CreateBoostReceiptCredentialsResponse.newBuilder()
|
||||
return CreateBoostReceiptCredentialResponse.newBuilder()
|
||||
.setPaymentStillProcessing(FailedPrecondition.getDefaultInstance()).build();
|
||||
}
|
||||
if (paymentDetails.status() != PaymentStatus.SUCCEEDED) {
|
||||
@@ -287,7 +287,7 @@ public class OneTimeDonationsGrpcService extends SimpleOneTimeDonationsGrpc.OneT
|
||||
if (paymentDetails.chargeFailure() != null) {
|
||||
paymentRequiredBuilder.setChargeFailure(toChargeFailure(processor, paymentDetails.chargeFailure()));
|
||||
}
|
||||
return CreateBoostReceiptCredentialsResponse.newBuilder()
|
||||
return CreateBoostReceiptCredentialResponse.newBuilder()
|
||||
.setPaymentRequired(paymentRequiredBuilder).build();
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ public class OneTimeDonationsGrpcService extends SimpleOneTimeDonationsGrpc.OneT
|
||||
issuedReceiptsManager.recordOneTimeIssuance(
|
||||
paymentDetails.id(), processor, receiptCredentialRequest, expiration);
|
||||
} catch (final WriteConflictException e) {
|
||||
return CreateBoostReceiptCredentialsResponse.newBuilder()
|
||||
return CreateBoostReceiptCredentialResponse.newBuilder()
|
||||
.setReceiptAlreadyIssued(FailedPrecondition.getDefaultInstance()).build();
|
||||
}
|
||||
|
||||
@@ -336,8 +336,8 @@ public class OneTimeDonationsGrpcService extends SimpleOneTimeDonationsGrpc.OneT
|
||||
UserAgentTagUtil.getPlatformTag(RequestAttributesUtil.getUserAgent().orElse(null))))
|
||||
.increment();
|
||||
|
||||
return CreateBoostReceiptCredentialsResponse.newBuilder()
|
||||
.setResult(CreateBoostReceiptCredentialsResponse.CreateBoostReceiptCredentialsResult.newBuilder()
|
||||
return CreateBoostReceiptCredentialResponse.newBuilder()
|
||||
.setResult(CreateBoostReceiptCredentialResponse.CreateBoostReceiptCredentialResult.newBuilder()
|
||||
.setReceiptCredentialResponse(ByteString.copyFrom(receiptCredentialResponse.serialize()))
|
||||
.build())
|
||||
.build();
|
||||
|
||||
+6
-6
@@ -181,7 +181,7 @@ public class ProfileAnonymousGrpcService extends SimpleProfileAnonymousGrpc.Prof
|
||||
|
||||
try {
|
||||
presentation = new AvatarUploadCredentialPresentation(
|
||||
request.getAvatarCredentialsPresentation().toByteArray());
|
||||
request.getAvatarCredentialPresentation().toByteArray());
|
||||
|
||||
presentation.verify(clock.instant(), this.genericServerSecretParams);
|
||||
|
||||
@@ -190,7 +190,7 @@ public class ProfileAnonymousGrpcService extends SimpleProfileAnonymousGrpc.Prof
|
||||
|
||||
} catch (VerificationFailedException _) {
|
||||
return GetAvatarUploadFormResponse.newBuilder()
|
||||
.setInvalidCredentialsPresentation(FailedZkAuthentication.getDefaultInstance())
|
||||
.setInvalidCredentialPresentation(FailedZkAuthentication.getDefaultInstance())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ public class ProfileAnonymousGrpcService extends SimpleProfileAnonymousGrpc.Prof
|
||||
final AvatarUploadCredentialPresentation presentation;
|
||||
try {
|
||||
presentation = new AvatarUploadCredentialPresentation(
|
||||
request.getAvatarCredentialsPresentation().toByteArray());
|
||||
request.getAvatarCredentialPresentation().toByteArray());
|
||||
} catch (InvalidInputException _) {
|
||||
throw GrpcExceptions.invalidArguments("invalid credential presentation");
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public class ProfileAnonymousGrpcService extends SimpleProfileAnonymousGrpc.Prof
|
||||
|
||||
} catch (VerificationFailedException _) {
|
||||
return ExtendAvatarTTLResponse.newBuilder()
|
||||
.setInvalidCredentialsPresentation(FailedZkAuthentication.getDefaultInstance())
|
||||
.setInvalidCredentialPresentation(FailedZkAuthentication.getDefaultInstance())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public class ProfileAnonymousGrpcService extends SimpleProfileAnonymousGrpc.Prof
|
||||
final AvatarUploadCredentialPresentation presentation;
|
||||
try {
|
||||
presentation = new AvatarUploadCredentialPresentation(
|
||||
request.getAvatarCredentialsPresentation().toByteArray());
|
||||
request.getAvatarCredentialPresentation().toByteArray());
|
||||
} catch (InvalidInputException _) {
|
||||
throw GrpcExceptions.invalidArguments("invalid credential presentation");
|
||||
}
|
||||
@@ -252,7 +252,7 @@ public class ProfileAnonymousGrpcService extends SimpleProfileAnonymousGrpc.Prof
|
||||
|
||||
} catch (VerificationFailedException _) {
|
||||
return DeleteAvatarResponse.newBuilder()
|
||||
.setInvalidCredentialsPresentation(FailedZkAuthentication.getDefaultInstance())
|
||||
.setInvalidCredentialPresentation(FailedZkAuthentication.getDefaultInstance())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.stream.Collectors;
|
||||
import org.signal.chat.common.S3UploadForm;
|
||||
import org.signal.chat.errors.FailedPrecondition;
|
||||
import org.signal.chat.errors.NotFound;
|
||||
import org.signal.chat.profile.GetAvatarCredentialsRequest;
|
||||
import org.signal.chat.profile.GetAvatarCredentialsResponse;
|
||||
import org.signal.chat.profile.GetAvatarCredentialRequest;
|
||||
import org.signal.chat.profile.GetAvatarCredentialResponse;
|
||||
import org.signal.chat.profile.GetProfileRequest;
|
||||
import org.signal.chat.profile.GetProfileResponse;
|
||||
import org.signal.chat.profile.PaymentsForbiddenInRegion;
|
||||
@@ -213,7 +213,7 @@ public class ProfileGrpcService extends SimpleProfileGrpc.ProfileImplBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetAvatarCredentialsResponse getAvatarCredentials(final GetAvatarCredentialsRequest request) {
|
||||
public GetAvatarCredentialResponse getAvatarCredential(final GetAvatarCredentialRequest request) {
|
||||
|
||||
final AuthenticatedDevice authenticatedDevice = AuthenticationUtil.requireAuthenticatedDevice();
|
||||
|
||||
@@ -221,14 +221,14 @@ public class ProfileGrpcService extends SimpleProfileGrpc.ProfileImplBase {
|
||||
.orElseThrow(() -> GrpcExceptions.invalidCredentials("invalid credentials"));
|
||||
|
||||
if (account.getZkCredentialKey().isEmpty()) {
|
||||
return GetAvatarCredentialsResponse.newBuilder()
|
||||
return GetAvatarCredentialResponse.newBuilder()
|
||||
.setMissingZkCredentialKey(FailedPrecondition.newBuilder().setDescription("account requires ZK credential key"))
|
||||
.build();
|
||||
}
|
||||
|
||||
try {
|
||||
final AvatarUploadCredentialRequest credentialRequest = new AvatarUploadCredentialRequest(
|
||||
request.getAvatarCredentialsRequest().toByteArray());
|
||||
request.getAvatarCredentialRequest().toByteArray());
|
||||
|
||||
final AvatarUploadCredentialResponse credentialResponse = credentialRequest.issueCredential(
|
||||
new ServiceId.Aci(account.getAccountIdentifier()),
|
||||
@@ -237,8 +237,8 @@ public class ProfileGrpcService extends SimpleProfileGrpc.ProfileImplBase {
|
||||
clock.instant().truncatedTo(ChronoUnit.DAYS),
|
||||
this.genericServerSecretParams);
|
||||
|
||||
return GetAvatarCredentialsResponse.newBuilder()
|
||||
.setAvatarCredentials(ByteString.copyFrom(credentialResponse.serialize()))
|
||||
return GetAvatarCredentialResponse.newBuilder()
|
||||
.setAvatarCredential(ByteString.copyFrom(credentialResponse.serialize()))
|
||||
.build();
|
||||
} catch (InvalidInputException | VerificationFailedException _) {
|
||||
throw GrpcExceptions.invalidArguments("invalid credential request");
|
||||
|
||||
+14
-15
@@ -5,16 +5,15 @@ import static org.whispersystems.textsecuregcm.grpc.SubscriptionsUtil.getPayPalL
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.Empty;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.time.Clock;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import org.signal.chat.errors.FailedPrecondition;
|
||||
import org.signal.chat.errors.FailedUnidentifiedAuthorization;
|
||||
import org.signal.chat.errors.FailedZkAuthentication;
|
||||
import org.signal.chat.errors.NotFound;
|
||||
import org.signal.chat.purchase.CreatePayPalPaymentMethodRequest;
|
||||
@@ -25,8 +24,8 @@ import org.signal.chat.purchase.DeleteSubscriberRequest;
|
||||
import org.signal.chat.purchase.DeleteSubscriberResponse;
|
||||
import org.signal.chat.purchase.GetBankMandateRequest;
|
||||
import org.signal.chat.purchase.GetBankMandateResponse;
|
||||
import org.signal.chat.purchase.GetReceiptCredentialsRequest;
|
||||
import org.signal.chat.purchase.GetReceiptCredentialsResponse;
|
||||
import org.signal.chat.purchase.GetReceiptCredentialRequest;
|
||||
import org.signal.chat.purchase.GetReceiptCredentialResponse;
|
||||
import org.signal.chat.purchase.GetSubscriptionInformationRequest;
|
||||
import org.signal.chat.purchase.GetSubscriptionInformationResponse;
|
||||
import org.signal.chat.purchase.PaymentRequired;
|
||||
@@ -434,12 +433,12 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetReceiptCredentialsResponse getReceiptCredentials(final GetReceiptCredentialsRequest request)
|
||||
public GetReceiptCredentialResponse getReceiptCredential(final GetReceiptCredentialRequest request)
|
||||
throws RateLimitExceededException {
|
||||
final SubscriberCredentials subscriberCredentials = SubscriberCredentials.process(
|
||||
request.getSubscriberId().toByteArray(), clock);
|
||||
try {
|
||||
final SubscriptionManager.ReceiptResult result = subscriptionManager.createReceiptCredentials(
|
||||
final SubscriptionManager.ReceiptResult result = subscriptionManager.createReceiptCredential(
|
||||
subscriberCredentials, request.getReceiptCredentialRequest().toByteArray(),
|
||||
r -> SubscriptionsUtil.receiptExpirationWithGracePeriod(subscriptionConfiguration, r),
|
||||
RequestAttributesUtil.getUserAgent().orElse(null));
|
||||
@@ -452,27 +451,27 @@ public class SubscriptionsGrpcService extends SimpleSubscriptionsGrpc.Subscripti
|
||||
.toLowerCase(Locale.ROOT)),
|
||||
UserAgentTagUtil.getPlatformTag(RequestAttributesUtil.getUserAgent().orElse(null))))
|
||||
.increment();
|
||||
return GetReceiptCredentialsResponse.newBuilder().setSuccess(
|
||||
GetReceiptCredentialsResponse.GetReceiptCredentialsResult.newBuilder()
|
||||
return GetReceiptCredentialResponse.newBuilder().setSuccess(
|
||||
GetReceiptCredentialResponse.GetReceiptCredentialResult.newBuilder()
|
||||
.setReceiptCredentialResponse(ByteString.copyFrom(result.receiptCredentialResponse().serialize()))
|
||||
.build()).build();
|
||||
} catch (final SubscriptionReceiptRequestedForOpenPaymentException e) {
|
||||
return GetReceiptCredentialsResponse.newBuilder().setNoPaidInvoice(FailedPrecondition.newBuilder().build())
|
||||
return GetReceiptCredentialResponse.newBuilder().setNoPaidInvoice(FailedPrecondition.newBuilder().build())
|
||||
.build();
|
||||
} catch (final SubscriptionChargeFailurePaymentRequiredException e) {
|
||||
return GetReceiptCredentialsResponse.newBuilder().setPaymentRequired(
|
||||
return GetReceiptCredentialResponse.newBuilder().setPaymentRequired(
|
||||
PaymentRequired.newBuilder()
|
||||
.setChargeFailure(SubscriptionsUtil.toChargeFailure(e.getProcessor(), e.getChargeFailure())).build()).build();
|
||||
} catch (final SubscriptionPaymentRequiredException e) {
|
||||
return GetReceiptCredentialsResponse.newBuilder()
|
||||
return GetReceiptCredentialResponse.newBuilder()
|
||||
.setPaymentRequired(PaymentRequired.newBuilder().build()).build();
|
||||
} catch (final SubscriptionInvalidArgumentsException e) {
|
||||
throw GrpcExceptions.invalidArguments(e.errorDetail().orElse(""));
|
||||
} catch (final SubscriptionReceiptAlreadyRedeemedException e) {
|
||||
return GetReceiptCredentialsResponse.newBuilder().setAlreadyRedeemed(FailedPrecondition.newBuilder().build())
|
||||
return GetReceiptCredentialResponse.newBuilder().setAlreadyRedeemed(FailedPrecondition.newBuilder().build())
|
||||
.build();
|
||||
} catch (final SubscriptionNotFoundException | SubscriptionForbiddenException _) {
|
||||
return GetReceiptCredentialsResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder().build()).build();
|
||||
return GetReceiptCredentialResponse.newBuilder().setSubscriberNotFound(NotFound.newBuilder().build()).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -201,7 +201,7 @@ public class SubscriptionManager {
|
||||
* request
|
||||
* @throws RateLimitExceededException if rate-limited
|
||||
*/
|
||||
public ReceiptResult createReceiptCredentials(
|
||||
public ReceiptResult createReceiptCredential(
|
||||
final SubscriberCredentials subscriberCredentials,
|
||||
final byte[] receiptCredentialRequestBytes,
|
||||
final Function<CustomerAwareSubscriptionPaymentProcessor.ReceiptItem, Instant> expiration,
|
||||
|
||||
@@ -16,7 +16,7 @@ import "org/signal/chat/tag.proto";
|
||||
|
||||
service Donations {
|
||||
option (require.auth) = AUTH_ONLY_AUTHENTICATED;
|
||||
// Redeem a receipt acquired from Subscriptions.CreateSubscriptionReceiptCredentials
|
||||
// Redeem a receipt acquired from Subscriptions.GetReceiptCredential
|
||||
// to add a badge to the account. After successful redemption, profile
|
||||
// responses will include the corresponding badge (if configured as visible)
|
||||
// until the expiration time on the receipt.
|
||||
|
||||
@@ -21,7 +21,7 @@ service OneTimeDonations {
|
||||
option (require.auth) = AUTH_ONLY_ANONYMOUS;
|
||||
|
||||
// Create a Stripe payment intent and return a client secret that can be used to complete the payment.
|
||||
// Once the payment is complete, the paymentIntentId can be used with CreateBoostReceiptCredentials
|
||||
// Once the payment is complete, the paymentIntentId can be used with CreateBoostReceiptCredential
|
||||
rpc CreateBoost(CreateBoostRequest) returns (CreateBoostResponse) {}
|
||||
|
||||
// Create a PayPal one-time payment.
|
||||
@@ -41,7 +41,7 @@ service OneTimeDonations {
|
||||
// Obtain a ZK receipt credential for a completed one-time donation payment.
|
||||
// The receipt credential can then be used to redeem the one-time donation entitlement
|
||||
// via Donations.RedeemReceipt
|
||||
rpc CreateBoostReceiptCredentials(CreateBoostReceiptCredentialsRequest) returns (CreateBoostReceiptCredentialsResponse) {}
|
||||
rpc CreateBoostReceiptCredential(CreateBoostReceiptCredentialRequest) returns (CreateBoostReceiptCredentialResponse) {}
|
||||
}
|
||||
|
||||
// The amount is below the minimum for the currency.
|
||||
@@ -149,7 +149,7 @@ message ConfirmPayPalBoostResponse {
|
||||
}
|
||||
}
|
||||
|
||||
message CreateBoostReceiptCredentialsRequest {
|
||||
message CreateBoostReceiptCredentialRequest {
|
||||
// a payment ID from the processor
|
||||
string payment_intent_id = 1 [(require.nonEmpty) = true];
|
||||
// ZK blind-signature receipt credential request bytes
|
||||
@@ -158,12 +158,12 @@ message CreateBoostReceiptCredentialsRequest {
|
||||
PaymentProvider processor = 3 [(require.specified) = true];
|
||||
}
|
||||
|
||||
message CreateBoostReceiptCredentialsResponse {
|
||||
message CreateBoostReceiptCredentialsResult {
|
||||
message CreateBoostReceiptCredentialResponse {
|
||||
message CreateBoostReceiptCredentialResult {
|
||||
bytes receipt_credential_response = 1;
|
||||
}
|
||||
oneof response {
|
||||
CreateBoostReceiptCredentialsResult result = 1;
|
||||
CreateBoostReceiptCredentialResult result = 1;
|
||||
// Payment is still processing; client should retry
|
||||
errors.FailedPrecondition payment_still_processing = 2 [(tag.reason) = "payment_still_processing"];
|
||||
// Payment failed
|
||||
|
||||
@@ -20,19 +20,19 @@ import "org/signal/chat/tag.proto";
|
||||
service Profile {
|
||||
option (require.auth) = AUTH_ONLY_AUTHENTICATED;
|
||||
|
||||
// Sets profile data and, if needed, returns credentials used by clients to upload a v1 avatar.
|
||||
// Sets profile data and, if needed, returns a credential used by clients to upload a v1 avatar.
|
||||
rpc SetProfile(SetProfileRequest) returns (SetProfileResponse) {}
|
||||
|
||||
// Retrieves profile data. Callers with an unidentified access key for the account
|
||||
// should use the version of this method in `ProfileAnonymous` instead.
|
||||
rpc GetProfile(GetProfileRequest) returns (GetProfileResponse) {}
|
||||
|
||||
// Returns anonymous credentials that may be presented with avatar operations in ProfilesAnonymous
|
||||
// Returns an anonymous credential that may be presented with avatar operations in ProfilesAnonymous
|
||||
//
|
||||
// Note: `Accounts.SetZkCredentialKey` is a pre-requisite for this RPC
|
||||
rpc GetAvatarCredentials(GetAvatarCredentialsRequest) returns (GetAvatarCredentialsResponse) {}
|
||||
rpc GetAvatarCredential(GetAvatarCredentialRequest) returns (GetAvatarCredentialResponse) {}
|
||||
|
||||
// Returns credentials used by clients to upload a v1 avatar, deleting any current avatar.
|
||||
// Returns a credential used by clients to upload a v1 avatar, deleting any current avatar.
|
||||
//
|
||||
// This RPC streamlines avatar changes during the v1 -> v2 transition by minimizing uploads:
|
||||
// 1. SetV1Avatar
|
||||
@@ -59,14 +59,14 @@ service ProfileAnonymous {
|
||||
// Retrieves a profile key credential.
|
||||
rpc GetExpiringProfileKeyCredential(GetExpiringProfileKeyCredentialRequest) returns (GetExpiringProfileKeyCredentialResponse) {}
|
||||
|
||||
// Returns credentials to upload a v2 avatar. After uploading the avatar, the client
|
||||
// Returns a credential to upload a v2 avatar. After uploading the avatar, the client
|
||||
// must call SetProfile with the new avatar URL in the encrypted `data`.
|
||||
//
|
||||
// Because avatars are uploaded anonymously, they have an expiration equal to the
|
||||
// idle account expiration. Clients must periodically (recommended: every 90 days)
|
||||
// call ExtendAvatarTTL to extend the TTl.
|
||||
//
|
||||
// Note: any existing avatar associated with these credentials will be deleted immediately
|
||||
// Note: any existing avatar associated with this credential will be deleted immediately
|
||||
rpc GetAvatarUploadForm(GetAvatarUploadFormRequest) returns (GetAvatarUploadFormResponse) {}
|
||||
|
||||
// Extends the TTL of the avatar currently associated with the request’s avatar auth credential
|
||||
@@ -366,13 +366,13 @@ enum CredentialType {
|
||||
|
||||
// avatar auth
|
||||
|
||||
message GetAvatarCredentialsRequest {
|
||||
bytes avatar_credentials_request = 1;
|
||||
message GetAvatarCredentialRequest {
|
||||
bytes avatar_credential_request = 1;
|
||||
}
|
||||
|
||||
message GetAvatarCredentialsResponse {
|
||||
message GetAvatarCredentialResponse {
|
||||
oneof response {
|
||||
bytes avatar_credentials = 1;
|
||||
bytes avatar_credential = 1;
|
||||
|
||||
// the client must call Accounts.SetZkCredentialKey to call this method
|
||||
errors.FailedPrecondition missing_zk_credential_key = 2 [(tag.reason) = "missing_zk_credential_key"];
|
||||
@@ -380,7 +380,7 @@ message GetAvatarCredentialsResponse {
|
||||
}
|
||||
|
||||
message GetAvatarUploadFormRequest {
|
||||
bytes avatar_credentials_presentation = 1;
|
||||
bytes avatar_credential_presentation = 1;
|
||||
|
||||
// The length of the attachment for the requested upload form. Uploads
|
||||
// performed with this form will be limited to the provided length.
|
||||
@@ -392,31 +392,31 @@ message GetAvatarUploadFormResponse {
|
||||
// the policy and credential used by clients to upload an avatar to the CDN
|
||||
common.S3UploadForm avatar_upload_form = 1;
|
||||
|
||||
errors.FailedZkAuthentication invalid_credentials_presentation = 2 [(tag.reason) = "invalid_credentials_presentation"];
|
||||
errors.FailedZkAuthentication invalid_credential_presentation = 2 [(tag.reason) = "invalid_credential_presentation"];
|
||||
}
|
||||
}
|
||||
|
||||
message ExtendAvatarTTLRequest {
|
||||
bytes avatar_credentials_presentation = 1;
|
||||
bytes avatar_credential_presentation = 1;
|
||||
}
|
||||
|
||||
message ExtendAvatarTTLResponse {
|
||||
oneof response {
|
||||
// The avatar that was extended. May be used as a check against state de-synchronization.
|
||||
string path = 1;
|
||||
errors.FailedZkAuthentication invalid_credentials_presentation = 2 [(tag.reason) = "invalid_credentials_presentation"];
|
||||
errors.FailedZkAuthentication invalid_credential_presentation = 2 [(tag.reason) = "invalid_credential_presentation"];
|
||||
// the identity does not have an active avatar
|
||||
errors.NotFound not_found = 3 [(tag.reason) = "no_active_avatar"];
|
||||
}
|
||||
}
|
||||
|
||||
message DeleteAvatarRequest {
|
||||
bytes avatar_credentials_presentation = 1;
|
||||
bytes avatar_credential_presentation = 1;
|
||||
}
|
||||
|
||||
message DeleteAvatarResponse {
|
||||
oneof response {
|
||||
google.protobuf.Empty success = 1;
|
||||
errors.FailedZkAuthentication invalid_credentials_presentation = 2 [(tag.reason) = "invalid_credentials_presentation"];
|
||||
errors.FailedZkAuthentication invalid_credential_presentation = 2 [(tag.reason) = "invalid_credential_presentation"];
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ service Subscriptions {
|
||||
// invoice. Clients SHOULD retry requests at this endpoint with the same ReceiptCredentialRequest value until
|
||||
// receiving a response. After receiving a response, clients should then compute the ReceiptCredentialPresentation
|
||||
// and redeem it at the receipt redemption endpoint. Once the first attempt is made there, the same
|
||||
// ReceiptCredentialRequest MUST NOT be used again to request receipt credentials.
|
||||
// ReceiptCredentialRequest MUST NOT be used again to request a receipt credential.
|
||||
//
|
||||
// Note that you may in fact redeem TWO or more invoices for the same ReceiptCredentialRequest while retrying this
|
||||
// operation if a later invoice gets paid while you are retrying. However, the returned receipt is always for the
|
||||
@@ -75,7 +75,7 @@ service Subscriptions {
|
||||
// cannot be redeemed.
|
||||
//
|
||||
// Clients MUST validate that the generated receipt credential's level and expiration matches their expectations.
|
||||
rpc GetReceiptCredentials(GetReceiptCredentialsRequest) returns (GetReceiptCredentialsResponse) {}
|
||||
rpc GetReceiptCredential(GetReceiptCredentialRequest) returns (GetReceiptCredentialResponse) {}
|
||||
|
||||
// Set a token that represents an IAP subscription made with App Store/Google Play Billing.
|
||||
//
|
||||
@@ -84,7 +84,7 @@ service Subscriptions {
|
||||
// 2. [Create a subscription](https://developer.apple.com/documentation/storekit/in-app_purchase/) with the App Store
|
||||
// directly via StoreKit and obtain a originalTransactionId.
|
||||
// 3. Call this RPC with the originalTransactionId
|
||||
// 4. Obtain a receipt via GetReceiptCredentials which can then be used to obtain the
|
||||
// 4. Obtain a receipt via GetReceiptCredential which can then be used to obtain the
|
||||
// entitlement
|
||||
//
|
||||
// Play Billing: Set a purchaseToken that represents an IAP subscription made with Google Play Billing.
|
||||
@@ -95,7 +95,7 @@ service Subscriptions {
|
||||
// directly and obtain a purchaseToken. Do not [acknowledge](https://developer.android.com/google/play/billing/integrate#subscriptions)
|
||||
// the purchaseToken.
|
||||
// 3. Call this RPC with the purchaseToken
|
||||
// 4. Obtain a receipt via GetReceiptCredentials which can then be used to obtain the
|
||||
// 4. Obtain a receipt via GetReceiptCredential which can then be used to obtain the
|
||||
// entitlement
|
||||
//
|
||||
// After calling this method, the payment is confirmed. Callers must durably store their subscriberId before calling
|
||||
@@ -374,18 +374,18 @@ message SetIapSubscriptionResponse {
|
||||
}
|
||||
}
|
||||
|
||||
message GetReceiptCredentialsRequest {
|
||||
message GetReceiptCredentialRequest {
|
||||
bytes subscriberId = 1 [(require.exactlySize) = 32];
|
||||
bytes receiptCredentialRequest = 2 [(require.exactlySize) = 97];
|
||||
}
|
||||
|
||||
message GetReceiptCredentialsResponse {
|
||||
message GetReceiptCredentialsResult {
|
||||
message GetReceiptCredentialResponse {
|
||||
message GetReceiptCredentialResult {
|
||||
bytes receiptCredentialResponse = 1;
|
||||
}
|
||||
|
||||
oneof response {
|
||||
GetReceiptCredentialsResult success = 1;
|
||||
GetReceiptCredentialResult success = 1;
|
||||
// The subscriber did not exist or it did not have an associated subscription
|
||||
errors.NotFound subscriber_not_found = 2 [(tag.reason) = "subscriber_not_found"];
|
||||
// No invoice has been issued for this subscription OR invoice is in 'draft' or 'open' state
|
||||
|
||||
+1
-1
@@ -276,7 +276,7 @@ class OneTimeDonationControllerTest extends AbstractV1SubscriptionControllerTest
|
||||
assertThat(response.getStatus()).isEqualTo(402);
|
||||
|
||||
if (expectChargeFailure) {
|
||||
assertThat(response.readEntity(OneTimeDonationController.CreateBoostReceiptCredentialsErrorResponse.class)
|
||||
assertThat(response.readEntity(OneTimeDonationController.CreateBoostReceiptCredentialErrorResponse.class)
|
||||
.chargeFailure()).isEqualTo(chargeFailure);
|
||||
} else {
|
||||
assertThat(response.readEntity(String.class)).isEqualTo("{}");
|
||||
|
||||
+3
-3
@@ -835,7 +835,7 @@ class SubscriptionControllerTest extends AbstractV1SubscriptionControllerTest {
|
||||
try (Response response = RESOURCE_EXTENSION
|
||||
.target(String.format("/v1/subscription/%s/receipt_credentials", subscriberId))
|
||||
.request()
|
||||
.post(Entity.json(new SubscriptionController.GetReceiptCredentialsRequest(receiptRequest.serialize())))) {
|
||||
.post(Entity.json(new SubscriptionController.GetReceiptCredentialRequest(receiptRequest.serialize())))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(402);
|
||||
responseMap = response.readEntity(Map.class);
|
||||
@@ -876,7 +876,7 @@ class SubscriptionControllerTest extends AbstractV1SubscriptionControllerTest {
|
||||
try (Response response = RESOURCE_EXTENSION
|
||||
.target(String.format("/v1/subscription/%s/receipt_credentials", subscriberId))
|
||||
.request()
|
||||
.post(Entity.json(new SubscriptionController.GetReceiptCredentialsRequest(receiptRequest.serialize())))) {
|
||||
.post(Entity.json(new SubscriptionController.GetReceiptCredentialRequest(receiptRequest.serialize())))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(409);
|
||||
}
|
||||
@@ -917,7 +917,7 @@ class SubscriptionControllerTest extends AbstractV1SubscriptionControllerTest {
|
||||
try (Response response = RESOURCE_EXTENSION
|
||||
.target(String.format("/v1/subscription/%s/receipt_credentials", subscriberId))
|
||||
.request()
|
||||
.post(Entity.json(new SubscriptionController.GetReceiptCredentialsRequest(receiptRequest.serialize())))) {
|
||||
.post(Entity.json(new SubscriptionController.GetReceiptCredentialRequest(receiptRequest.serialize())))) {
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -32,8 +32,8 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.Mock;
|
||||
import org.signal.chat.purchase.ConfirmPayPalBoostRequest;
|
||||
import org.signal.chat.purchase.ConfirmPayPalBoostResponse;
|
||||
import org.signal.chat.purchase.CreateBoostReceiptCredentialsRequest;
|
||||
import org.signal.chat.purchase.CreateBoostReceiptCredentialsResponse;
|
||||
import org.signal.chat.purchase.CreateBoostReceiptCredentialRequest;
|
||||
import org.signal.chat.purchase.CreateBoostReceiptCredentialResponse;
|
||||
import org.signal.chat.purchase.CreateBoostRequest;
|
||||
import org.signal.chat.purchase.CreateBoostResponse;
|
||||
import org.signal.chat.purchase.CreatePayPalBoostRequest;
|
||||
@@ -268,22 +268,22 @@ public class OneTimeDonationsGrpcServiceTest extends
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void createBoostReceiptCredentialsPaymentRequired(
|
||||
void createBoostReceiptCredentialPaymentRequired(
|
||||
@Nullable final ChargeFailure chargeFailure,
|
||||
final boolean expectChargeFailure) throws IOException {
|
||||
when(stripeManager.claimOneTimePurchase(any())).thenReturn(
|
||||
Optional.of(new PaymentDetails("id", null, PaymentStatus.FAILED,
|
||||
clock.instant(), chargeFailure)));
|
||||
|
||||
final CreateBoostReceiptCredentialsResponse response =
|
||||
unauthenticatedServiceStub().createBoostReceiptCredentials(
|
||||
CreateBoostReceiptCredentialsRequest.newBuilder()
|
||||
final CreateBoostReceiptCredentialResponse response =
|
||||
unauthenticatedServiceStub().createBoostReceiptCredential(
|
||||
CreateBoostReceiptCredentialRequest.newBuilder()
|
||||
.setPaymentIntentId("test-payment-intent-id")
|
||||
.setReceiptCredentialRequest(ByteString.copyFromUtf8("abcd"))
|
||||
.setProcessor(PaymentProvider.PAYMENT_PROVIDER_STRIPE)
|
||||
.build());
|
||||
|
||||
assertEquals(CreateBoostReceiptCredentialsResponse.ResponseCase.PAYMENT_REQUIRED,
|
||||
assertEquals(CreateBoostReceiptCredentialResponse.ResponseCase.PAYMENT_REQUIRED,
|
||||
response.getResponseCase());
|
||||
if (expectChargeFailure) {
|
||||
assertEquals("generic_decline", response.getPaymentRequired().getChargeFailure().getCode());
|
||||
@@ -292,7 +292,7 @@ public class OneTimeDonationsGrpcServiceTest extends
|
||||
}
|
||||
}
|
||||
|
||||
static Stream<Arguments> createBoostReceiptCredentialsPaymentRequired() {
|
||||
static Stream<Arguments> createBoostReceiptCredentialPaymentRequired() {
|
||||
return Stream.of(
|
||||
Arguments.of(new ChargeFailure("generic_decline", "some failure message", null, null, null), true),
|
||||
Arguments.of(null, false)
|
||||
@@ -300,7 +300,7 @@ public class OneTimeDonationsGrpcServiceTest extends
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBoostReceiptCredentialsAlreadyRedeemed() throws Exception {
|
||||
void createBoostReceiptCredentialAlreadyRedeemed() throws Exception {
|
||||
final ReceiptCredentialRequest receiptCredentialRequest = new ClientZkReceiptOperations(
|
||||
ServerSecretParams.generate().getPublicParams()).createReceiptCredentialRequestContext(
|
||||
new ReceiptSerial(new byte[ReceiptSerial.SIZE])).getRequest();
|
||||
@@ -312,15 +312,15 @@ public class OneTimeDonationsGrpcServiceTest extends
|
||||
doThrow(WriteConflictException.class).when(issuedReceiptsManager)
|
||||
.recordOneTimeIssuance(any(), any(), any(), any());
|
||||
|
||||
final CreateBoostReceiptCredentialsResponse response =
|
||||
unauthenticatedServiceStub().createBoostReceiptCredentials(
|
||||
CreateBoostReceiptCredentialsRequest.newBuilder()
|
||||
final CreateBoostReceiptCredentialResponse response =
|
||||
unauthenticatedServiceStub().createBoostReceiptCredential(
|
||||
CreateBoostReceiptCredentialRequest.newBuilder()
|
||||
.setPaymentIntentId("test-payment-intent-id")
|
||||
.setReceiptCredentialRequest(ByteString.copyFrom(receiptCredentialRequest.serialize()))
|
||||
.setProcessor(PaymentProvider.PAYMENT_PROVIDER_STRIPE)
|
||||
.build());
|
||||
|
||||
assertEquals(CreateBoostReceiptCredentialsResponse.ResponseCase.RECEIPT_ALREADY_ISSUED,
|
||||
assertEquals(CreateBoostReceiptCredentialResponse.ResponseCase.RECEIPT_ALREADY_ISSUED,
|
||||
response.getResponseCase());
|
||||
}
|
||||
|
||||
|
||||
+15
-15
@@ -691,7 +691,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
genericServerSecretParams, clock);
|
||||
|
||||
final GetAvatarUploadFormRequest request = GetAvatarUploadFormRequest.newBuilder()
|
||||
.setAvatarCredentialsPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setAvatarCredentialPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setUploadLength(100)
|
||||
.build();
|
||||
|
||||
@@ -711,7 +711,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
genericServerSecretParams, clock);
|
||||
|
||||
final GetAvatarUploadFormRequest request = GetAvatarUploadFormRequest.newBuilder()
|
||||
.setAvatarCredentialsPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setAvatarCredentialPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setUploadLength(Math.toIntExact(ProfileHelper.MAX_PROFILE_AVATAR_SIZE_BYTES + 1))
|
||||
.build();
|
||||
|
||||
@@ -726,12 +726,12 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAvatarUploadFormInvalidCredentialsPresentation() throws Exception {
|
||||
void getAvatarUploadFormInvalidCredentialPresentation() throws Exception {
|
||||
final AvatarUploadCredentialPresentation avatarUploadCredentialPresentation = getAvatarUploadCredentialPresentation(
|
||||
genericServerSecretParams, clock);
|
||||
|
||||
final GetAvatarUploadFormRequest request = GetAvatarUploadFormRequest.newBuilder()
|
||||
.setAvatarCredentialsPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setAvatarCredentialPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setUploadLength(100)
|
||||
.build();
|
||||
|
||||
@@ -740,7 +740,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
|
||||
final GetAvatarUploadFormResponse response = authenticatedServiceStub().getAvatarUploadForm(request);
|
||||
|
||||
assertTrue(response.hasInvalidCredentialsPresentation());
|
||||
assertTrue(response.hasInvalidCredentialPresentation());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -753,7 +753,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
.when(profileAvatarBytesRateLimiter).validate(anyString(), anyLong());
|
||||
|
||||
final GetAvatarUploadFormRequest request = GetAvatarUploadFormRequest.newBuilder()
|
||||
.setAvatarCredentialsPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setAvatarCredentialPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setUploadLength(100)
|
||||
.build();
|
||||
|
||||
@@ -771,7 +771,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
genericServerSecretParams, clock);
|
||||
|
||||
final ExtendAvatarTTLRequest request = ExtendAvatarTTLRequest.newBuilder()
|
||||
.setAvatarCredentialsPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setAvatarCredentialPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.build();
|
||||
|
||||
final ExtendAvatarTTLResponse response = authenticatedServiceStub().extendAvatarTTL(request);
|
||||
@@ -789,7 +789,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
genericServerSecretParams, clock);
|
||||
|
||||
final ExtendAvatarTTLRequest request = ExtendAvatarTTLRequest.newBuilder()
|
||||
.setAvatarCredentialsPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setAvatarCredentialPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.build();
|
||||
|
||||
|
||||
@@ -799,12 +799,12 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
}
|
||||
|
||||
@Test
|
||||
void extendAvatarTtlInvalidCredentialsPresentation() throws Exception {
|
||||
void extendAvatarTtlInvalidCredentialPresentation() throws Exception {
|
||||
final AvatarUploadCredentialPresentation avatarUploadCredentialPresentation = getAvatarUploadCredentialPresentation(
|
||||
genericServerSecretParams, clock);
|
||||
|
||||
final ExtendAvatarTTLRequest request = ExtendAvatarTTLRequest.newBuilder()
|
||||
.setAvatarCredentialsPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setAvatarCredentialPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.build();
|
||||
|
||||
// trigger a verification failure by advancing the clock beyond validity
|
||||
@@ -812,7 +812,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
|
||||
final ExtendAvatarTTLResponse response = authenticatedServiceStub().extendAvatarTTL(request);
|
||||
|
||||
assertTrue(response.hasInvalidCredentialsPresentation());
|
||||
assertTrue(response.hasInvalidCredentialPresentation());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -821,7 +821,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
genericServerSecretParams, clock);
|
||||
|
||||
final DeleteAvatarRequest request = DeleteAvatarRequest.newBuilder()
|
||||
.setAvatarCredentialsPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setAvatarCredentialPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.build();
|
||||
|
||||
final DeleteAvatarResponse response = authenticatedServiceStub().deleteAvatar(request);
|
||||
@@ -832,12 +832,12 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAvatarInvalidCredentialsPresentation() throws Exception {
|
||||
void deleteAvatarInvalidCredentialPresentation() throws Exception {
|
||||
final AvatarUploadCredentialPresentation avatarUploadCredentialPresentation = getAvatarUploadCredentialPresentation(
|
||||
genericServerSecretParams, clock);
|
||||
|
||||
final DeleteAvatarRequest request = DeleteAvatarRequest.newBuilder()
|
||||
.setAvatarCredentialsPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.setAvatarCredentialPresentation(ByteString.copyFrom(avatarUploadCredentialPresentation.serialize()))
|
||||
.build();
|
||||
|
||||
// trigger a verification failure by advancing the clock beyond validity
|
||||
@@ -845,7 +845,7 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
|
||||
final DeleteAvatarResponse response = authenticatedServiceStub().deleteAvatar(request);
|
||||
|
||||
assertTrue(response.hasInvalidCredentialsPresentation());
|
||||
assertTrue(response.hasInvalidCredentialPresentation());
|
||||
}
|
||||
|
||||
static AvatarUploadCredentialPresentation getAvatarUploadCredentialPresentation(final GenericServerSecretParams serverSecretParams, final Clock clock) throws VerificationFailedException {
|
||||
|
||||
+13
-13
@@ -60,8 +60,8 @@ import org.mockito.Mock;
|
||||
import org.signal.chat.common.IdentityType;
|
||||
import org.signal.chat.common.ServiceIdentifier;
|
||||
import org.signal.chat.profile.AccountInfo;
|
||||
import org.signal.chat.profile.GetAvatarCredentialsRequest;
|
||||
import org.signal.chat.profile.GetAvatarCredentialsResponse;
|
||||
import org.signal.chat.profile.GetAvatarCredentialRequest;
|
||||
import org.signal.chat.profile.GetAvatarCredentialResponse;
|
||||
import org.signal.chat.profile.GetProfileRequest;
|
||||
import org.signal.chat.profile.GetProfileResponse;
|
||||
import org.signal.chat.profile.LegacyProfileResult;
|
||||
@@ -847,15 +847,15 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest<ProfileGrpcServic
|
||||
new ServiceId.Aci(AUTHENTICATED_ACI), zkCredentialKeyPair, rotationId);
|
||||
final AvatarUploadCredentialRequest credentialRequest = avatarUploadCredentialRequestContext.getRequest();
|
||||
|
||||
final GetAvatarCredentialsResponse response = authenticatedServiceStub().getAvatarCredentials(
|
||||
GetAvatarCredentialsRequest.newBuilder()
|
||||
.setAvatarCredentialsRequest(ByteString.copyFrom(credentialRequest.serialize()))
|
||||
final GetAvatarCredentialResponse response = authenticatedServiceStub().getAvatarCredential(
|
||||
GetAvatarCredentialRequest.newBuilder()
|
||||
.setAvatarCredentialRequest(ByteString.copyFrom(credentialRequest.serialize()))
|
||||
.build());
|
||||
|
||||
assertTrue(response.hasAvatarCredentials());
|
||||
assertTrue(response.hasAvatarCredential());
|
||||
|
||||
assertDoesNotThrow(() -> avatarUploadCredentialRequestContext.receiveResponse(
|
||||
new AvatarUploadCredentialResponse(response.getAvatarCredentials().toByteArray()),
|
||||
new AvatarUploadCredentialResponse(response.getAvatarCredential().toByteArray()),
|
||||
genericServerSecretParams.getPublicParams()));
|
||||
}
|
||||
|
||||
@@ -864,7 +864,7 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest<ProfileGrpcServic
|
||||
when(accountsManager.getByAccountIdentifier(AUTHENTICATED_ACI)).thenReturn(Optional.empty());
|
||||
|
||||
final StatusRuntimeException statusRuntimeException = assertStatusException(Status.UNAUTHENTICATED,
|
||||
() -> authenticatedServiceStub().getAvatarCredentials(GetAvatarCredentialsRequest.getDefaultInstance()));
|
||||
() -> authenticatedServiceStub().getAvatarCredential(GetAvatarCredentialRequest.getDefaultInstance()));
|
||||
assertEquals("invalid credentials", statusRuntimeException.getStatus().getDescription());
|
||||
}
|
||||
|
||||
@@ -872,8 +872,8 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest<ProfileGrpcServic
|
||||
void getAvatarCredentialMissingZkCredentialKey() {
|
||||
when(account.getZkCredentialKey()).thenReturn(Optional.empty());
|
||||
|
||||
final GetAvatarCredentialsResponse response = authenticatedServiceStub().getAvatarCredentials(
|
||||
GetAvatarCredentialsRequest.getDefaultInstance());
|
||||
final GetAvatarCredentialResponse response = authenticatedServiceStub().getAvatarCredential(
|
||||
GetAvatarCredentialRequest.getDefaultInstance());
|
||||
|
||||
assertTrue(response.hasMissingZkCredentialKey());
|
||||
|
||||
@@ -897,9 +897,9 @@ public class ProfileGrpcServiceTest extends SimpleBaseGrpcTest<ProfileGrpcServic
|
||||
final AvatarUploadCredentialRequest credentialRequest = avatarUploadCredentialRequestContext.getRequest();
|
||||
|
||||
final StatusRuntimeException statusRuntimeException = assertStatusInvalidArgument(
|
||||
() -> authenticatedServiceStub().getAvatarCredentials(
|
||||
GetAvatarCredentialsRequest.newBuilder()
|
||||
.setAvatarCredentialsRequest(ByteString.copyFrom(credentialRequest.serialize()))
|
||||
() -> authenticatedServiceStub().getAvatarCredential(
|
||||
GetAvatarCredentialRequest.newBuilder()
|
||||
.setAvatarCredentialRequest(ByteString.copyFrom(credentialRequest.serialize()))
|
||||
.build()));
|
||||
|
||||
assertEquals("invalid credential request", statusRuntimeException.getStatus().getDescription());
|
||||
|
||||
+21
-21
@@ -42,8 +42,8 @@ import org.signal.chat.purchase.DeleteSubscriberRequest;
|
||||
import org.signal.chat.purchase.DeleteSubscriberResponse;
|
||||
import org.signal.chat.purchase.GetBankMandateRequest;
|
||||
import org.signal.chat.purchase.GetBankMandateResponse;
|
||||
import org.signal.chat.purchase.GetReceiptCredentialsRequest;
|
||||
import org.signal.chat.purchase.GetReceiptCredentialsResponse;
|
||||
import org.signal.chat.purchase.GetReceiptCredentialRequest;
|
||||
import org.signal.chat.purchase.GetReceiptCredentialResponse;
|
||||
import org.signal.chat.purchase.GetSubscriptionInformationRequest;
|
||||
import org.signal.chat.purchase.GetSubscriptionInformationResponse;
|
||||
import org.signal.chat.purchase.PaymentMethod;
|
||||
@@ -569,39 +569,39 @@ public class SubscriptionsGrpcServiceTest extends
|
||||
}
|
||||
|
||||
@Test
|
||||
void getReceiptCredentials() throws Exception {
|
||||
void getReceiptCredential() throws Exception {
|
||||
final ReceiptCredentialResponse receiptCredentialResponse = mock(ReceiptCredentialResponse.class);
|
||||
final byte[] responseBytes = TestRandomUtil.nextBytes(16);
|
||||
when(receiptCredentialResponse.serialize()).thenReturn(responseBytes);
|
||||
when(subscriptionManager.createReceiptCredentials(any(), any(), any(), any()))
|
||||
when(subscriptionManager.createReceiptCredential(any(), any(), any(), any()))
|
||||
.thenReturn(new SubscriptionManager.ReceiptResult(receiptCredentialResponse, new SubscriptionPaymentProcessor.ReceiptItem("test-item-id", null, 5), PaymentProvider.STRIPE));
|
||||
final GetReceiptCredentialsResponse response = unauthenticatedServiceStub().getReceiptCredentials(
|
||||
GetReceiptCredentialsRequest.newBuilder()
|
||||
final GetReceiptCredentialResponse response = unauthenticatedServiceStub().getReceiptCredential(
|
||||
GetReceiptCredentialRequest.newBuilder()
|
||||
.setSubscriberId(SUBSCRIBER_ID)
|
||||
.setReceiptCredentialRequest(ByteString.copyFrom(TestRandomUtil.nextBytes(97)))
|
||||
.build());
|
||||
assertEquals(GetReceiptCredentialsResponse.ResponseCase.SUCCESS, response.getResponseCase());
|
||||
assertEquals(GetReceiptCredentialResponse.ResponseCase.SUCCESS, response.getResponseCase());
|
||||
assertArrayEquals(responseBytes, response.getSuccess().getReceiptCredentialResponse().toByteArray());
|
||||
}
|
||||
|
||||
static Stream<Arguments> getReceiptCredentialsExceptions() {
|
||||
static Stream<Arguments> getReceiptCredentialExceptions() {
|
||||
return Stream.of(
|
||||
Arguments.of(new SubscriptionReceiptRequestedForOpenPaymentException(),
|
||||
GetReceiptCredentialsResponse.ResponseCase.NO_PAID_INVOICE),
|
||||
GetReceiptCredentialResponse.ResponseCase.NO_PAID_INVOICE),
|
||||
Arguments.of(new SubscriptionPaymentRequiredException(),
|
||||
GetReceiptCredentialsResponse.ResponseCase.PAYMENT_REQUIRED),
|
||||
GetReceiptCredentialResponse.ResponseCase.PAYMENT_REQUIRED),
|
||||
Arguments.of(new SubscriptionReceiptAlreadyRedeemedException(),
|
||||
GetReceiptCredentialsResponse.ResponseCase.ALREADY_REDEEMED)
|
||||
GetReceiptCredentialResponse.ResponseCase.ALREADY_REDEEMED)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void getReceiptCredentialsExceptions(final SubscriptionException exception,
|
||||
final GetReceiptCredentialsResponse.ResponseCase expectedCase) throws Exception {
|
||||
doThrow(exception).when(subscriptionManager).createReceiptCredentials(any(), any(), any(), any());
|
||||
final GetReceiptCredentialsResponse response = unauthenticatedServiceStub().getReceiptCredentials(
|
||||
GetReceiptCredentialsRequest.newBuilder()
|
||||
void getReceiptCredentialExceptions(final SubscriptionException exception,
|
||||
final GetReceiptCredentialResponse.ResponseCase expectedCase) throws Exception {
|
||||
doThrow(exception).when(subscriptionManager).createReceiptCredential(any(), any(), any(), any());
|
||||
final GetReceiptCredentialResponse response = unauthenticatedServiceStub().getReceiptCredential(
|
||||
GetReceiptCredentialRequest.newBuilder()
|
||||
.setSubscriberId(SUBSCRIBER_ID)
|
||||
.setReceiptCredentialRequest(ByteString.copyFrom(TestRandomUtil.nextBytes(97)))
|
||||
.build());
|
||||
@@ -609,16 +609,16 @@ public class SubscriptionsGrpcServiceTest extends
|
||||
}
|
||||
|
||||
@Test
|
||||
void getReceiptCredentialsChargeFailure() throws Exception {
|
||||
void getReceiptCredentialChargeFailure() throws Exception {
|
||||
doThrow(new SubscriptionChargeFailurePaymentRequiredException(PaymentProvider.STRIPE,
|
||||
new ChargeFailure("card_declined", "Insufficient funds", null, null, null)))
|
||||
.when(subscriptionManager).createReceiptCredentials(any(), any(), any(), any());
|
||||
final GetReceiptCredentialsResponse response = unauthenticatedServiceStub().getReceiptCredentials(
|
||||
GetReceiptCredentialsRequest.newBuilder()
|
||||
.when(subscriptionManager).createReceiptCredential(any(), any(), any(), any());
|
||||
final GetReceiptCredentialResponse response = unauthenticatedServiceStub().getReceiptCredential(
|
||||
GetReceiptCredentialRequest.newBuilder()
|
||||
.setSubscriberId(SUBSCRIBER_ID)
|
||||
.setReceiptCredentialRequest(ByteString.copyFrom(TestRandomUtil.nextBytes(97)))
|
||||
.build());
|
||||
assertEquals(GetReceiptCredentialsResponse.ResponseCase.PAYMENT_REQUIRED, response.getResponseCase());
|
||||
assertEquals(GetReceiptCredentialResponse.ResponseCase.PAYMENT_REQUIRED, response.getResponseCase());
|
||||
assertEquals(org.signal.chat.purchase.PaymentProvider.PAYMENT_PROVIDER_STRIPE,
|
||||
response.getPaymentRequired().getChargeFailure().getProcessor());
|
||||
assertEquals("card_declined", response.getPaymentRequired().getChargeFailure().getCode());
|
||||
|
||||
Reference in new issue
Block a user