Skip to content

Commit

Permalink
fix(test): oidc
Browse files Browse the repository at this point in the history
  • Loading branch information
david-leifker committed Dec 5, 2022
1 parent 4ec44e1 commit f6d0f4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
29 changes: 16 additions & 13 deletions datahub-frontend/test/app/ApplicationOidcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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]",
Expand All @@ -71,7 +73,7 @@ public void init() throws IOException, InterruptedException {
createBrowser();
startServer();

Thread.sleep(5000);
Thread.sleep(2000);
}

@AfterAll
Expand All @@ -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());
Expand Down
5 changes: 3 additions & 2 deletions datahub-frontend/test/app/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@SetEnvironmentVariable(key = "DATAHUB_SECRET", value = "test")
@SetEnvironmentVariable(key = "KAFKA_BOOTSTRAP_SERVER", value = "")
@SetEnvironmentVariable(key = "DATAHUB_ANALYTICS_ENABLED", value = "false")
public class ApplicationTest extends WithApplication {

@Override
protected Application provideApplication() {
return new GuiceApplicationBuilder().in(new Environment(Mode.TEST)).build();
return new GuiceApplicationBuilder()
.configure("analytics.enabled", "false")
.in(new Environment(Mode.TEST)).build();
}

@BeforeAll
Expand Down

0 comments on commit f6d0f4e

Please sign in to comment.