-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
json headers - organization as json payload is not transmitted fix
Resolve and store user organization for extended LDAP configs Tests: adding an IT
- Loading branch information
1 parent
8c75e77
commit c36dd87
Showing
10 changed files
with
271 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...src/main/java/org/georchestra/gateway/security/ldap/extended/ExtendedGeorchestraUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.georchestra.gateway.security.ldap.extended; | ||
|
||
import org.georchestra.security.model.GeorchestraUser; | ||
import org.georchestra.security.model.Organization; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
import lombok.experimental.Delegate; | ||
|
||
/** | ||
* {@link GeorchestraUser} with resolved {@link #getOrg() Organization} | ||
*/ | ||
@SuppressWarnings("serial") | ||
@RequiredArgsConstructor | ||
@Accessors(chain = true) | ||
public class ExtendedGeorchestraUser extends GeorchestraUser { | ||
|
||
@JsonIgnore | ||
private final @NonNull @Delegate GeorchestraUser user; | ||
|
||
@JsonIgnore | ||
private @Getter @Setter Organization org; | ||
|
||
public @Override boolean equals(Object o) { | ||
if (!(o instanceof GeorchestraUser)) { | ||
return false; | ||
} | ||
return super.equals(o); | ||
} | ||
|
||
public @Override int hashCode() { | ||
return super.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
.../src/test/java/org/georchestra/gateway/security/ResolveGeorchestraUserGlobalFilterIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.georchestra.gateway.security; | ||
|
||
import org.georchestra.gateway.app.GeorchestraGatewayApplication; | ||
import org.georchestra.gateway.filter.headers.providers.JsonPayloadHeadersContributor; | ||
import org.georchestra.gateway.model.GatewayConfigProperties; | ||
import org.georchestra.gateway.model.HeaderMappings; | ||
import org.georchestra.testcontainers.ldap.GeorchestraLdapContainer; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@SpringBootTest(classes = GeorchestraGatewayApplication.class) | ||
@AutoConfigureWebTestClient(timeout = "PT20S") | ||
@ActiveProfiles("georheaders") | ||
public class ResolveGeorchestraUserGlobalFilterIT { | ||
|
||
public static GeorchestraLdapContainer ldap = new GeorchestraLdapContainer(); | ||
|
||
private @Autowired WebTestClient testClient; | ||
|
||
private @Autowired GatewayConfigProperties gatewayConfig; | ||
|
||
private @Autowired ApplicationContext context; | ||
|
||
public static GenericContainer httpEcho = new GenericContainer(DockerImageName.parse("ealen/echo-server")) { | ||
@Override | ||
protected void doStart() { | ||
super.doStart(); | ||
Integer mappedPort = this.getMappedPort(80); | ||
System.setProperty("httpEchoHost", this.getHost()); | ||
System.setProperty("httpEchoPort", mappedPort.toString()); | ||
System.out.println("Automatically set system property httpEchoHost=" + this.getHost()); | ||
System.out.println("Automatically set system property httpEchoPort=" + mappedPort); | ||
} | ||
}; | ||
|
||
public static @BeforeAll void startUpContainers() { | ||
httpEcho.setExposedPorts(Arrays.asList(new Integer[] { 80 })); | ||
httpEcho.start(); | ||
ldap.start(); | ||
} | ||
|
||
public static @AfterAll void shutDownContainers() { | ||
ldap.stop(); | ||
httpEcho.stop(); | ||
} | ||
|
||
public @Test void testReceivedHeadersAsJson() { | ||
gatewayConfig.getDefaultHeaders().setJsonUser(Optional.of(true)); | ||
gatewayConfig.getDefaultHeaders().setJsonOrganization(Optional.of(true)); | ||
assertNotNull(context.getBean(JsonPayloadHeadersContributor.class)); | ||
|
||
testClient.get().uri("/echo/")// | ||
.header("Authorization", "Basic dGVzdGFkbWluOnRlc3RhZG1pbg==") // testadmin:testadmin | ||
.exchange()// | ||
.expectStatus()// | ||
.is2xxSuccessful()// | ||
.expectBody()// | ||
.jsonPath(".request.headers.sec-user").exists().jsonPath(".request.headers.sec-organization").exists(); | ||
} | ||
|
||
public @Test void testJsonUserNoOrganization() { | ||
gatewayConfig.getDefaultHeaders().setJsonUser(Optional.of(true)); | ||
gatewayConfig.getDefaultHeaders().setJsonOrganization(Optional.of(false)); | ||
|
||
testClient.get().uri("/echo/")// | ||
.header("Authorization", "Basic dGVzdGFkbWluOnRlc3RhZG1pbg==") // testadmin:testadmin | ||
.exchange()// | ||
.expectStatus()// | ||
.is2xxSuccessful()// | ||
.expectBody()// | ||
.jsonPath(".request.headers.sec-user").exists()// | ||
.jsonPath(".request.headers.sec-organization").doesNotHaveJsonPath(); | ||
|
||
} | ||
|
||
public @Test void testNoJsonUserJsonOrganization() { | ||
gatewayConfig.getDefaultHeaders().setJsonUser(Optional.of(false)); | ||
gatewayConfig.getDefaultHeaders().setJsonOrganization(Optional.of(true)); | ||
|
||
testClient.get().uri("/echo/")// | ||
.header("Authorization", "Basic dGVzdGFkbWluOnRlc3RhZG1pbg==") // testadmin:testadmin | ||
.exchange()// | ||
.expectStatus()// | ||
.is2xxSuccessful()// | ||
.expectBody()// | ||
.jsonPath(".request.headers.sec-user").doesNotHaveJsonPath()// | ||
.jsonPath(".request.headers.sec-organization").exists(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.