@Test void testCalculateExpirationTime0PasswordPolicy() { UserManagementProto.Account account = UserManagementProto.Account.newBuilder() .setPasswordPolicy(UserManagementProto.WorkloadPasswordPolicy.newBuilder() .setWorkloadPasswordMaxLifetime(0) .build()) .build(); when(grpcUmsClient.getAccountDetails(eq(INTERNAL_ACTOR_CRN), eq(ACCOUNT_ID), any())).thenReturn(account); assertEquals(Optional.empty(), underTest.calculateExpirationTime(INTERNAL_ACTOR_CRN, ACCOUNT_ID)); }
@VisibleForTesting Optional<Instant> calculateExpirationTime(String actorCrn, String accountId) { LOGGER.debug("calculating expiration time for password in account {}", accountId); UserManagementProto.Account account = umsClient.getAccountDetails(INTERNAL_ACTOR_CRN, accountId, MDCUtils.getRequestId()); if (account.hasPasswordPolicy()) { long maxLifetime = account.getPasswordPolicy().getWorkloadPasswordMaxLifetime(); if (maxLifetime != 0L) { LOGGER.debug("Calculating password expiration by adding lifetime '{}' to current time", maxLifetime); return Optional.of(clock.getCurrentInstant().plusMillis(maxLifetime)); } else { LOGGER.debug("Password policy lifetime is {}. Using max expiration time", maxLifetime); return Optional.empty(); } } else { LOGGER.debug("Account {} does not have a password policy. Using max expiration time for password", accountId); return Optional.empty(); } }
PasswordService { @VisibleForTesting Optional<Instant> calculateExpirationTime(String actorCrn, String accountId) { LOGGER.debug("calculating expiration time for password in account {}", accountId); UserManagementProto.Account account = umsClient.getAccountDetails(INTERNAL_ACTOR_CRN, accountId, MDCUtils.getRequestId()); if (account.hasPasswordPolicy()) { long maxLifetime = account.getPasswordPolicy().getWorkloadPasswordMaxLifetime(); if (maxLifetime != 0L) { LOGGER.debug("Calculating password expiration by adding lifetime '{}' to current time", maxLifetime); return Optional.of(clock.getCurrentInstant().plusMillis(maxLifetime)); } else { LOGGER.debug("Password policy lifetime is {}. Using max expiration time", maxLifetime); return Optional.empty(); } } else { LOGGER.debug("Account {} does not have a password policy. Using max expiration time for password", accountId); return Optional.empty(); } } }
PasswordService { @VisibleForTesting Optional<Instant> calculateExpirationTime(String actorCrn, String accountId) { LOGGER.debug("calculating expiration time for password in account {}", accountId); UserManagementProto.Account account = umsClient.getAccountDetails(INTERNAL_ACTOR_CRN, accountId, MDCUtils.getRequestId()); if (account.hasPasswordPolicy()) { long maxLifetime = account.getPasswordPolicy().getWorkloadPasswordMaxLifetime(); if (maxLifetime != 0L) { LOGGER.debug("Calculating password expiration by adding lifetime '{}' to current time", maxLifetime); return Optional.of(clock.getCurrentInstant().plusMillis(maxLifetime)); } else { LOGGER.debug("Password policy lifetime is {}. Using max expiration time", maxLifetime); return Optional.empty(); } } else { LOGGER.debug("Account {} does not have a password policy. Using max expiration time for password", accountId); return Optional.empty(); } }  }
PasswordService { @VisibleForTesting Optional<Instant> calculateExpirationTime(String actorCrn, String accountId) { LOGGER.debug("calculating expiration time for password in account {}", accountId); UserManagementProto.Account account = umsClient.getAccountDetails(INTERNAL_ACTOR_CRN, accountId, MDCUtils.getRequestId()); if (account.hasPasswordPolicy()) { long maxLifetime = account.getPasswordPolicy().getWorkloadPasswordMaxLifetime(); if (maxLifetime != 0L) { LOGGER.debug("Calculating password expiration by adding lifetime '{}' to current time", maxLifetime); return Optional.of(clock.getCurrentInstant().plusMillis(maxLifetime)); } else { LOGGER.debug("Password policy lifetime is {}. Using max expiration time", maxLifetime); return Optional.empty(); } } else { LOGGER.debug("Account {} does not have a password policy. Using max expiration time for password", accountId); return Optional.empty(); } }  Operation setPassword(String accountId, String actorCrn, String userCrn, String password, Set<String> environmentCrnFilter); Operation setPasswordWithCustomPermissionCheck(String accountId, String actorCrn, String userCrn,
            String password, Set<String> environmentCrnFilter, AuthorizationResourceAction action); }
PasswordService { @VisibleForTesting Optional<Instant> calculateExpirationTime(String actorCrn, String accountId) { LOGGER.debug("calculating expiration time for password in account {}", accountId); UserManagementProto.Account account = umsClient.getAccountDetails(INTERNAL_ACTOR_CRN, accountId, MDCUtils.getRequestId()); if (account.hasPasswordPolicy()) { long maxLifetime = account.getPasswordPolicy().getWorkloadPasswordMaxLifetime(); if (maxLifetime != 0L) { LOGGER.debug("Calculating password expiration by adding lifetime '{}' to current time", maxLifetime); return Optional.of(clock.getCurrentInstant().plusMillis(maxLifetime)); } else { LOGGER.debug("Password policy lifetime is {}. Using max expiration time", maxLifetime); return Optional.empty(); } } else { LOGGER.debug("Account {} does not have a password policy. Using max expiration time for password", accountId); return Optional.empty(); } }  Operation setPassword(String accountId, String actorCrn, String userCrn, String password, Set<String> environmentCrnFilter); Operation setPasswordWithCustomPermissionCheck(String accountId, String actorCrn, String userCrn,
            String password, Set<String> environmentCrnFilter, AuthorizationResourceAction action);  }