Get accounts asynchronously when checking SVR credentials via gRPC
This commit is contained in:
parent
d18f576239
commit
bf05e47e26
|
@ -24,6 +24,7 @@ import org.whispersystems.textsecuregcm.storage.Account;
|
||||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
import reactor.util.function.Tuples;
|
||||||
|
|
||||||
public class ExternalServiceCredentialsAnonymousGrpcService extends
|
public class ExternalServiceCredentialsAnonymousGrpcService extends
|
||||||
ReactorExternalServiceCredentialsAnonymousGrpc.ExternalServiceCredentialsAnonymousImplBase {
|
ReactorExternalServiceCredentialsAnonymousGrpc.ExternalServiceCredentialsAnonymousImplBase {
|
||||||
|
@ -60,15 +61,17 @@ public class ExternalServiceCredentialsAnonymousGrpcService extends
|
||||||
svrCredentialsGenerator,
|
svrCredentialsGenerator,
|
||||||
MAX_SVR_PASSWORD_AGE_SECONDS);
|
MAX_SVR_PASSWORD_AGE_SECONDS);
|
||||||
|
|
||||||
// the username associated with the provided number
|
return Mono.fromFuture(() -> accountsManager.getByE164Async(request.getNumber()))
|
||||||
final Optional<String> matchingUsername = accountsManager
|
// the username associated with the provided number
|
||||||
.getByE164(request.getNumber())
|
.map(maybeAccount -> maybeAccount.map(Account::getUuid)
|
||||||
.map(Account::getUuid)
|
.map(svrCredentialsGenerator::generateForUuid)
|
||||||
.map(svrCredentialsGenerator::generateForUuid)
|
.map(ExternalServiceCredentials::username))
|
||||||
.map(ExternalServiceCredentials::username);
|
.flatMapMany(maybeMatchingUsername -> Flux.fromIterable(credentials)
|
||||||
|
.map(credential -> Tuples.of(maybeMatchingUsername, credential)))
|
||||||
|
.reduce(CheckSvrCredentialsResponse.newBuilder(), ((builder, usernameAndCredentialInfo) -> {
|
||||||
|
final Optional<String> matchingUsername = usernameAndCredentialInfo.getT1();
|
||||||
|
final ExternalServiceCredentialsSelector.CredentialInfo credentialInfo = usernameAndCredentialInfo.getT2();
|
||||||
|
|
||||||
return Flux.fromIterable(credentials)
|
|
||||||
.reduce(CheckSvrCredentialsResponse.newBuilder(), ((builder, credentialInfo) -> {
|
|
||||||
final AuthCheckResult authCheckResult;
|
final AuthCheckResult authCheckResult;
|
||||||
if (!credentialInfo.valid()) {
|
if (!credentialInfo.valid()) {
|
||||||
authCheckResult = AuthCheckResult.AUTH_CHECK_RESULT_INVALID;
|
authCheckResult = AuthCheckResult.AUTH_CHECK_RESULT_INVALID;
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.time.Duration;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
@ -58,7 +59,8 @@ class ExternalServiceCredentialsAnonymousGrpcServiceTest extends
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Mockito.when(accountsManager.getByE164(USER_E164)).thenReturn(Optional.of(account(USER_UUID)));
|
Mockito.when(accountsManager.getByE164Async(USER_E164))
|
||||||
|
.thenReturn(CompletableFuture.completedFuture(Optional.of(account(USER_UUID))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue