@Test @WithMockUser(value = USERNAME, roles = ROLE_SU) void testDisableForUser() { User molgenisUser = mock(User.class); UserSecret userSecret = mock(UserSecret.class); when(molgenisUser.getUsername()).thenReturn(USERNAME); when(molgenisUser.getId()).thenReturn("1324"); when(userService.getUser(USERNAME)).thenReturn(molgenisUser); Query<UserSecret> userSecretQuery = mock(Query.class, RETURNS_SELF); when(dataService.query(UserSecretMetadata.USER_SECRET, UserSecret.class)) .thenReturn(userSecretQuery); when(userSecretQuery.eq(UserSecretMetadata.USER_ID, molgenisUser.getId()).findOne()) .thenReturn(userSecret); when(userService.getUser(molgenisUser.getUsername())).thenReturn(molgenisUser); when(dataService .query(UserSecretMetadata.USER_SECRET, UserSecret.class) .eq(UserSecretMetadata.USER_ID, molgenisUser.getId()) .findOne()) .thenReturn(userSecret); twoFactorAuthenticationServiceImpl.disableForUser(); }
@Override public void disableForUser() { User user = getUser(); user.setTwoFactorAuthentication(false); userService.update(user); UserSecret userSecret = getSecret(); runAsSystem(() -> dataService.delete(USER_SECRET, userSecret)); }
TwoFactorAuthenticationServiceImpl implements TwoFactorAuthenticationService { @Override public void disableForUser() { User user = getUser(); user.setTwoFactorAuthentication(false); userService.update(user); UserSecret userSecret = getSecret(); runAsSystem(() -> dataService.delete(USER_SECRET, userSecret)); } }
TwoFactorAuthenticationServiceImpl implements TwoFactorAuthenticationService { @Override public void disableForUser() { User user = getUser(); user.setTwoFactorAuthentication(false); userService.update(user); UserSecret userSecret = getSecret(); runAsSystem(() -> dataService.delete(USER_SECRET, userSecret)); } TwoFactorAuthenticationServiceImpl(
      OtpService otpService,
      DataService dataService,
      UserService userService,
      IdGenerator idGenerator,
      UserSecretFactory userSecretFactory); }
TwoFactorAuthenticationServiceImpl implements TwoFactorAuthenticationService { @Override public void disableForUser() { User user = getUser(); user.setTwoFactorAuthentication(false); userService.update(user); UserSecret userSecret = getSecret(); runAsSystem(() -> dataService.delete(USER_SECRET, userSecret)); } TwoFactorAuthenticationServiceImpl(
      OtpService otpService,
      DataService dataService,
      UserService userService,
      IdGenerator idGenerator,
      UserSecretFactory userSecretFactory); @Override boolean isVerificationCodeValidForUser(String verificationCode); @Override boolean userIsBlocked(); @Override void saveSecretForUser(String secret); @Override void resetSecretForUser(); @Override void enableForUser(); @Override void disableForUser(); @Override String generateSecretKey(); @Override boolean isConfiguredForUser(); }
TwoFactorAuthenticationServiceImpl implements TwoFactorAuthenticationService { @Override public void disableForUser() { User user = getUser(); user.setTwoFactorAuthentication(false); userService.update(user); UserSecret userSecret = getSecret(); runAsSystem(() -> dataService.delete(USER_SECRET, userSecret)); } TwoFactorAuthenticationServiceImpl(
      OtpService otpService,
      DataService dataService,
      UserService userService,
      IdGenerator idGenerator,
      UserSecretFactory userSecretFactory); @Override boolean isVerificationCodeValidForUser(String verificationCode); @Override boolean userIsBlocked(); @Override void saveSecretForUser(String secret); @Override void resetSecretForUser(); @Override void enableForUser(); @Override void disableForUser(); @Override String generateSecretKey(); @Override boolean isConfiguredForUser();  }