From 5a8d95f3b60f4ac463e45bc5e26acefaf9e0fbc3 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 8 Sep 2022 12:09:01 +0200 Subject: [PATCH 1/3] fix: fixing no tenant set when attempt to retrieve consultant data --- .../api/tenant/MultitenancyWithSingleDomainTenantResolver.java | 3 +++ .../tenant/MultitenancyWithSingleDomainTenantResolverTest.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolver.java b/src/main/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolver.java index e69cd6441..007b410c5 100644 --- a/src/main/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolver.java +++ b/src/main/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolver.java @@ -49,7 +49,10 @@ public Optional resolve(HttpServletRequest request) { } private Optional resolveTenantFromConsultantRequestParameter() { + // temporarily set technical tenant to be able to run query during tenant determination + TenantContext.setCurrentTenant(0L); Optional consultant = consultantService.getConsultant(getConsultantId()); + TenantContext.clear(); if (consultant.isPresent()) { return Optional.of(consultant.get().getTenantId()); } diff --git a/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java b/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java index 7a55efeda..0fb9d7653 100644 --- a/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java @@ -87,6 +87,7 @@ void resolve_Should_ResolveToEmpty_When_FeatureMultitenancyWithSingleDomainIsDis assertThat(multitenancyWithSingleDomainTenantResolver.canResolve(request)).isTrue(); assertThat(multitenancyWithSingleDomainTenantResolver.resolve(request)) .isEqualTo(Optional.of(ANOTHER_TENANT)); + assertThat(TenantContext.getCurrentTenant()).isNull(); } @Test @@ -106,6 +107,7 @@ void resolve_Should_ResolveToEmpty_When_FeatureMultitenancyWithSingleDomainIsDis // when assertThat(multitenancyWithSingleDomainTenantResolver.canResolve(request)).isFalse(); assertThat(multitenancyWithSingleDomainTenantResolver.resolve(request)).isEmpty(); + assertThat(TenantContext.getCurrentTenant()).isNull(); } @Test From 472524b9498d39a5919b302deb565d4d70c8546f Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 8 Sep 2022 12:22:40 +0200 Subject: [PATCH 2/3] fix: fixing no tenant set when attempt to retrieve consultant data --- .../MultitenancyWithSingleDomainTenantResolverTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java b/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java index 0fb9d7653..fdf42791c 100644 --- a/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java @@ -14,6 +14,7 @@ import javax.servlet.http.HttpServletRequest; import org.jeasy.random.EasyRandom; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -42,6 +43,10 @@ class MultitenancyWithSingleDomainTenantResolverTest { @Mock private ServletRequestAttributes requestAttributes; + @BeforeEach + public void initialize() { + TenantContext.clear(); + } @AfterEach public void tearDown() { resetRequestAttributes(); From 4aedfd326acadbc6161115d5353abc0dff7ea13a Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 8 Sep 2022 12:25:23 +0200 Subject: [PATCH 3/3] fix: fixing no tenant set when attempt to retrieve consultant data --- .../tenant/MultitenancyWithSingleDomainTenantResolverTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java b/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java index fdf42791c..19aad5716 100644 --- a/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/tenant/MultitenancyWithSingleDomainTenantResolverTest.java @@ -47,6 +47,7 @@ class MultitenancyWithSingleDomainTenantResolverTest { public void initialize() { TenantContext.clear(); } + @AfterEach public void tearDown() { resetRequestAttributes();