@Override
  public Mono<LookupUsernameLinkResponse> lookupUsernameLink(final LookupUsernameLinkRequest request) {
    final UUID linkHandle;

    try {
      linkHandle = UUIDUtil.fromByteString(request.getUsernameLinkHandle());
    } catch (final IllegalArgumentException e) {
      throw Status.INVALID_ARGUMENT
          .withDescription("Could not interpret link handle as UUID")
          .withCause(e)
          .asRuntimeException();
    }

    return RateLimitUtil.rateLimitByRemoteAddress(rateLimiters.getUsernameLinkLookupLimiter())
        .then(Mono.fromFuture(() -> accountsManager.getByUsernameLinkHandle(linkHandle)))
        .map(maybeAccount -> maybeAccount
            .flatMap(Account::getEncryptedUsername)
            .orElseThrow(Status.NOT_FOUND::asRuntimeException))
        .map(usernameCiphertext -> LookupUsernameLinkResponse.newBuilder()
            .setUsernameCiphertext(ByteString.copyFrom(usernameCiphertext))
            .build());
  }
@Test
  void lookupUsernameLink() {
    final UUID linkHandle = UUID.randomUUID();

    final byte[] usernameCiphertext = TestRandomUtil.nextBytes(32);

    final Account account = mock(Account.class);
    when(account.getEncryptedUsername()).thenReturn(Optional.of(usernameCiphertext));

    when(accountsManager.getByUsernameLinkHandle(linkHandle))
        .thenReturn(CompletableFuture.completedFuture(Optional.of(account)));

    assertEquals(ByteString.copyFrom(usernameCiphertext),
        unauthenticatedServiceStub().lookupUsernameLink(LookupUsernameLinkRequest.newBuilder()
                .setUsernameLinkHandle(UUIDUtil.toByteString(linkHandle))
                .build())
            .getUsernameCiphertext());

    when(account.getEncryptedUsername()).thenReturn(Optional.empty());

    //noinspection ResultOfMethodCallIgnored
    GrpcTestUtils.assertStatusException(Status.NOT_FOUND,
        () -> unauthenticatedServiceStub().lookupUsernameLink(LookupUsernameLinkRequest.newBuilder()
            .setUsernameLinkHandle(UUIDUtil.toByteString(linkHandle))
            .build()));

    //noinspection ResultOfMethodCallIgnored
    GrpcTestUtils.assertStatusException(Status.NOT_FOUND,
        () -> unauthenticatedServiceStub().lookupUsernameLink(LookupUsernameLinkRequest.newBuilder()
            .setUsernameLinkHandle(UUIDUtil.toByteString(UUID.randomUUID()))
            .build()));
  }