fix credentials-api-paths+includes
This commit is contained in:
		| @@ -1,13 +1,13 @@ | |||||||
| classDiagram | classDiagram | ||||||
|     direction LR |     direction LR | ||||||
|  |  | ||||||
|     OfficePerson o.. "*" LoginCredentials |     OfficePerson o.. "*" Credentials | ||||||
|     LoginCredentials "1" o-- "1" RbacSubject |     Credentials "1" o-- "1" RbacSubject | ||||||
|  |  | ||||||
|     LoginContext "1..n" --o "1" LoginContextMapping |     CredentialsContext "1..n" --o "1" CredentialsContextMapping | ||||||
|     LoginCredentials "1..n" --o "1" LoginContextMapping |     Credentials "1..n" --o "1" CredentialsContextMapping | ||||||
|  |  | ||||||
|     class LoginCredentials{ |     class Credentials{ | ||||||
|         +twoFactorAuth: text |         +twoFactorAuth: text | ||||||
|         +telephonePassword: text |         +telephonePassword: text | ||||||
|         +emailAdress: text |         +emailAdress: text | ||||||
| @@ -18,14 +18,14 @@ classDiagram | |||||||
|         -onboardingToken: text [w/o] |         -onboardingToken: text [w/o] | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     class LoginContext{ |     class CredentialsContext{ | ||||||
|         -type: Enum [SSH, Matrix, Mastodon, ...] |         -type: Enum [SSH, Matrix, Mastodon, ...] | ||||||
|         -qualifier: text |         -qualifier: text | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     class LoginContextMapping{ |     class CredentialsContextMapping{ | ||||||
|     } |     } | ||||||
|     note for LoginContextMapping "Assigns LoginCredentials to LoginContexts" |     note for CredentialsContextMapping "Assigns Credentials to CredentialsContexts" | ||||||
|  |  | ||||||
|     class RbacSubject{ |     class RbacSubject{ | ||||||
|         +uuid: uuid |         +uuid: uuid | ||||||
| @@ -41,9 +41,9 @@ classDiagram | |||||||
|         +salutation: text |         +salutation: text | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     style LoginContext fill:#00f,color:#fff |     style CredentialsContext fill:#00f,color:#fff | ||||||
|     style LoginContextMapping fill:#00f,color:#fff |     style CredentialsContextMapping fill:#00f,color:#fff | ||||||
|     style LoginCredentials fill:#00f,color:#fff |     style Credentials fill:#00f,color:#fff | ||||||
|  |  | ||||||
|     style RbacSubject fill:#f96,color:#fff |     style RbacSubject fill:#f96,color:#fff | ||||||
|     style OfficePerson fill:#f66,color:#000 |     style OfficePerson fill:#f66,color:#000 | ||||||
|   | |||||||
| @@ -5,8 +5,8 @@ import java.util.List; | |||||||
| import io.micrometer.core.annotation.Timed; | import io.micrometer.core.annotation.Timed; | ||||||
| import net.hostsharing.hsadminng.config.NoSecurityRequirement; | import net.hostsharing.hsadminng.config.NoSecurityRequirement; | ||||||
| import net.hostsharing.hsadminng.context.Context; | import net.hostsharing.hsadminng.context.Context; | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.api.LoginContextsApi; | import net.hostsharing.hsadminng.credentials.generated.api.v1.api.ContextsApi; | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginContextResource; | import net.hostsharing.hsadminng.credentials.generated.api.v1.model.ContextResource; | ||||||
| import net.hostsharing.hsadminng.mapper.StrictMapper; | import net.hostsharing.hsadminng.mapper.StrictMapper; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.http.ResponseEntity; | import org.springframework.http.ResponseEntity; | ||||||
| @@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController; | |||||||
|  |  | ||||||
| @RestController | @RestController | ||||||
| @NoSecurityRequirement | @NoSecurityRequirement | ||||||
| public class HsCredentialsContextsController implements LoginContextsApi { | public class HsCredentialsContextsController implements ContextsApi { | ||||||
|  |  | ||||||
|     @Autowired |     @Autowired | ||||||
|     private Context context; |     private Context context; | ||||||
| @@ -27,11 +27,11 @@ public class HsCredentialsContextsController implements LoginContextsApi { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Timed("app.credentials.contexts.getListOfLoginContexts") |     @Timed("app.credentials.contexts.getListOfLoginContexts") | ||||||
|     public ResponseEntity<List<LoginContextResource>> getListOfLoginContexts(final String assumedRoles) { |     public ResponseEntity<List<ContextResource>> getListOfContexts(final String assumedRoles) { | ||||||
|         context.assumeRoles(assumedRoles); |         context.assumeRoles(assumedRoles); | ||||||
|  |  | ||||||
|         final var loginContexts = contextRepo.findAll(); |         final var loginContexts = contextRepo.findAll(); | ||||||
|         final var result = mapper.mapList(loginContexts, LoginContextResource.class); |         final var result = mapper.mapList(loginContexts, ContextResource.class); | ||||||
|         return ResponseEntity.ok(result); |         return ResponseEntity.ok(result); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,10 +6,10 @@ import java.util.UUID; | |||||||
| import io.micrometer.core.annotation.Timed; | import io.micrometer.core.annotation.Timed; | ||||||
| import io.swagger.v3.oas.annotations.security.SecurityRequirement; | import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||||||
| import net.hostsharing.hsadminng.context.Context; | import net.hostsharing.hsadminng.context.Context; | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.api.LoginCredentialsApi; | import net.hostsharing.hsadminng.credentials.generated.api.v1.api.CredentialsApi; | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginCredentialsInsertResource; | import net.hostsharing.hsadminng.credentials.generated.api.v1.model.CredentialsInsertResource; | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginCredentialsPatchResource; | import net.hostsharing.hsadminng.credentials.generated.api.v1.model.CredentialsPatchResource; | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginCredentialsResource; | import net.hostsharing.hsadminng.credentials.generated.api.v1.model.CredentialsResource; | ||||||
| import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRbacRepository; | import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRbacRepository; | ||||||
| import net.hostsharing.hsadminng.mapper.StrictMapper; | import net.hostsharing.hsadminng.mapper.StrictMapper; | ||||||
| import net.hostsharing.hsadminng.persistence.EntityManagerWrapper; | import net.hostsharing.hsadminng.persistence.EntityManagerWrapper; | ||||||
| @@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.RestController; | |||||||
|  |  | ||||||
| @RestController | @RestController | ||||||
| @SecurityRequirement(name = "casTicket") | @SecurityRequirement(name = "casTicket") | ||||||
| public class HsCredentialsController implements LoginCredentialsApi { | public class HsCredentialsController implements CredentialsApi { | ||||||
|  |  | ||||||
|     @Autowired |     @Autowired | ||||||
|     private Context context; |     private Context context; | ||||||
| @@ -34,72 +34,72 @@ public class HsCredentialsController implements LoginCredentialsApi { | |||||||
|     private HsOfficePersonRbacRepository personRepo; |     private HsOfficePersonRbacRepository personRepo; | ||||||
|  |  | ||||||
|     @Autowired |     @Autowired | ||||||
|     private HsCredentialsRepository loginCredentialsRepo; |     private HsCredentialsRepository credentialsRepo; | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Timed("app.credentials.credentials.getSingleLoginCredentialsByUuid") |     @Timed("app.credentials.credentials.getSingleCredentialsByUuid") | ||||||
|     public ResponseEntity<LoginCredentialsResource> getSingleLoginCredentialsByUuid( |     public ResponseEntity<CredentialsResource> getSingleCredentialsByUuid( | ||||||
|             final String assumedRoles, |             final String assumedRoles, | ||||||
|             final UUID loginCredentialsUuid) { |             final UUID credentialsUuid) { | ||||||
|         context.assumeRoles(assumedRoles); |         context.assumeRoles(assumedRoles); | ||||||
|  |  | ||||||
|         final var credentials = loginCredentialsRepo.findByUuid(loginCredentialsUuid); |         final var credentials = credentialsRepo.findByUuid(credentialsUuid); | ||||||
|         final var result = mapper.map(credentials, LoginCredentialsResource.class); |         final var result = mapper.map(credentials, CredentialsResource.class); | ||||||
|         return ResponseEntity.ok(result); |         return ResponseEntity.ok(result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Timed("app.credentials.credentials.getListOfLoginCredentialsByPersonUuid") |     @Timed("app.credentials.credentials.getListOfCredentialsByPersonUuid") | ||||||
|     public ResponseEntity<List<LoginCredentialsResource>> getListOfLoginCredentialsByPersonUuid( |     public ResponseEntity<List<CredentialsResource>> getListOfCredentialsByPersonUuid( | ||||||
|             final String assumedRoles, |             final String assumedRoles, | ||||||
|             final UUID personUuid |             final UUID personUuid | ||||||
|     ) { |     ) { | ||||||
|         context.assumeRoles(assumedRoles); |         context.assumeRoles(assumedRoles); | ||||||
|  |  | ||||||
|         final var person = personRepo.findByUuid(personUuid).orElseThrow(); // FIXME: use proper exception |         final var person = personRepo.findByUuid(personUuid).orElseThrow(); // FIXME: use proper exception | ||||||
|         final var credentials = loginCredentialsRepo.findByPerson(person); |         final var credentials = credentialsRepo.findByPerson(person); | ||||||
|         final var result = mapper.mapList(credentials, LoginCredentialsResource.class); |         final var result = mapper.mapList(credentials, CredentialsResource.class); | ||||||
|         return ResponseEntity.ok(result); |         return ResponseEntity.ok(result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Timed("app.credentials.credentials.postNewLoginCredentials") |     @Timed("app.credentials.credentials.postNewCredentials") | ||||||
|     public ResponseEntity<LoginCredentialsResource> postNewLoginCredentials( |     public ResponseEntity<CredentialsResource> postNewCredentials( | ||||||
|             final String assumedRoles, |             final String assumedRoles, | ||||||
|             final LoginCredentialsInsertResource body |             final CredentialsInsertResource body | ||||||
|     ) { |     ) { | ||||||
|         context.assumeRoles(assumedRoles); |         context.assumeRoles(assumedRoles); | ||||||
|  |  | ||||||
|         final var newLoginCredentialsEntity = mapper.map(body, HsCredentialsEntity.class); |         final var newCredentialsEntity = mapper.map(body, HsCredentialsEntity.class); | ||||||
|         final var savedLoginCredentialsEntity = loginCredentialsRepo.save(newLoginCredentialsEntity); |         final var savedCredentialsEntity = credentialsRepo.save(newCredentialsEntity); | ||||||
|         final var newLoginCredentialsResource = mapper.map(savedLoginCredentialsEntity, LoginCredentialsResource.class); |         final var newCredentialsResource = mapper.map(savedCredentialsEntity, CredentialsResource.class); | ||||||
|         return ResponseEntity.ok(newLoginCredentialsResource); |         return ResponseEntity.ok(newCredentialsResource); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Timed("app.credentials.credentials.deleteLoginCredentialsByUuid") |     @Timed("app.credentials.credentials.deleteCredentialsByUuid") | ||||||
|     public ResponseEntity<Void> deleteLoginCredentialsByUuid(final String assumedRoles, final UUID loginCredentialsUuid) { |     public ResponseEntity<Void> deleteCredentialsByUuid(final String assumedRoles, final UUID credentialsUuid) { | ||||||
|         context.assumeRoles(assumedRoles); |         context.assumeRoles(assumedRoles); | ||||||
|         final var loginCredentialsEntity = em.getReference(HsCredentialsEntity.class, loginCredentialsUuid); |         final var credentialsEntity = em.getReference(HsCredentialsEntity.class, credentialsUuid); | ||||||
|         em.remove(loginCredentialsEntity); |         em.remove(credentialsEntity); | ||||||
|         return ResponseEntity.noContent().build(); |         return ResponseEntity.noContent().build(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     @Timed("app.credentials.credentials.patchLoginCredentials") |     @Timed("app.credentials.credentials.patchCredentials") | ||||||
|     public ResponseEntity<LoginCredentialsResource> patchLoginCredentials( |     public ResponseEntity<CredentialsResource> patchCredentials( | ||||||
|             final String assumedRoles, |             final String assumedRoles, | ||||||
|             final UUID loginCredentialsUuid, |             final UUID credentialsUuid, | ||||||
|             final LoginCredentialsPatchResource body |             final CredentialsPatchResource body | ||||||
|     ) { |     ) { | ||||||
|         context.assumeRoles(assumedRoles); |         context.assumeRoles(assumedRoles); | ||||||
|  |  | ||||||
|         final var current = loginCredentialsRepo.findByUuid(loginCredentialsUuid).orElseThrow(); |         final var current = credentialsRepo.findByUuid(credentialsUuid).orElseThrow(); | ||||||
|  |  | ||||||
|         new HsCredentialsEntityPatcher(em, current).apply(body); |         new HsCredentialsEntityPatcher(em, current).apply(body); | ||||||
|  |  | ||||||
|         final var saved = loginCredentialsRepo.save(current); |         final var saved = credentialsRepo.save(current); | ||||||
|         final var mapped = mapper.map(saved, LoginCredentialsResource.class); |         final var mapped = mapper.map(saved, CredentialsResource.class); | ||||||
|         return ResponseEntity.ok(mapped); |         return ResponseEntity.ok(mapped); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ import static net.hostsharing.hsadminng.repr.Stringify.stringify; | |||||||
| @AllArgsConstructor | @AllArgsConstructor | ||||||
| public class HsCredentialsEntity implements BaseEntity<HsCredentialsEntity>, Stringifyable { | public class HsCredentialsEntity implements BaseEntity<HsCredentialsEntity>, Stringifyable { | ||||||
|  |  | ||||||
|     protected static Stringify<HsCredentialsEntity> stringify = stringify(HsCredentialsEntity.class, "loginCredentials") |     protected static Stringify<HsCredentialsEntity> stringify = stringify(HsCredentialsEntity.class, "credentials") | ||||||
|             .withProp(HsCredentialsEntity::isActive) |             .withProp(HsCredentialsEntity::isActive) | ||||||
|             .withProp(HsCredentialsEntity::getEmailAddress) |             .withProp(HsCredentialsEntity::getEmailAddress) | ||||||
|             .withProp(HsCredentialsEntity::getTwoFactorAuth) |             .withProp(HsCredentialsEntity::getTwoFactorAuth) | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| package net.hostsharing.hsadminng.credentials; | package net.hostsharing.hsadminng.credentials; | ||||||
|  |  | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginContextResource; | import net.hostsharing.hsadminng.credentials.generated.api.v1.model.ContextResource; | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginCredentialsPatchResource; | import net.hostsharing.hsadminng.credentials.generated.api.v1.model.CredentialsPatchResource; | ||||||
| import net.hostsharing.hsadminng.mapper.EntityPatcher; | import net.hostsharing.hsadminng.mapper.EntityPatcher; | ||||||
| import net.hostsharing.hsadminng.mapper.OptionalFromJson; | import net.hostsharing.hsadminng.mapper.OptionalFromJson; | ||||||
|  |  | ||||||
| @@ -11,7 +11,7 @@ import java.util.List; | |||||||
| import java.util.Set; | import java.util.Set; | ||||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||||
|  |  | ||||||
| public class HsCredentialsEntityPatcher implements EntityPatcher<LoginCredentialsPatchResource> { | public class HsCredentialsEntityPatcher implements EntityPatcher<CredentialsPatchResource> { | ||||||
|  |  | ||||||
|     private final EntityManager em; |     private final EntityManager em; | ||||||
|     private final HsCredentialsEntity entity; |     private final HsCredentialsEntity entity; | ||||||
| @@ -22,7 +22,7 @@ public class HsCredentialsEntityPatcher implements EntityPatcher<LoginCredential | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void apply(final LoginCredentialsPatchResource resource) { |     public void apply(final CredentialsPatchResource resource) { | ||||||
|         if ( resource.getActive() != null ) { |         if ( resource.getActive() != null ) { | ||||||
|                 entity.setActive(resource.getActive()); |                 entity.setActive(resource.getActive()); | ||||||
|         } |         } | ||||||
| @@ -40,11 +40,11 @@ public class HsCredentialsEntityPatcher implements EntityPatcher<LoginCredential | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void syncLoginContextEntities( |     public void syncLoginContextEntities( | ||||||
|             List<LoginContextResource> resources, |             List<ContextResource> resources, | ||||||
|             Set<HsCredentialsContextRealEntity> entities |             Set<HsCredentialsContextRealEntity> entities | ||||||
|     ) { |     ) { | ||||||
|         final var resourceUuids = resources.stream() |         final var resourceUuids = resources.stream() | ||||||
|                 .map(LoginContextResource::getUuid) |                 .map(ContextResource::getUuid) | ||||||
|                 .collect(Collectors.toSet()); |                 .collect(Collectors.toSet()); | ||||||
|  |  | ||||||
|         final var entityUuids = entities.stream() |         final var entityUuids = entities.stream() | ||||||
| @@ -61,7 +61,7 @@ public class HsCredentialsEntityPatcher implements EntityPatcher<LoginCredential | |||||||
|                     throw new EntityNotFoundException( |                     throw new EntityNotFoundException( | ||||||
|                             HsCredentialsContextRealEntity.class.getName() + " with uuid " + resource.getUuid() + " not found."); |                             HsCredentialsContextRealEntity.class.getName() + " with uuid " + resource.getUuid() + " not found."); | ||||||
|                 } |                 } | ||||||
|                 if (!existingContextEntity.getType().equals(resource.getType().name()) && |                 if (!existingContextEntity.getType().equals(resource.getType()) && | ||||||
|                     !existingContextEntity.getQualifier().equals(resource.getQualifier())) { |                     !existingContextEntity.getQualifier().equals(resource.getQualifier())) { | ||||||
|                     // FIXME: i18n |                     // FIXME: i18n | ||||||
|                     throw new EntityNotFoundException("existing " +  existingContextEntity + " does not match given resource " + resource); |                     throw new EntityNotFoundException("existing " +  existingContextEntity + " does not match given resource " + resource); | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ paths: | |||||||
|   # Credentials |   # Credentials | ||||||
|  |  | ||||||
|   /api/hs/credentials/credentials: |   /api/hs/credentials/credentials: | ||||||
|     $ref: "api-paths.yaml" |     $ref: "credentials.yaml" | ||||||
|  |  | ||||||
|   /api/hs/credentials/credentials/{credentialsUuid}: |   /api/hs/credentials/credentials/{credentialsUuid}: | ||||||
|     $ref: "credentials-with-uuid.yaml" |     $ref: "credentials-with-uuid.yaml" | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ components: | |||||||
|                 contexts: |                 contexts: | ||||||
|                     type: array |                     type: array | ||||||
|                     items: |                     items: | ||||||
|                         $ref: '-context-schemas.yaml#/components/schemas/Context' |                         $ref: 'context-schemas.yaml#/components/schemas/Context' | ||||||
|             required: |             required: | ||||||
|                 - uuid |                 - uuid | ||||||
|                 - active |                 - active | ||||||
| @@ -55,7 +55,7 @@ components: | |||||||
|                 contexts: |                 contexts: | ||||||
|                     type: array |                     type: array | ||||||
|                     items: |                     items: | ||||||
|                         $ref: '-context-schemas.yaml#/components/schemas/Context' |                         $ref: 'context-schemas.yaml#/components/schemas/Context' | ||||||
|             additionalProperties: false |             additionalProperties: false | ||||||
|  |  | ||||||
|         CredentialsInsert: |         CredentialsInsert: | ||||||
| @@ -83,7 +83,7 @@ components: | |||||||
|                 contexts: |                 contexts: | ||||||
|                     type: array |                     type: array | ||||||
|                     items: |                     items: | ||||||
|                         $ref: '-context-schemas.yaml#/components/schemas/Context' |                         $ref: 'context-schemas.yaml#/components/schemas/Context' | ||||||
|             required: |             required: | ||||||
|                 - uuid |                 - uuid | ||||||
|                 - active |                 - active | ||||||
|   | |||||||
| @@ -97,7 +97,7 @@ class HsCredentialsContextsControllerRestTest { | |||||||
|  |  | ||||||
|         // when |         // when | ||||||
|         mockMvc.perform(MockMvcRequestBuilders |         mockMvc.perform(MockMvcRequestBuilders | ||||||
|                 .get("/api/login/contexts") |                 .get("/api/hs/credentials/contexts") | ||||||
|                 .header("Authorization", "Bearer superuser-alex@hostsharing.net") |                 .header("Authorization", "Bearer superuser-alex@hostsharing.net") | ||||||
|                 .accept(MediaType.APPLICATION_JSON)) |                 .accept(MediaType.APPLICATION_JSON)) | ||||||
|                 .andDo(print()) |                 .andDo(print()) | ||||||
|   | |||||||
| @@ -1,8 +1,7 @@ | |||||||
| package net.hostsharing.hsadminng.credentials; | package net.hostsharing.hsadminng.credentials; | ||||||
|  |  | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginContextResource; | import net.hostsharing.hsadminng.credentials.generated.api.v1.model.ContextResource; | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginContextTypeResource; | import net.hostsharing.hsadminng.credentials.generated.api.v1.model.CredentialsPatchResource; | ||||||
| import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginCredentialsPatchResource; |  | ||||||
| import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; | import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase; | ||||||
| import org.junit.jupiter.api.BeforeEach; | import org.junit.jupiter.api.BeforeEach; | ||||||
| import org.junit.jupiter.api.TestInstance; | import org.junit.jupiter.api.TestInstance; | ||||||
| @@ -24,7 +23,7 @@ import static org.mockito.Mockito.lenient; | |||||||
| @TestInstance(PER_CLASS) | @TestInstance(PER_CLASS) | ||||||
| @ExtendWith(MockitoExtension.class) | @ExtendWith(MockitoExtension.class) | ||||||
| class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase< | class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase< | ||||||
|         LoginCredentialsPatchResource, |         CredentialsPatchResource, | ||||||
|         HsCredentialsEntity |         HsCredentialsEntity | ||||||
|         > { |         > { | ||||||
|  |  | ||||||
| @@ -58,8 +57,8 @@ class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase< | |||||||
|             .qualifier("dev") |             .qualifier("dev") | ||||||
|             .build(); |             .build(); | ||||||
|  |  | ||||||
|     private LoginContextResource patchContextResource2; |     private ContextResource patchContextResource2; | ||||||
|     private LoginContextResource patchContextResource3; |     private ContextResource patchContextResource3; | ||||||
|  |  | ||||||
|     // This is what em.find should return for CONTEXT_UUID_3 |     // This is what em.find should return for CONTEXT_UUID_3 | ||||||
|     private final HsCredentialsContextRealEntity newContextEntity3 = HsCredentialsContextRealEntity.builder() |     private final HsCredentialsContextRealEntity newContextEntity3 = HsCredentialsContextRealEntity.builder() | ||||||
| @@ -69,7 +68,7 @@ class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase< | |||||||
|             .build(); |             .build(); | ||||||
|  |  | ||||||
|     private final Set<HsCredentialsContextRealEntity> initialContextEntities = Set.of(initialContextEntity1, initialContextEntity2); |     private final Set<HsCredentialsContextRealEntity> initialContextEntities = Set.of(initialContextEntity1, initialContextEntity2); | ||||||
|     private List<LoginContextResource> patchedContextResources; |     private List<ContextResource> patchedContextResources; | ||||||
|     private final Set<HsCredentialsContextRealEntity> expectedPatchedContextEntities = Set.of(initialContextEntity2, newContextEntity3); |     private final Set<HsCredentialsContextRealEntity> expectedPatchedContextEntities = Set.of(initialContextEntity2, newContextEntity3); | ||||||
|  |  | ||||||
|     @Mock |     @Mock | ||||||
| @@ -82,14 +81,14 @@ class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase< | |||||||
|         lenient().when(em.find(eq(HsCredentialsContextRealEntity.class), eq(CONTEXT_UUID_2))).thenReturn(initialContextEntity2); |         lenient().when(em.find(eq(HsCredentialsContextRealEntity.class), eq(CONTEXT_UUID_2))).thenReturn(initialContextEntity2); | ||||||
|         lenient().when(em.find(eq(HsCredentialsContextRealEntity.class), eq(CONTEXT_UUID_3))).thenReturn(newContextEntity3); |         lenient().when(em.find(eq(HsCredentialsContextRealEntity.class), eq(CONTEXT_UUID_3))).thenReturn(newContextEntity3); | ||||||
|  |  | ||||||
|         patchContextResource2 = new LoginContextResource(); |         patchContextResource2 = new ContextResource(); | ||||||
|         patchContextResource2.setUuid(CONTEXT_UUID_2); |         patchContextResource2.setUuid(CONTEXT_UUID_2); | ||||||
|         patchContextResource2.setType(LoginContextTypeResource.SSH); |         patchContextResource2.setType("SSH"); | ||||||
|         patchContextResource2.setQualifier("dev"); |         patchContextResource2.setQualifier("dev"); | ||||||
|  |  | ||||||
|         patchContextResource3 = new LoginContextResource(); |         patchContextResource3 = new ContextResource(); | ||||||
|         patchContextResource3.setUuid(CONTEXT_UUID_3); |         patchContextResource3.setUuid(CONTEXT_UUID_3); | ||||||
|         patchContextResource3.setType(LoginContextTypeResource.HSADMIN); |         patchContextResource3.setType("HSADMIN"); | ||||||
|         patchContextResource3.setQualifier("test"); |         patchContextResource3.setQualifier("test"); | ||||||
|  |  | ||||||
|         patchedContextResources = List.of(patchContextResource2, patchContextResource3); |         patchedContextResources = List.of(patchContextResource2, patchContextResource3); | ||||||
| @@ -110,8 +109,8 @@ class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase< | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     protected LoginCredentialsPatchResource newPatchResource() { |     protected CredentialsPatchResource newPatchResource() { | ||||||
|         return new LoginCredentialsPatchResource(); |         return new CredentialsPatchResource(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @@ -124,38 +123,38 @@ class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase< | |||||||
|         return Stream.of( |         return Stream.of( | ||||||
|                 new SimpleProperty<>( |                 new SimpleProperty<>( | ||||||
|                         "active", |                         "active", | ||||||
|                         LoginCredentialsPatchResource::setActive, |                         CredentialsPatchResource::setActive, | ||||||
|                         PATCHED_ACTIVE, |                         PATCHED_ACTIVE, | ||||||
|                         HsCredentialsEntity::setActive, |                         HsCredentialsEntity::setActive, | ||||||
|                         PATCHED_ACTIVE) |                         PATCHED_ACTIVE) | ||||||
|                     .notNullable(), |                     .notNullable(), | ||||||
|                 new JsonNullableProperty<>( |                 new JsonNullableProperty<>( | ||||||
|                         "emailAddress", |                         "emailAddress", | ||||||
|                         LoginCredentialsPatchResource::setEmailAddress, |                         CredentialsPatchResource::setEmailAddress, | ||||||
|                         PATCHED_EMAIL_ADDRESS, |                         PATCHED_EMAIL_ADDRESS, | ||||||
|                         HsCredentialsEntity::setEmailAddress, |                         HsCredentialsEntity::setEmailAddress, | ||||||
|                         PATCHED_EMAIL_ADDRESS), |                         PATCHED_EMAIL_ADDRESS), | ||||||
|                 new JsonNullableProperty<>( |                 new JsonNullableProperty<>( | ||||||
|                         "twoFactorAuth", |                         "twoFactorAuth", | ||||||
|                         LoginCredentialsPatchResource::setTwoFactorAuth, |                         CredentialsPatchResource::setTwoFactorAuth, | ||||||
|                         PATCHED_TWO_FACTOR_AUTH, |                         PATCHED_TWO_FACTOR_AUTH, | ||||||
|                         HsCredentialsEntity::setTwoFactorAuth, |                         HsCredentialsEntity::setTwoFactorAuth, | ||||||
|                         PATCHED_TWO_FACTOR_AUTH), |                         PATCHED_TWO_FACTOR_AUTH), | ||||||
|                 new JsonNullableProperty<>( |                 new JsonNullableProperty<>( | ||||||
|                         "smsNumber", |                         "smsNumber", | ||||||
|                         LoginCredentialsPatchResource::setSmsNumber, |                         CredentialsPatchResource::setSmsNumber, | ||||||
|                         PATCHED_SMS_NUMBER, |                         PATCHED_SMS_NUMBER, | ||||||
|                         HsCredentialsEntity::setSmsNumber, |                         HsCredentialsEntity::setSmsNumber, | ||||||
|                         PATCHED_SMS_NUMBER), |                         PATCHED_SMS_NUMBER), | ||||||
|                 new JsonNullableProperty<>( |                 new JsonNullableProperty<>( | ||||||
|                         "phonePassword", |                         "phonePassword", | ||||||
|                         LoginCredentialsPatchResource::setPhonePassword, |                         CredentialsPatchResource::setPhonePassword, | ||||||
|                         PATCHED_PHONE_PASSWORD, |                         PATCHED_PHONE_PASSWORD, | ||||||
|                         HsCredentialsEntity::setPhonePassword, |                         HsCredentialsEntity::setPhonePassword, | ||||||
|                         PATCHED_PHONE_PASSWORD), |                         PATCHED_PHONE_PASSWORD), | ||||||
|                 new SimpleProperty<>( |                 new SimpleProperty<>( | ||||||
|                         "contexts", |                         "contexts", | ||||||
|                         LoginCredentialsPatchResource::setContexts, |                         CredentialsPatchResource::setContexts, | ||||||
|                         patchedContextResources, |                         patchedContextResources, | ||||||
|                         HsCredentialsEntity::setLoginContexts, |                         HsCredentialsEntity::setLoginContexts, | ||||||
|                         expectedPatchedContextEntities) |                         expectedPatchedContextEntities) | ||||||
|   | |||||||
| @@ -42,7 +42,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest { | |||||||
|     HttpServletRequest request; |     HttpServletRequest request; | ||||||
|  |  | ||||||
|     @Autowired |     @Autowired | ||||||
|     private HsCredentialsRepository loginCredentialsRepository; |     private HsCredentialsRepository credentialsRepository; | ||||||
|  |  | ||||||
|     @Autowired |     @Autowired | ||||||
|     private HsCredentialsContextRealRepository loginContextRealRepo; |     private HsCredentialsContextRealRepository loginContextRealRepo; | ||||||
| @@ -88,7 +88,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest { | |||||||
|     @Test |     @Test | ||||||
|     void shouldFindByUuidUsingTestData() { |     void shouldFindByUuidUsingTestData() { | ||||||
|         // when |         // when | ||||||
|         final var foundEntityOptional = loginCredentialsRepository.findByUuid(alexSubject.getUuid()); |         final var foundEntityOptional = credentialsRepository.findByUuid(alexSubject.getUuid()); | ||||||
|  |  | ||||||
|         // then |         // then | ||||||
|         assertThat(foundEntityOptional).isPresent() |         assertThat(foundEntityOptional).isPresent() | ||||||
| @@ -96,7 +96,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Test |     @Test | ||||||
|     void shouldSaveLoginCredentialsWithExistingContext() { |     void shouldSaveCredentialsWithExistingContext() { | ||||||
|         // given |         // given | ||||||
|         final var existingContext = loginContextRealRepo.findByTypeAndQualifier("HSADMIN", "prod") |         final var existingContext = loginContextRealRepo.findByTypeAndQualifier("HSADMIN", "prod") | ||||||
|                 .orElseThrow(); |                 .orElseThrow(); | ||||||
| @@ -111,12 +111,12 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest { | |||||||
|                 .build(); |                 .build(); | ||||||
|  |  | ||||||
|         // when |         // when | ||||||
|         loginCredentialsRepository.save(newCredentials); |         credentialsRepository.save(newCredentials); | ||||||
|         em.flush(); |         em.flush(); | ||||||
|         em.clear(); |         em.clear(); | ||||||
|  |  | ||||||
|         // then |         // then | ||||||
|         final var foundEntityOptional = loginCredentialsRepository.findByUuid(drewSubject.getUuid()); |         final var foundEntityOptional = credentialsRepository.findByUuid(drewSubject.getUuid()); | ||||||
|         assertThat(foundEntityOptional).isPresent(); |         assertThat(foundEntityOptional).isPresent(); | ||||||
|         final var foundEntity = foundEntityOptional.get(); |         final var foundEntity = foundEntityOptional.get(); | ||||||
|         assertThat(foundEntity.getEmailAddress()).isEqualTo("drew.new@example.com"); |         assertThat(foundEntity.getEmailAddress()).isEqualTo("drew.new@example.com"); | ||||||
| @@ -129,7 +129,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Test |     @Test | ||||||
|     void shouldNotSaveLoginCredentialsWithNewContext() { |     void shouldNotSaveCredentialsWithNewContext() { | ||||||
|         // given |         // given | ||||||
|         final var newContext = HsCredentialsContextRealEntity.builder() |         final var newContext = HsCredentialsContextRealEntity.builder() | ||||||
|                 .type("MATRIX") |                 .type("MATRIX") | ||||||
| @@ -146,7 +146,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest { | |||||||
|  |  | ||||||
|         // when |         // when | ||||||
|         final var exception = catchThrowable(() -> { |         final var exception = catchThrowable(() -> { | ||||||
|             loginCredentialsRepository.save(newCredentials); |             credentialsRepository.save(newCredentials); | ||||||
|             em.flush(); |             em.flush(); | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
| @@ -155,7 +155,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Test |     @Test | ||||||
|     void shouldSaveNewLoginCredentialsWithoutContext() { |     void shouldSaveNewCredentialsWithoutContext() { | ||||||
|         // given |         // given | ||||||
|         final var newCredentials = HsCredentialsEntity.builder() |         final var newCredentials = HsCredentialsEntity.builder() | ||||||
|                 .subject(testUserSubject) |                 .subject(testUserSubject) | ||||||
| @@ -167,12 +167,12 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest { | |||||||
|                 .build(); |                 .build(); | ||||||
|  |  | ||||||
|         // when |         // when | ||||||
|         loginCredentialsRepository.save(newCredentials); |         credentialsRepository.save(newCredentials); | ||||||
|         em.flush(); |         em.flush(); | ||||||
|         em.clear(); |         em.clear(); | ||||||
|  |  | ||||||
|         // then |         // then | ||||||
|         final var foundEntityOptional = loginCredentialsRepository.findByUuid(testUserSubject.getUuid()); |         final var foundEntityOptional = credentialsRepository.findByUuid(testUserSubject.getUuid()); | ||||||
|         assertThat(foundEntityOptional).isPresent(); |         assertThat(foundEntityOptional).isPresent(); | ||||||
|         final var foundEntity = foundEntityOptional.get(); |         final var foundEntity = foundEntityOptional.get(); | ||||||
|         assertThat(foundEntity.getEmailAddress()).isEqualTo("test.user.new@example.com"); |         assertThat(foundEntity.getEmailAddress()).isEqualTo("test.user.new@example.com"); | ||||||
| @@ -183,21 +183,21 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Test |     @Test | ||||||
|     void shouldUpdateExistingLoginCredentials() { |     void shouldUpdateExistingCredentials() { | ||||||
|         // given |         // given | ||||||
|         final var entityToUpdate = loginCredentialsRepository.findByUuid(alexSubject.getUuid()).orElseThrow(); |         final var entityToUpdate = credentialsRepository.findByUuid(alexSubject.getUuid()).orElseThrow(); | ||||||
|         final var initialVersion = entityToUpdate.getVersion(); |         final var initialVersion = entityToUpdate.getVersion(); | ||||||
|  |  | ||||||
|         // when |         // when | ||||||
|         entityToUpdate.setActive(false); |         entityToUpdate.setActive(false); | ||||||
|         entityToUpdate.setEmailAddress("updated.user1@example.com"); |         entityToUpdate.setEmailAddress("updated.user1@example.com"); | ||||||
|         final var savedEntity = loginCredentialsRepository.save(entityToUpdate); |         final var savedEntity = credentialsRepository.save(entityToUpdate); | ||||||
|         em.flush(); |         em.flush(); | ||||||
|         em.clear(); |         em.clear(); | ||||||
|  |  | ||||||
|         // then |         // then | ||||||
|         assertThat(savedEntity.getVersion()).isGreaterThan(initialVersion); |         assertThat(savedEntity.getVersion()).isGreaterThan(initialVersion); | ||||||
|         final var updatedEntityOptional = loginCredentialsRepository.findByUuid(alexSubject.getUuid()); |         final var updatedEntityOptional = credentialsRepository.findByUuid(alexSubject.getUuid()); | ||||||
|         assertThat(updatedEntityOptional).isPresent(); |         assertThat(updatedEntityOptional).isPresent(); | ||||||
|         final var updatedEntity = updatedEntityOptional.get(); |         final var updatedEntity = updatedEntityOptional.get(); | ||||||
|         assertThat(updatedEntity.isActive()).isFalse(); |         assertThat(updatedEntity.isActive()).isFalse(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user