Skip to content

Commit

Permalink
feat(sandside): #198 limit the number of generated passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
Marthym committed Jan 14, 2024
1 parent c3035da commit 0a2d2db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @param self The Persisted Entity
* @param <T> The type of the persisted object
*/
@Builder(toBuilder = true)
@Builder
public record Entity<T>(
@NonNull String id,
@NonNull String createdBy,
Expand All @@ -37,7 +37,7 @@ public record Entity<T>(
* @return An identified Object with ID
*/
public static <T> Entity<T> identify(String id, Instant createdAt, T entity) {
return new Entity<T>(id, NO_ONE, createdAt, entity);
return new Entity<>(id, NO_ONE, createdAt, entity);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ public Mono<PasswordEvaluation> checkPasswordStrength(User user) {

@Override
public Flux<String> generateSecurePassword(int number) {
if (number > 100 || number < 1) {
return Flux.error(() -> new IllegalArgumentException("Invalid number of passwords required !"));
}
return Flux.<String>create(sink ->
sink.onRequest(n -> LongStream.range(0, number)
.mapToObj(ignore -> passwordChecker.generate())
.forEach(sink::next)))
.take(Integer.valueOf(number).longValue());
.take(number);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 0a2d2db

Please sign in to comment.