diff --git a/sandside/src/main/java/fr/ght1pc9kc/baywatch/common/api/model/Entity.java b/sandside/src/main/java/fr/ght1pc9kc/baywatch/common/api/model/Entity.java index da413c0b..c6c5ef5a 100644 --- a/sandside/src/main/java/fr/ght1pc9kc/baywatch/common/api/model/Entity.java +++ b/sandside/src/main/java/fr/ght1pc9kc/baywatch/common/api/model/Entity.java @@ -12,7 +12,7 @@ * @param self The Persisted Entity * @param The type of the persisted object */ -@Builder(toBuilder = true) +@Builder public record Entity( @NonNull String id, @NonNull String createdBy, @@ -37,7 +37,7 @@ public record Entity( * @return An identified Object with ID */ public static Entity identify(String id, Instant createdAt, T entity) { - return new Entity(id, NO_ONE, createdAt, entity); + return new Entity<>(id, NO_ONE, createdAt, entity); } /** diff --git a/sandside/src/main/java/fr/ght1pc9kc/baywatch/security/domain/PasswordServiceImpl.java b/sandside/src/main/java/fr/ght1pc9kc/baywatch/security/domain/PasswordServiceImpl.java index 8d29f905..c22aeefd 100644 --- a/sandside/src/main/java/fr/ght1pc9kc/baywatch/security/domain/PasswordServiceImpl.java +++ b/sandside/src/main/java/fr/ght1pc9kc/baywatch/security/domain/PasswordServiceImpl.java @@ -39,10 +39,13 @@ public Mono checkPasswordStrength(User user) { @Override public Flux generateSecurePassword(int number) { + if (number > 100 || number < 1) { + return Flux.error(() -> new IllegalArgumentException("Invalid number of passwords required !")); + } return Flux.create(sink -> sink.onRequest(n -> LongStream.range(0, number) .mapToObj(ignore -> passwordChecker.generate()) .forEach(sink::next))) - .take(Integer.valueOf(number).longValue()); + .take(number); } } diff --git a/sandside/src/test/java/fr/ght1pc9kc/baywatch/security/domain/PasswordServiceImplTest.java b/sandside/src/test/java/fr/ght1pc9kc/baywatch/security/domain/PasswordServiceImplTest.java index c71a9550..fee1a3e4 100644 --- a/sandside/src/test/java/fr/ght1pc9kc/baywatch/security/domain/PasswordServiceImplTest.java +++ b/sandside/src/test/java/fr/ght1pc9kc/baywatch/security/domain/PasswordServiceImplTest.java @@ -72,4 +72,11 @@ void should_generate_password() { .assertNext(actual -> Assertions.assertThat(actual).isNotBlank().hasSize(16)) .verifyComplete(); } + + @ParameterizedTest + @CsvSource({"-10", "1000"}) + void should_fail_on_invalid_number_of_password(int number) { + StepVerifier.create(tested.generateSecurePassword(number)) + .verifyError(IllegalArgumentException.class); + } } \ No newline at end of file