Skip to content

Commit

Permalink
enforce accounts must start with 0x (PegaSysEng#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarla authored and tmohay committed Feb 20, 2019
1 parent c1d36ae commit 173c629
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ private boolean containsInvalidAccount(final List<String> accounts) {

static boolean isValidAccountString(final String account) {
try {
if (account == null || !account.startsWith("0x")) {
return false;
}
BytesValue bytesValue = BytesValue.fromHexString(account);
return bytesValue.size() == ACCOUNT_BYTES_SIZE;
} catch (NullPointerException | IndexOutOfBoundsException | IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ public void reloadAccountWhitelistWithErrorReadingConfigFileShouldKeepOldWhiteli
.containsExactly("0xfe3b557e8fb62b89f4916b721be55ceb828dbd73");
}

@Test
public void accountThatDoesNotStartWith0xIsNotValid() {
assertThat(AccountWhitelistController.isValidAccountString("bob")).isFalse();
assertThat(
AccountWhitelistController.isValidAccountString(
"b9b81ee349c3807e46bc71aa2632203c5b462032"))
.isFalse();
assertThat(
AccountWhitelistController.isValidAccountString(
"0xb9b81ee349c3807e46bc71aa2632203c5b462032"))
.isTrue();
}

private Path createPermissionsFileWithAccount(final String account) throws IOException {
final String nodePermissionsFileContent = "accounts-whitelist=[\"" + account + "\"]";
final Path permissionsFile = Files.createTempFile("account_permissions", "");
Expand Down

0 comments on commit 173c629

Please sign in to comment.