@ -50,7 +50,7 @@ public class AccountLocalConfigPermissioningControllerTest {
private AccountLocalConfigPermissioningController controller ;
@Mock private LocalPermissioningConfiguration permissioningConfig ;
@Mock private WhitelistPersistor white listPersistor;
@Mock private AllowlistPersistor allow listPersistor;
@Mock private MetricsSystem metricsSystem ;
@Mock private Counter checkCounter ;
@Mock private Counter checkPermittedCounter ;
@ -79,17 +79,17 @@ public class AccountLocalConfigPermissioningControllerTest {
controller =
new AccountLocalConfigPermissioningController (
permissioningConfig , white listPersistor , metricsSystem ) ;
permissioningConfig , allo wlistPersistor, metricsSystem ) ;
}
@Test
public void whenPermConfigHasAccountsShouldAddAllAccountsToWhitelist ( ) {
when ( permissioningConfig . isAccountWhite listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountWhite list ( ) )
when ( permissioningConfig . isAccountAllow listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountAllow list ( ) )
. thenReturn ( singletonList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
controller =
new AccountLocalConfigPermissioningController (
permissioningConfig , white listPersistor , metricsSystem ) ;
permissioningConfig , allo wlistPersistor, metricsSystem ) ;
assertThat ( controller . getAccountWhitelist ( ) )
. contains ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ;
@ -97,12 +97,12 @@ public class AccountLocalConfigPermissioningControllerTest {
@Test
public void whenLoadingAccountsFromConfigShouldNormalizeAccountsToLowerCase ( ) {
when ( permissioningConfig . isAccountWhite listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountWhite list ( ) )
when ( permissioningConfig . isAccountAllow listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountAllow list ( ) )
. thenReturn ( singletonList ( "0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73" ) ) ;
controller =
new AccountLocalConfigPermissioningController (
permissioningConfig , white listPersistor , metricsSystem ) ;
permissioningConfig , allo wlistPersistor, metricsSystem ) ;
assertThat ( controller . getAccountWhitelist ( ) )
. containsExactly ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ;
@ -110,30 +110,30 @@ public class AccountLocalConfigPermissioningControllerTest {
@Test
public void whenPermConfigContainsEmptyListOfAccountsContainsShouldReturnFalse ( ) {
when ( permissioningConfig . isAccountWhite listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountWhite list ( ) ) . thenReturn ( new ArrayList < > ( ) ) ;
when ( permissioningConfig . isAccountAllow listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountAllow list ( ) ) . thenReturn ( new ArrayList < > ( ) ) ;
controller =
new AccountLocalConfigPermissioningController (
permissioningConfig , white listPersistor , metricsSystem ) ;
permissioningConfig , allo wlistPersistor, metricsSystem ) ;
assertThat ( controller . contains ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) . isFalse ( ) ;
}
@Test
public void addAccountsWithInvalidAccountShouldReturnInvalidEntryResult ( ) {
White listOperationResult addResult = controller . addAccounts ( Arrays . asList ( "0x0" ) ) ;
Allow listOperationResult addResult = controller . addAccounts ( Arrays . asList ( "0x0" ) ) ;
assertThat ( addResult ) . isEqualTo ( White listOperationResult. ERROR_INVALID_ENTRY ) ;
assertThat ( addResult ) . isEqualTo ( Allow listOperationResult. ERROR_INVALID_ENTRY ) ;
assertThat ( controller . getAccountWhitelist ( ) ) . isEmpty ( ) ;
}
@Test
public void addExistingAccountShouldReturnExistingEntryResult ( ) {
controller . addAccounts ( Arrays . asList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
White listOperationResult addResult =
Allow listOperationResult addResult =
controller . addAccounts ( Arrays . asList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
assertThat ( addResult ) . isEqualTo ( White listOperationResult. ERROR_EXISTING_ENTRY ) ;
assertThat ( addResult ) . isEqualTo ( Allow listOperationResult. ERROR_EXISTING_ENTRY ) ;
assertThat ( controller . getAccountWhitelist ( ) )
. containsExactly ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ;
}
@ -141,30 +141,30 @@ public class AccountLocalConfigPermissioningControllerTest {
@Test
public void addExistingAccountWithDifferentCasingShouldReturnExistingEntryResult ( ) {
controller . addAccounts ( Arrays . asList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
White listOperationResult addResult =
Allow listOperationResult addResult =
controller . addAccounts ( Arrays . asList ( "0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73" ) ) ;
assertThat ( addResult ) . isEqualTo ( White listOperationResult. ERROR_EXISTING_ENTRY ) ;
assertThat ( addResult ) . isEqualTo ( Allow listOperationResult. ERROR_EXISTING_ENTRY ) ;
assertThat ( controller . getAccountWhitelist ( ) )
. containsExactly ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ;
}
@Test
public void addValidAccountsShouldReturnSuccessResult ( ) {
White listOperationResult addResult =
Allow listOperationResult addResult =
controller . addAccounts ( Arrays . asList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
assertThat ( addResult ) . isEqualTo ( White listOperationResult. SUCCESS ) ;
assertThat ( addResult ) . isEqualTo ( Allow listOperationResult. SUCCESS ) ;
assertThat ( controller . getAccountWhitelist ( ) )
. containsExactly ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ;
}
@Test
public void addAccountsShouldAddAccountNormalizedToLowerCase ( ) {
White listOperationResult addResult =
Allow listOperationResult addResult =
controller . addAccounts ( Arrays . asList ( "0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73" ) ) ;
assertThat ( addResult ) . isEqualTo ( White listOperationResult. SUCCESS ) ;
assertThat ( addResult ) . isEqualTo ( Allow listOperationResult. SUCCESS ) ;
assertThat ( controller . getAccountWhitelist ( ) )
. containsExactly ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ;
}
@ -173,10 +173,10 @@ public class AccountLocalConfigPermissioningControllerTest {
public void removeExistingAccountShouldReturnSuccessResult ( ) {
controller . addAccounts ( Arrays . asList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
White listOperationResult removeResult =
Allow listOperationResult removeResult =
controller . removeAccounts ( Arrays . asList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
assertThat ( removeResult ) . isEqualTo ( White listOperationResult. SUCCESS ) ;
assertThat ( removeResult ) . isEqualTo ( Allow listOperationResult. SUCCESS ) ;
assertThat ( controller . getAccountWhitelist ( ) ) . isEmpty ( ) ;
}
@ -184,69 +184,69 @@ public class AccountLocalConfigPermissioningControllerTest {
public void removeAccountShouldNormalizeAccountToLowerCAse ( ) {
controller . addAccounts ( Arrays . asList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
White listOperationResult removeResult =
Allow listOperationResult removeResult =
controller . removeAccounts ( Arrays . asList ( "0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73" ) ) ;
assertThat ( removeResult ) . isEqualTo ( White listOperationResult. SUCCESS ) ;
assertThat ( removeResult ) . isEqualTo ( Allow listOperationResult. SUCCESS ) ;
assertThat ( controller . getAccountWhitelist ( ) ) . isEmpty ( ) ;
}
@Test
public void removeAbsentAccountShouldReturnAbsentEntryResult ( ) {
White listOperationResult removeResult =
Allow listOperationResult removeResult =
controller . removeAccounts ( Arrays . asList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
assertThat ( removeResult ) . isEqualTo ( White listOperationResult. ERROR_ABSENT_ENTRY ) ;
assertThat ( removeResult ) . isEqualTo ( Allow listOperationResult. ERROR_ABSENT_ENTRY ) ;
assertThat ( controller . getAccountWhitelist ( ) ) . isEmpty ( ) ;
}
@Test
public void removeInvalidAccountShouldReturnInvalidEntryResult ( ) {
White listOperationResult removeResult = controller . removeAccounts ( Arrays . asList ( "0x0" ) ) ;
Allow listOperationResult removeResult = controller . removeAccounts ( Arrays . asList ( "0x0" ) ) ;
assertThat ( removeResult ) . isEqualTo ( White listOperationResult. ERROR_INVALID_ENTRY ) ;
assertThat ( removeResult ) . isEqualTo ( Allow listOperationResult. ERROR_INVALID_ENTRY ) ;
assertThat ( controller . getAccountWhitelist ( ) ) . isEmpty ( ) ;
}
@Test
public void addDuplicatedAccountShouldReturnDuplicatedEntryResult ( ) {
White listOperationResult addResult =
Allow listOperationResult addResult =
controller . addAccounts (
Arrays . asList (
"0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ,
"0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
assertThat ( addResult ) . isEqualTo ( White listOperationResult. ERROR_DUPLICATED_ENTRY ) ;
assertThat ( addResult ) . isEqualTo ( Allow listOperationResult. ERROR_DUPLICATED_ENTRY ) ;
}
@Test
public void removeDuplicatedAccountShouldReturnDuplicatedEntryResult ( ) {
White listOperationResult removeResult =
Allow listOperationResult removeResult =
controller . removeAccounts (
Arrays . asList (
"0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ,
"0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
assertThat ( removeResult ) . isEqualTo ( White listOperationResult. ERROR_DUPLICATED_ENTRY ) ;
assertThat ( removeResult ) . isEqualTo ( Allow listOperationResult. ERROR_DUPLICATED_ENTRY ) ;
}
@Test
public void removeNullListShouldReturnEmptyEntryResult ( ) {
White listOperationResult removeResult = controller . removeAccounts ( null ) ;
Allow listOperationResult removeResult = controller . removeAccounts ( null ) ;
assertThat ( removeResult ) . isEqualTo ( White listOperationResult. ERROR_EMPTY_ENTRY ) ;
assertThat ( removeResult ) . isEqualTo ( Allow listOperationResult. ERROR_EMPTY_ENTRY ) ;
}
@Test
public void removeEmptyListShouldReturnEmptyEntryResult ( ) {
White listOperationResult removeResult = controller . removeAccounts ( new ArrayList < > ( ) ) ;
Allow listOperationResult removeResult = controller . removeAccounts ( new ArrayList < > ( ) ) ;
assertThat ( removeResult ) . isEqualTo ( White listOperationResult. ERROR_EMPTY_ENTRY ) ;
assertThat ( removeResult ) . isEqualTo ( Allow listOperationResult. ERROR_EMPTY_ENTRY ) ;
}
@Test
public void stateShouldRevertIfWhitelistPersistFails ( )
throws IOException , White listFileSyncException {
throws IOException , Allow listFileSyncException {
List < String > newAccount = singletonList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ;
List < String > newAccount2 = singletonList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd72" ) ;
@ -255,15 +255,15 @@ public class AccountLocalConfigPermissioningControllerTest {
controller . addAccounts ( newAccount ) ;
assertThat ( controller . getAccountWhitelist ( ) . size ( ) ) . isEqualTo ( 1 ) ;
doThrow ( new IOException ( ) ) . when ( white listPersistor ) . updateConfig ( any ( ) , any ( ) ) ;
doThrow ( new IOException ( ) ) . when ( allo wlistPersistor) . updateConfig ( any ( ) , any ( ) ) ;
controller . addAccounts ( newAccount2 ) ;
assertThat ( controller . getAccountWhitelist ( ) . size ( ) ) . isEqualTo ( 1 ) ;
assertThat ( controller . getAccountWhitelist ( ) ) . isEqualTo ( newAccount ) ;
verify ( white listPersistor , times ( 3 ) ) . verifyConfigFileMatchesState ( any ( ) , any ( ) ) ;
verify ( white listPersistor , times ( 2 ) ) . updateConfig ( any ( ) , any ( ) ) ;
verifyNoMoreInteractions ( white listPersistor ) ;
verify ( allo wlistPersistor, times ( 3 ) ) . verifyConfigFileMatchesState ( any ( ) , any ( ) ) ;
verify ( allo wlistPersistor, times ( 2 ) ) . updateConfig ( any ( ) , any ( ) ) ;
verifyNoMoreInteractions ( allo wlistPersistor) ;
}
@Test
@ -273,12 +273,12 @@ public class AccountLocalConfigPermissioningControllerTest {
when ( permissioningConfig . getAccountPermissioningConfigFilePath ( ) )
. thenReturn ( permissionsFile . toAbsolutePath ( ) . toString ( ) ) ;
when ( permissioningConfig . isAccountWhite listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountWhite list ( ) )
when ( permissioningConfig . isAccountAllow listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountAllow list ( ) )
. thenReturn ( Arrays . asList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
controller =
new AccountLocalConfigPermissioningController (
permissioningConfig , white listPersistor , metricsSystem ) ;
permissioningConfig , allo wlistPersistor, metricsSystem ) ;
controller . reload ( ) ;
@ -288,12 +288,12 @@ public class AccountLocalConfigPermissioningControllerTest {
@Test
public void reloadAccountWhitelistWithErrorReadingConfigFileShouldKeepOldWhitelist ( ) {
when ( permissioningConfig . getAccountPermissioningConfigFilePath ( ) ) . thenReturn ( "foo" ) ;
when ( permissioningConfig . isAccountWhite listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountWhite list ( ) )
when ( permissioningConfig . isAccountAllow listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountAllow list ( ) )
. thenReturn ( Arrays . asList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
controller =
new AccountLocalConfigPermissioningController (
permissioningConfig , white listPersistor , metricsSystem ) ;
permissioningConfig , allo wlistPersistor, metricsSystem ) ;
final Throwable thrown = catchThrowable ( ( ) - > controller . reload ( ) ) ;
@ -320,24 +320,24 @@ public class AccountLocalConfigPermissioningControllerTest {
@Test
public void shouldMatchAccountsWithInconsistentCasing ( ) {
when ( permissioningConfig . isAccountWhite listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountWhite list ( ) )
when ( permissioningConfig . isAccountAllow listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountAllow list ( ) )
. thenReturn ( singletonList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
controller =
new AccountLocalConfigPermissioningController (
permissioningConfig , white listPersistor , metricsSystem ) ;
permissioningConfig , allo wlistPersistor, metricsSystem ) ;
assertThat ( controller . contains ( "0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73" ) ) . isTrue ( ) ;
}
@Test
public void isPermittedShouldCheckIfAccountExistInTheWhitelist ( ) {
when ( permissioningConfig . isAccountWhite listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountWhite list ( ) )
when ( permissioningConfig . isAccountAllow listEnabled ( ) ) . thenReturn ( true ) ;
when ( permissioningConfig . getAccountAllow list ( ) )
. thenReturn ( singletonList ( "0xfe3b557e8fb62b89f4916b721be55ceb828dbd73" ) ) ;
controller =
new AccountLocalConfigPermissioningController (
permissioningConfig , white listPersistor , metricsSystem ) ;
permissioningConfig , allo wlistPersistor, metricsSystem ) ;
final Transaction transaction = mock ( Transaction . class ) ;
when ( transaction . getSender ( ) )