1
0

fix credentials-api-paths+includes

This commit is contained in:
Michael Hoennig
2025-05-21 10:25:18 +02:00
parent f4bf614d77
commit 037bbf5a4c
10 changed files with 94 additions and 95 deletions

View File

@@ -97,7 +97,7 @@ class HsCredentialsContextsControllerRestTest {
// when
mockMvc.perform(MockMvcRequestBuilders
.get("/api/login/contexts")
.get("/api/hs/credentials/contexts")
.header("Authorization", "Bearer superuser-alex@hostsharing.net")
.accept(MediaType.APPLICATION_JSON))
.andDo(print())

View File

@@ -1,8 +1,7 @@
package net.hostsharing.hsadminng.credentials;
import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginContextResource;
import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginContextTypeResource;
import net.hostsharing.hsadminng.credentials.generated.api.v1.model.LoginCredentialsPatchResource;
import net.hostsharing.hsadminng.credentials.generated.api.v1.model.ContextResource;
import net.hostsharing.hsadminng.credentials.generated.api.v1.model.CredentialsPatchResource;
import net.hostsharing.hsadminng.rbac.test.PatchUnitTestBase;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance;
@@ -24,7 +23,7 @@ import static org.mockito.Mockito.lenient;
@TestInstance(PER_CLASS)
@ExtendWith(MockitoExtension.class)
class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase<
LoginCredentialsPatchResource,
CredentialsPatchResource,
HsCredentialsEntity
> {
@@ -58,8 +57,8 @@ class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase<
.qualifier("dev")
.build();
private LoginContextResource patchContextResource2;
private LoginContextResource patchContextResource3;
private ContextResource patchContextResource2;
private ContextResource patchContextResource3;
// This is what em.find should return for CONTEXT_UUID_3
private final HsCredentialsContextRealEntity newContextEntity3 = HsCredentialsContextRealEntity.builder()
@@ -69,7 +68,7 @@ class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase<
.build();
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);
@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_3))).thenReturn(newContextEntity3);
patchContextResource2 = new LoginContextResource();
patchContextResource2 = new ContextResource();
patchContextResource2.setUuid(CONTEXT_UUID_2);
patchContextResource2.setType(LoginContextTypeResource.SSH);
patchContextResource2.setType("SSH");
patchContextResource2.setQualifier("dev");
patchContextResource3 = new LoginContextResource();
patchContextResource3 = new ContextResource();
patchContextResource3.setUuid(CONTEXT_UUID_3);
patchContextResource3.setType(LoginContextTypeResource.HSADMIN);
patchContextResource3.setType("HSADMIN");
patchContextResource3.setQualifier("test");
patchedContextResources = List.of(patchContextResource2, patchContextResource3);
@@ -110,8 +109,8 @@ class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase<
}
@Override
protected LoginCredentialsPatchResource newPatchResource() {
return new LoginCredentialsPatchResource();
protected CredentialsPatchResource newPatchResource() {
return new CredentialsPatchResource();
}
@Override
@@ -124,38 +123,38 @@ class HsCredentialsEntityPatcherUnitTest extends PatchUnitTestBase<
return Stream.of(
new SimpleProperty<>(
"active",
LoginCredentialsPatchResource::setActive,
CredentialsPatchResource::setActive,
PATCHED_ACTIVE,
HsCredentialsEntity::setActive,
PATCHED_ACTIVE)
.notNullable(),
new JsonNullableProperty<>(
"emailAddress",
LoginCredentialsPatchResource::setEmailAddress,
CredentialsPatchResource::setEmailAddress,
PATCHED_EMAIL_ADDRESS,
HsCredentialsEntity::setEmailAddress,
PATCHED_EMAIL_ADDRESS),
new JsonNullableProperty<>(
"twoFactorAuth",
LoginCredentialsPatchResource::setTwoFactorAuth,
CredentialsPatchResource::setTwoFactorAuth,
PATCHED_TWO_FACTOR_AUTH,
HsCredentialsEntity::setTwoFactorAuth,
PATCHED_TWO_FACTOR_AUTH),
new JsonNullableProperty<>(
"smsNumber",
LoginCredentialsPatchResource::setSmsNumber,
CredentialsPatchResource::setSmsNumber,
PATCHED_SMS_NUMBER,
HsCredentialsEntity::setSmsNumber,
PATCHED_SMS_NUMBER),
new JsonNullableProperty<>(
"phonePassword",
LoginCredentialsPatchResource::setPhonePassword,
CredentialsPatchResource::setPhonePassword,
PATCHED_PHONE_PASSWORD,
HsCredentialsEntity::setPhonePassword,
PATCHED_PHONE_PASSWORD),
new SimpleProperty<>(
"contexts",
LoginCredentialsPatchResource::setContexts,
CredentialsPatchResource::setContexts,
patchedContextResources,
HsCredentialsEntity::setLoginContexts,
expectedPatchedContextEntities)

View File

@@ -42,7 +42,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest {
HttpServletRequest request;
@Autowired
private HsCredentialsRepository loginCredentialsRepository;
private HsCredentialsRepository credentialsRepository;
@Autowired
private HsCredentialsContextRealRepository loginContextRealRepo;
@@ -88,7 +88,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest {
@Test
void shouldFindByUuidUsingTestData() {
// when
final var foundEntityOptional = loginCredentialsRepository.findByUuid(alexSubject.getUuid());
final var foundEntityOptional = credentialsRepository.findByUuid(alexSubject.getUuid());
// then
assertThat(foundEntityOptional).isPresent()
@@ -96,7 +96,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest {
}
@Test
void shouldSaveLoginCredentialsWithExistingContext() {
void shouldSaveCredentialsWithExistingContext() {
// given
final var existingContext = loginContextRealRepo.findByTypeAndQualifier("HSADMIN", "prod")
.orElseThrow();
@@ -111,12 +111,12 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest {
.build();
// when
loginCredentialsRepository.save(newCredentials);
credentialsRepository.save(newCredentials);
em.flush();
em.clear();
// then
final var foundEntityOptional = loginCredentialsRepository.findByUuid(drewSubject.getUuid());
final var foundEntityOptional = credentialsRepository.findByUuid(drewSubject.getUuid());
assertThat(foundEntityOptional).isPresent();
final var foundEntity = foundEntityOptional.get();
assertThat(foundEntity.getEmailAddress()).isEqualTo("drew.new@example.com");
@@ -129,7 +129,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest {
}
@Test
void shouldNotSaveLoginCredentialsWithNewContext() {
void shouldNotSaveCredentialsWithNewContext() {
// given
final var newContext = HsCredentialsContextRealEntity.builder()
.type("MATRIX")
@@ -146,7 +146,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest {
// when
final var exception = catchThrowable(() -> {
loginCredentialsRepository.save(newCredentials);
credentialsRepository.save(newCredentials);
em.flush();
});
@@ -155,7 +155,7 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest {
}
@Test
void shouldSaveNewLoginCredentialsWithoutContext() {
void shouldSaveNewCredentialsWithoutContext() {
// given
final var newCredentials = HsCredentialsEntity.builder()
.subject(testUserSubject)
@@ -167,12 +167,12 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest {
.build();
// when
loginCredentialsRepository.save(newCredentials);
credentialsRepository.save(newCredentials);
em.flush();
em.clear();
// then
final var foundEntityOptional = loginCredentialsRepository.findByUuid(testUserSubject.getUuid());
final var foundEntityOptional = credentialsRepository.findByUuid(testUserSubject.getUuid());
assertThat(foundEntityOptional).isPresent();
final var foundEntity = foundEntityOptional.get();
assertThat(foundEntity.getEmailAddress()).isEqualTo("test.user.new@example.com");
@@ -183,21 +183,21 @@ class HsCredentialsRepositoryIntegrationTest extends ContextBasedTest {
}
@Test
void shouldUpdateExistingLoginCredentials() {
void shouldUpdateExistingCredentials() {
// given
final var entityToUpdate = loginCredentialsRepository.findByUuid(alexSubject.getUuid()).orElseThrow();
final var entityToUpdate = credentialsRepository.findByUuid(alexSubject.getUuid()).orElseThrow();
final var initialVersion = entityToUpdate.getVersion();
// when
entityToUpdate.setActive(false);
entityToUpdate.setEmailAddress("updated.user1@example.com");
final var savedEntity = loginCredentialsRepository.save(entityToUpdate);
final var savedEntity = credentialsRepository.save(entityToUpdate);
em.flush();
em.clear();
// then
assertThat(savedEntity.getVersion()).isGreaterThan(initialVersion);
final var updatedEntityOptional = loginCredentialsRepository.findByUuid(alexSubject.getUuid());
final var updatedEntityOptional = credentialsRepository.findByUuid(alexSubject.getUuid());
assertThat(updatedEntityOptional).isPresent();
final var updatedEntity = updatedEntityOptional.get();
assertThat(updatedEntity.isActive()).isFalse();