-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ec44e1
commit f6d0f4e
Showing
2 changed files
with
19 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import no.nav.security.mock.oauth2.MockOAuth2Server; | ||
import no.nav.security.mock.oauth2.token.DefaultOAuth2TokenCallback; | ||
import org.junit.Ignore; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -27,23 +28,24 @@ | |
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
@SetEnvironmentVariable(key = "DATAHUB_SECRET", value = "test") | ||
@SetEnvironmentVariable(key = "KAFKA_BOOTSTRAP_SERVER", value = "") | ||
@SetEnvironmentVariable(key = "DATAHUB_ANALYTICS_ENABLED", value = "false") | ||
@SetEnvironmentVariable(key = "AUTH_OIDC_ENABLED", value = "true") | ||
@SetEnvironmentVariable(key = "AUTH_OIDC_CLIENT_ID", value = "testclient") | ||
@SetEnvironmentVariable(key = "AUTH_OIDC_CLIENT_SECRET", value = "testsecret") | ||
@SetEnvironmentVariable(key = "AUTH_OIDC_DISCOVERY_URI", value = "http://localhost:51152/testIssuer/.well-known/openid-configuration") | ||
@SetEnvironmentVariable(key = "AUTH_OIDC_BASE_URL", value = "http://localhost:51153") | ||
public class ApplicationOidcTest extends WithBrowser { | ||
private static final String ISSUER_ID = "testIssuer"; | ||
|
||
@Override | ||
protected Application provideApplication() { | ||
return new GuiceApplicationBuilder().in(new Environment(Mode.TEST)).build(); | ||
return new GuiceApplicationBuilder() | ||
.configure("analytics.enabled", "false") | ||
.configure("auth.baseUrl", "http://localhost:" + providePort()) | ||
.configure("auth.oidc.enabled", "true") | ||
.configure("auth.oidc.clientId", "testclient") | ||
.configure("auth.oidc.clientSecret", "testsecret") | ||
.configure("auth.oidc.discoveryUri", "http://localhost:" + oauthServerPort() | ||
+ "/testIssuer/.well-known/openid-configuration") | ||
.in(new Environment(Mode.TEST)).build(); | ||
} | ||
|
||
@Override | ||
protected int providePort() { | ||
return 51153; | ||
public int oauthServerPort() { | ||
return providePort() + 1; | ||
} | ||
|
||
@Override | ||
|
@@ -57,7 +59,7 @@ protected TestBrowser provideBrowser(int port) { | |
@BeforeAll | ||
public void init() throws IOException, InterruptedException { | ||
_oauthServer = new MockOAuth2Server(); | ||
_oauthServer.start(InetAddress.getByName("localhost"), 51152); | ||
_oauthServer.start(InetAddress.getByName("localhost"), providePort() + 1); | ||
_oauthServer.enqueueCallback( | ||
new DefaultOAuth2TokenCallback(ISSUER_ID, "testUser", List.of(), Map.of( | ||
"email", "[email protected]", | ||
|
@@ -71,7 +73,7 @@ public void init() throws IOException, InterruptedException { | |
createBrowser(); | ||
startServer(); | ||
|
||
Thread.sleep(5000); | ||
Thread.sleep(2000); | ||
} | ||
|
||
@AfterAll | ||
|
@@ -82,10 +84,11 @@ public void shutdown() throws IOException { | |
|
||
@Test | ||
public void testOpenIdConfig() { | ||
assertEquals("http://localhost:51152/testIssuer/.well-known/openid-configuration", _wellKnownUrl); | ||
assertEquals("http://localhost:" + oauthServerPort() + "/testIssuer/.well-known/openid-configuration", _wellKnownUrl); | ||
} | ||
|
||
@Test | ||
@Ignore("works local, not on github actions") | ||
public void testHappyPathOidc() { | ||
browser.goTo("/authenticate"); | ||
assertEquals("", browser.url()); | ||
|
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