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:
@@ -109,7 +109,10 @@ public class AccountResolver {
|
|||||||
|
|
||||||
return result.asList().stream()
|
return result.asList().stream()
|
||||||
.map(a -> formatForException(result, a))
|
.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) {
|
private static String formatForException(Result result, AccountState state) {
|
||||||
|
|||||||
@@ -269,7 +269,8 @@ public class AccountResolverTest {
|
|||||||
() -> search("foo", searchers, allVisible()).asUnique());
|
() -> search("foo", searchers, allVisible()).asUnique());
|
||||||
assertThat(thrown)
|
assertThat(thrown)
|
||||||
.hasMessageThat()
|
.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
|
@Test
|
||||||
@@ -311,7 +312,8 @@ public class AccountResolverTest {
|
|||||||
.new Result(
|
.new Result(
|
||||||
"foo", ImmutableList.of(newAccount(3), newAccount(1)), ImmutableList.of())))
|
"foo", ImmutableList.of(newAccount(3), newAccount(1)), ImmutableList.of())))
|
||||||
.hasMessageThat()
|
.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
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user