JdbcUserGoogleMfaCredentialsProvisioning implements SystemDeletable, UserMfaCredentialsProvisioning<UserGoogleMfaCredentials> { @Override public void update(UserGoogleMfaCredentials credentials, String zoneId) { jdbcTemplate.update(UPDATE_USER_MFA_CONFIG_SQL, ps -> { int pos = 1; try { ps.setString(pos++, encrypt(credentials.getSecretKey())); ps.setString(pos++, encrypt(String.valueOf(credentials.getValidationCode()))); ps.setString(pos++, encrypt(toCSScratchCode(credentials.getScratchCodes()))); } catch (EncryptionServiceException e) { logger.error("Unable to encrypt MFA credentials", e); throw new UnableToPersistMfaException(e); } ps.setString(pos++, credentials.getMfaProviderId()); ps.setString(pos++, zoneId); ps.setString(pos++, credentials.getUserId()); }); retrieve(credentials.getUserId(), credentials.getMfaProviderId()); } JdbcUserGoogleMfaCredentialsProvisioning(JdbcTemplate jdbcTemplate, EncryptionKeyService encryptionKeyService); @Override void save(UserGoogleMfaCredentials credentials, String zoneId); @Override void update(UserGoogleMfaCredentials credentials, String zoneId); @Override UserGoogleMfaCredentials retrieve(String userId, String mfaProviderId); @Override int deleteByUser(String userId, String zoneId); @Override int deleteByMfaProvider(String mfaProviderId, String zoneId); @Override int deleteByIdentityZone(String zoneId); @Override int delete(String userId); @Override Logger getLogger();  }
@Test void updateUserGoogleMfaCredentials_noUser() { assertEquals(0, jdbcTemplate.queryForList("SELECT * FROM user_google_mfa_credentials").size()); UserGoogleMfaCredentials userGoogleMfaCredentials = new UserGoogleMfaCredentials("jabbahut", "very_sercret_key", 74718234, Arrays.asList(1, 22)); assertThrows(UserMfaConfigDoesNotExistException.class, () -> db.update(userGoogleMfaCredentials, zoneId)); }