Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed exception when a user has no organization #123

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public class ResolveGeorchestraUserGlobalFilter implements GlobalFilter, Ordered
if (usr != null && usr instanceof ExtendedGeorchestraUser) {
ExtendedGeorchestraUser eu = (ExtendedGeorchestraUser) usr;
Organization org = eu.getOrg();
GeorchestraOrganizations.store(exchange, org);
if (org != null) {
GeorchestraOrganizations.store(exchange, org);
}
}
return exchange;
})//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Optional;

import org.georchestra.gateway.model.GeorchestraUsers;
import org.georchestra.gateway.security.ldap.extended.ExtendedGeorchestraUser;
import org.georchestra.security.model.GeorchestraUser;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -121,4 +122,22 @@ void testFilter_UseResolved() {
Optional<GeorchestraUser> resolved = GeorchestraUsers.resolve(exchange);
assertSame(user1, resolved.orElseThrow());
}

@Test
void testFilter_UseResolvedWithoutOrganization() {
Authentication auth1 = mock(Authentication.class);
ExtendedGeorchestraUser user1 = mock(ExtendedGeorchestraUser.class);
when(mockMapper.resolve(same(auth1))).thenReturn(Optional.of(user1));
when(user1.getOrg()).thenReturn(null);

ServerWebExchange exchange = this.exchange.mutate().principal(Mono.just(auth1)).build();

filter.filter(exchange, mockChain).block();

verify(mockChain, times(1)).filter(same(exchange));
verify(mockMapper, times(1)).resolve(any());

Optional<GeorchestraUser> resolved = GeorchestraUsers.resolve(exchange);
assertSame(user1, resolved.orElseThrow());
}
}
Loading