-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#77 added a validation test on the in-memory user props and renamed t…
…he username field
- Loading branch information
1 parent
3f0d036
commit b2906d0
Showing
9 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...oformosa/quartzmanager/api/security/properties/InMemoryUsersValidationControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package it.fabioformosa.quartzmanager.api.security.properties; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.springframework.boot.context.properties.bind.BindResult; | ||
import org.springframework.boot.context.properties.bind.Binder; | ||
import org.springframework.boot.context.properties.source.ConfigurationPropertySource; | ||
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource; | ||
|
||
import javax.validation.Validation; | ||
import javax.validation.Validator; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
public class InMemoryUsersValidationControllerTest { | ||
|
||
private static Validator propertyValidator; | ||
|
||
static Stream<Arguments> notValidInMemoryProps = Stream.of( | ||
Arguments.of( | ||
Map.of("quartz-manager.security.accounts.in-memory.users[0].password", "bar"), | ||
Map.of("quartz-manager.security.accounts.in-memory.users[0].roles[0]", "admin")), | ||
Arguments.of( | ||
Map.of("quartz-manager.security.accounts.in-memory.users[0].username", "foo"), | ||
Map.of("quartz-manager.security.accounts.in-memory.users[0].roles[0]", "admin")), | ||
Arguments.of( | ||
Map.of("quartz-manager.security.accounts.in-memory.users[0].username", "foo"), | ||
Map.of("quartz-manager.security.accounts.in-memory.users[0].password", "bar")) | ||
); | ||
|
||
|
||
@BeforeAll | ||
public static void setup() { | ||
propertyValidator = Validation.buildDefaultValidatorFactory().getValidator(); | ||
} | ||
|
||
static Stream<Arguments> getNotValidInMemoryProps(){ | ||
return notValidInMemoryProps; | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("it.fabioformosa.quartzmanager.api.security.properties.InMemoryUsersValidationControllerTest#getNotValidInMemoryProps") | ||
void givenAMissingUsername_whenThePropertyValidationIsApplied_thenShouldRaiseValidationError(Map<String, String> properties) throws Exception { | ||
ConfigurationPropertySource source = new MapConfigurationPropertySource(properties); | ||
|
||
Binder binder = new Binder(source); | ||
BindResult<InMemoryAccountProperties> result = binder.bind("quartz-manager.security.accounts.in-memory", InMemoryAccountProperties.class); | ||
|
||
Assertions.assertThat(result.isBound()).isTrue(); | ||
|
||
InMemoryAccountProperties inMemoryAccountProperties = result.get(); | ||
Assertions.assertThat(propertyValidator.validate(inMemoryAccountProperties).size()).isGreaterThan(0); | ||
|
||
} | ||
|
||
@Test | ||
void givenAllInMemoryPropsAreSet_whenThePropertyValidationIsApplied_thenShouldRaiseValidationError() throws Exception { | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put("quartz-manager.security.accounts.in-memory.users[0].username", "foo"); | ||
properties.put("quartz-manager.security.accounts.in-memory.users[0].password", "bar"); | ||
properties.put("quartz-manager.security.accounts.in-memory.users[0].roles[0]", "admin"); | ||
|
||
ConfigurationPropertySource source = new MapConfigurationPropertySource(properties); | ||
|
||
Binder binder = new Binder(source); | ||
BindResult<InMemoryAccountProperties> result = binder.bind("quartz-manager.security.accounts.in-memory", InMemoryAccountProperties.class); | ||
|
||
Assertions.assertThat(result.isBound()).isTrue(); | ||
|
||
InMemoryAccountProperties inMemoryAccountProperties = result.get(); | ||
Assertions.assertThat(propertyValidator.validate(inMemoryAccountProperties).size()).isEqualTo(0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters