forked from georchestra/georchestra-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case set up to assert PR georchestra#86
- Loading branch information
Showing
5 changed files
with
47 additions
and
12 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package org.georchestra.gateway.security; | ||
|
||
import org.georchestra.gateway.accounts.admin.CreateAccountUserCustomizer; | ||
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.gateway.security.preauth.PreauthAuthenticationManager; | ||
import org.georchestra.testcontainers.ldap.GeorchestraLdapContainer; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
@@ -12,6 +14,7 @@ | |
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
import org.testcontainers.containers.GenericContainer; | ||
|
@@ -23,7 +26,7 @@ | |
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@SpringBootTest(classes = GeorchestraGatewayApplication.class) | ||
@AutoConfigureWebTestClient(timeout = "PT20S") | ||
@AutoConfigureWebTestClient(timeout = "PT200S") | ||
@ActiveProfiles("georheaders") | ||
public class ResolveGeorchestraUserGlobalFilterIT { | ||
|
||
|
@@ -101,4 +104,33 @@ protected void doStart() { | |
.jsonPath(".request.headers.sec-organization").exists(); | ||
|
||
} | ||
|
||
/** | ||
* Show error message to OAuth2 user when a matching local account already | ||
* exists: i.e. it tries to create a user with an email address for which a user | ||
* already exists. | ||
* <p> | ||
* {@link GeorchestraUserMapper} calls the | ||
* {@link GeorchestraUserCustomizerExtension}s. | ||
* {@link CreateAccountUserCustomizer} will try to create an account with email | ||
* {@literal [email protected]}, which already exists (for user | ||
* {@literal testadmin}) | ||
*/ | ||
@Test | ||
void testRedirectIfOauth2UserExists() { | ||
final String email = "[email protected]"; | ||
// set up scenario: have a use | ||
String expected = ""; | ||
|
||
testClient.get().uri("/echo/")// | ||
.header(PreauthAuthenticationManager.PREAUTH_HEADER_NAME, "true") | ||
.header(PreauthAuthenticationManager.PREAUTH_EMAIL, email) | ||
.header(PreauthAuthenticationManager.PREAUTH_FIRSTNAME, "bob") | ||
.header(PreauthAuthenticationManager.PREAUTH_LASTNAME, "sponge") | ||
.header(PreauthAuthenticationManager.PREAUTH_USERNAME, "bobsponge").accept(MediaType.APPLICATION_JSON) | ||
.exchange()// | ||
.expectStatus()// | ||
.is3xxRedirection().expectHeader().location(expected); | ||
} | ||
|
||
} |
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