Search in sources :

Example 6 with CreateCredentialsRequestDTO

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);
}
Also used : CredentialsBO(com.nexblocks.authguard.service.model.CredentialsBO) ValidatableResponse(io.restassured.response.ValidatableResponse) CredentialsDTO(com.nexblocks.authguard.api.dto.entities.CredentialsDTO) CreateCredentialsRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO) Test(org.junit.jupiter.api.Test)

Example 7 with CreateCredentialsRequestDTO

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));
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) CreateCredentialsRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO) Test(org.junit.jupiter.api.Test)

Example 8 with CreateCredentialsRequestDTO

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();
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) CreateCredentialsRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO) Test(org.junit.jupiter.api.Test)

Aggregations

CreateCredentialsRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO)8 Test (org.junit.jupiter.api.Test)7 Violation (com.nexblocks.authguard.api.dto.validation.violations.Violation)4 CredentialsBO (com.nexblocks.authguard.service.model.CredentialsBO)4 ValidatableResponse (io.restassured.response.ValidatableResponse)4 CreateAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO)3 CreateCompleteAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountRequestDTO)3 CreateCompleteAccountResponseDTO (com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountResponseDTO)3 AccountBO (com.nexblocks.authguard.service.model.AccountBO)3 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)3 CredentialsDTO (com.nexblocks.authguard.api.dto.entities.CredentialsDTO)2 IdempotencyException (com.nexblocks.authguard.service.exceptions.IdempotencyException)2 CompletionException (java.util.concurrent.CompletionException)2 Inject (com.google.inject.Inject)1 AuthGuardRoles (com.nexblocks.authguard.api.access.AuthGuardRoles)1 Error (com.nexblocks.authguard.api.dto.entities.Error)1 UserIdentifierDTO (com.nexblocks.authguard.api.dto.entities.UserIdentifierDTO)1 PasswordResetRequestDTO (com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO)1 PasswordResetTokenRequestDTO (com.nexblocks.authguard.api.dto.requests.PasswordResetTokenRequestDTO)1 UserIdentifiersRequestDTO (com.nexblocks.authguard.api.dto.requests.UserIdentifiersRequestDTO)1