Drop the 365-day check when deciding if an account is enabled.

This commit is contained in:
Jon Chambers 2020-09-28 17:15:36 -04:00 committed by Jon Chambers
parent 73da4844ee
commit 65cdd5fcbe
2 changed files with 20 additions and 32 deletions

View File

@ -160,10 +160,7 @@ public class Account implements Principal {
} }
public boolean isEnabled() { public boolean isEnabled() {
final boolean enabled = final boolean enabled = getMasterDevice().map(Device::isEnabled).orElse(false);
getMasterDevice().isPresent() &&
getMasterDevice().get().isEnabled() &&
getLastSeen() > (System.currentTimeMillis() - TimeUnit.DAYS.toMillis(365));
if (enabled) { if (enabled) {
ENABLED_ACCOUNT_COUNTER.increment(); ENABLED_ACCOUNT_COUNTER.increment();

View File

@ -65,37 +65,28 @@ public class AccountTest {
} }
@Test @Test
public void testAccountActive() { public void testIsEnabled() {
Account recentAccount = new Account("+14152222222", UUID.randomUUID(), new HashSet<Device>() {{ final Device enabledMasterDevice = mock(Device.class);
add(recentMasterDevice); final Device enabledLinkedDevice = mock(Device.class);
add(recentSecondaryDevice); final Device disabledMasterDevice = mock(Device.class);
}}, "1234".getBytes()); final Device disabledLinkedDevice = mock(Device.class);
assertTrue(recentAccount.isEnabled()); when(enabledMasterDevice.isEnabled()).thenReturn(true);
when(enabledLinkedDevice.isEnabled()).thenReturn(true);
when(disabledMasterDevice.isEnabled()).thenReturn(false);
when(disabledLinkedDevice.isEnabled()).thenReturn(false);
Account oldSecondaryAccount = new Account("+14152222222", UUID.randomUUID(), new HashSet<Device>() {{ when(enabledMasterDevice.getId()).thenReturn(1L);
add(recentMasterDevice); when(enabledLinkedDevice.getId()).thenReturn(2L);
add(agingSecondaryDevice); when(disabledMasterDevice.getId()).thenReturn(1L);
}}, "1234".getBytes()); when(disabledLinkedDevice.getId()).thenReturn(2L);
assertTrue(oldSecondaryAccount.isEnabled()); assertTrue( new Account("+14151234567", UUID.randomUUID(), Set.of(enabledMasterDevice), new byte[0]).isEnabled());
assertTrue( new Account("+14151234567", UUID.randomUUID(), Set.of(enabledMasterDevice, enabledLinkedDevice), new byte[0]).isEnabled());
Account agingPrimaryAccount = new Account("+14152222222", UUID.randomUUID(), new HashSet<Device>() {{ assertTrue( new Account("+14151234567", UUID.randomUUID(), Set.of(enabledMasterDevice, disabledLinkedDevice), new byte[0]).isEnabled());
add(oldMasterDevice); assertFalse(new Account("+14151234567", UUID.randomUUID(), Set.of(disabledMasterDevice), new byte[0]).isEnabled());
add(agingSecondaryDevice); assertFalse(new Account("+14151234567", UUID.randomUUID(), Set.of(disabledMasterDevice, enabledLinkedDevice), new byte[0]).isEnabled());
}}, "1234".getBytes()); assertFalse(new Account("+14151234567", UUID.randomUUID(), Set.of(disabledMasterDevice, disabledLinkedDevice), new byte[0]).isEnabled());
assertTrue(agingPrimaryAccount.isEnabled());
}
@Test
public void testAccountInactive() {
Account oldPrimaryAccount = new Account("+14152222222", UUID.randomUUID(), new HashSet<Device>() {{
add(oldMasterDevice);
add(oldSecondaryDevice);
}}, "1234".getBytes());
assertFalse(oldPrimaryAccount.isEnabled());
} }
@Test @Test