Skip to content

Commit

Permalink
Merge pull request Onlineberatung#488 from Onlineberatung/VIC-1461-fi…
Browse files Browse the repository at this point in the history
…x-tenant-resolution-in-case-of-direct-consultant-link

fix: fixing no tenant set when attempt to retrieve consultant data
  • Loading branch information
tkuzynow authored Sep 8, 2022
2 parents e834883 + 4aedfd3 commit 5da7851
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public Optional<Long> resolve(HttpServletRequest request) {
}

private Optional<Long> resolveTenantFromConsultantRequestParameter() {
// temporarily set technical tenant to be able to run query during tenant determination
TenantContext.setCurrentTenant(0L);
Optional<Consultant> consultant = consultantService.getConsultant(getConsultantId());
TenantContext.clear();
if (consultant.isPresent()) {
return Optional.of(consultant.get().getTenantId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,6 +43,11 @@ class MultitenancyWithSingleDomainTenantResolverTest {

@Mock private ServletRequestAttributes requestAttributes;

@BeforeEach
public void initialize() {
TenantContext.clear();
}

@AfterEach
public void tearDown() {
resetRequestAttributes();
Expand Down Expand Up @@ -87,6 +93,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
Expand All @@ -106,6 +113,7 @@ void resolve_Should_ResolveToEmpty_When_FeatureMultitenancyWithSingleDomainIsDis
// when
assertThat(multitenancyWithSingleDomainTenantResolver.canResolve(request)).isFalse();
assertThat(multitenancyWithSingleDomainTenantResolver.resolve(request)).isEmpty();
assertThat(TenantContext.getCurrentTenant()).isNull();
}

@Test
Expand Down

0 comments on commit 5da7851

Please sign in to comment.