AccountResolver: limit number of ambiguous accounts in error message

Don't list more than 3 ambiguous accounts in error message of
UnresolvableAccountException in order to prevent flooding the log and
displaying a lot of sensitive account data in an error dialog.

Bug: Issue 13803
Change-Id: I95fe697988f3d900cce29ca93114a725b1c17ca6
This commit is contained in:
Matthias Sohn
2021-01-13 00:42:33 +01:00
parent 96ccc2388a
commit e19fa5cbac
2 changed files with 8 additions and 3 deletions

View File

@@ -109,7 +109,10 @@ public class AccountResolver {
return result.asList().stream()
.map(a -> formatForException(result, a))
.collect(joining("\n", "Account '" + result.input() + "' is ambiguous:\n", ""));
.limit(3)
.collect(
joining(
"\n", "Account '" + result.input() + "' is ambiguous (at most 3 shown):\n", ""));
}
private static String formatForException(Result result, AccountState state) {

View File

@@ -269,7 +269,8 @@ public class AccountResolverTest {
() -> search("foo", searchers, allVisible()).asUnique());
assertThat(thrown)
.hasMessageThat()
.isEqualTo("Account 'foo' is ambiguous:\n1: Anonymous Name (1)\n2: Anonymous Name (2)");
.isEqualTo(
"Account 'foo' is ambiguous (at most 3 shown):\n1: Anonymous Name (1)\n2: Anonymous Name (2)");
}
@Test
@@ -311,7 +312,8 @@ public class AccountResolverTest {
.new Result(
"foo", ImmutableList.of(newAccount(3), newAccount(1)), ImmutableList.of())))
.hasMessageThat()
.isEqualTo("Account 'foo' is ambiguous:\n1: Anonymous Name (1)\n3: Anonymous Name (3)");
.isEqualTo(
"Account 'foo' is ambiguous (at most 3 shown):\n1: Anonymous Name (1)\n3: Anonymous Name (3)");
}
@Test