use of com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO in project AuthGuard by AuthGuard.
the class CredentialsRouteTest method create.
@Test
void create() {
final CreateCredentialsRequestDTO credentialsRequest = randomObject(CreateCredentialsRequestDTO.class);
final CredentialsBO credentialsBO = mapper().toBO(credentialsRequest).withPasswordVersion(null);
final CredentialsBO serviceResponse = credentialsBO.withPlainPassword(null).withId(UUID.randomUUID().toString()).withPasswordVersion(1);
Mockito.when(credentialsService.create(Mockito.any(), Mockito.any())).thenReturn(serviceResponse);
final ValidatableResponse httpResponse = given().body(credentialsRequest).contentType(ContentType.JSON).header("X-IdempotentKey", "key").post(url()).then().statusCode(201).contentType(ContentType.JSON);
final CredentialsDTO responseBody = httpResponse.extract().response().getBody().as(CredentialsDTO.class);
assertThat(responseBody).isEqualToIgnoringGivenFields(credentialsRequest, "id", "plainPassword", "createdAt", "lastModified", "passwordUpdatedAt", "passwordVersion");
assertThat(responseBody.getPlainPassword()).isNull();
assertThat(responseBody.getId()).isEqualTo(serviceResponse.getId());
assertThat(responseBody.getPasswordVersion()).isEqualTo(1);
}
use of com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO in project AuthGuard by AuthGuard.
the class CreateCredentialsRequestValidatorTest method validateMissingFields.
@Test
void validateMissingFields() {
final CreateCredentialsRequestDTO request = CreateCredentialsRequestDTO.builder().build();
final Validator<CreateCredentialsRequestDTO> validator = Validators.getForClass(CreateCredentialsRequestDTO.class);
final List<Violation> violations = validator.validate(request);
assertThat(violations).containsExactlyInAnyOrder(new Violation("accountId", ViolationType.MISSING_REQUIRED_VALUE), new Violation("plainPassword", ViolationType.MISSING_REQUIRED_VALUE), new Violation("identifiers", ViolationType.EMPTY_LIST), new Violation("domain", ViolationType.MISSING_REQUIRED_VALUE));
}
use of com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO in project AuthGuard by AuthGuard.
the class CreateCredentialsRequestValidatorTest method validateValid.
@Test
void validateValid() {
final CreateCredentialsRequestDTO request = CreateCredentialsRequestDTO.builder().accountId("account").addIdentifiers(UserIdentifierDTO.builder().type(UserIdentifier.Type.USERNAME).identifier("username").build()).plainPassword("password").domain("main").build();
final Validator<CreateCredentialsRequestDTO> validator = Validators.getForClass(CreateCredentialsRequestDTO.class);
final List<Violation> violations = validator.validate(request);
assertThat(violations).isEmpty();
}
Aggregations