From f9ba1226f8e6f624ec37e6b48164632a7cd977b8 Mon Sep 17 00:00:00 2001 From: haynescd Date: Fri, 9 Feb 2024 17:21:11 -0500 Subject: [PATCH 1/5] Update Security Integration test to remove selenium container --- .../workflows/security-integration-test.yml | 5 +- pom.xml | 4 +- .../integration/security/ContainerConfig.java | 63 ++------ .../security/OAuth2AuthIntegrationTest.java | 17 +-- .../OAuth2ResourceServerIntegrationTest.java | 9 +- .../security/SamlAuthIntegrationTest.java | 19 +-- .../test/integration/security/util/Util.java | 136 +++++++----------- .../keycloak-configuration-generated.json | 16 +-- 8 files changed, 84 insertions(+), 185 deletions(-) diff --git a/.github/workflows/security-integration-test.yml b/.github/workflows/security-integration-test.yml index 2cccb95f25c..c43d35e4e8b 100644 --- a/.github/workflows/security-integration-test.yml +++ b/.github/workflows/security-integration-test.yml @@ -24,9 +24,8 @@ jobs: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - - name: 'Add host.testcontainers.internal to /etc/hosts' - run: | - echo "127.0.0.1 host.testcontainers.internal" | sudo tee -a /etc/hosts + - uses: browser-actions/setup-chrome@latest + - run: chrome --version - name: 'Copy Application.Properties' working-directory: ./cbioportal run: | diff --git a/pom.xml b/pom.xml index c883c4ac2d0..9a442e2d7ea 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ 1.6.3 3.0.2 - 1.19.3 + 1.19.4 5.15.0 4.1.1 @@ -96,6 +96,7 @@ 5.1.48 3.2.0 3.14.0 + 4.17.0 7.1.0 @@ -277,6 +278,7 @@ org.seleniumhq.selenium selenium-java + ${selenium.version} test diff --git a/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java b/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java index a5f02e12507..e2ba358c31f 100644 --- a/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java +++ b/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java @@ -1,77 +1,42 @@ package org.cbioportal.test.integration.security; import dasniko.testcontainers.keycloak.KeycloakContainer; -import org.cbioportal.test.integration.OAuth2ResourceServerKeycloakInitializer; import org.cbioportal.test.integration.MysqlInitializer; import org.cbioportal.test.integration.OAuth2KeycloakInitializer; +import org.cbioportal.test.integration.OAuth2ResourceServerKeycloakInitializer; import org.cbioportal.test.integration.SamlKeycloakInitializer; +import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.springframework.boot.test.util.TestPropertyValues; -import org.springframework.boot.web.context.WebServerInitializedEvent; import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; -import org.testcontainers.Testcontainers; import org.testcontainers.containers.BindMode; -import org.testcontainers.containers.BrowserWebDriverContainer; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.MySQLContainer; import org.testcontainers.shaded.com.google.common.collect.ImmutableList; -import org.testcontainers.utility.DockerImageName; -import java.io.File; -import java.io.IOException; import java.time.Duration; import java.util.HashMap; import java.util.Map; -import static org.cbioportal.test.integration.security.util.Util.isHostMappingPresent; -import static org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL; - public class ContainerConfig { - + public final static int CBIO_PORT = 8080; - public final static int SESSION_SERVICE_PORT = 5000; - public final static int MONGO_PORT = 27017; - public final static int MYSQL_PORT = 3306; + public final static int MOCKSERVER_PORT = 8085; public final static String DOWNLOAD_FOLDER = "/tmp/browser_downloads"; - private static final String SESSION_IMAGE_VERSION = "docker.io/cbioportal/session-service:0.6.1"; - private static final String MONGO_IMAGE_VERSION = "docker.io/mongo:3.7.9"; private static final String KEYCLOAK_IMAGE_VERSION = "quay.io/keycloak/keycloak:22.0.5"; private static final String MYSQL_IMAGE_VERSION = "mysql:5.7"; private static final String MOCKSERVER_IMAGE_VERSION = "docker.io/mockserver/mockserver:5.15.0"; - static final GenericContainer sessionServiceContainer; - static final GenericContainer mongoContainer; static final MySQLContainer mysqlContainer; static final GenericContainer mockServerContainer; static final KeycloakContainer keycloakContainer; - static final BrowserWebDriverContainer chromedriverContainer; + static final ChromeDriver chromeDriver; static { - String hostToCheck = "host.testcontainers.internal"; - String ipAddressToCheck = "127.0.0.1"; - try { - if (!isHostMappingPresent(hostToCheck, ipAddressToCheck)) { - throw new IllegalStateException(hostToCheck + " is not mapped to " + ipAddressToCheck + " in /etc/hosts. Please add this mapping."); - } - } catch (IOException e) { - throw new RuntimeException("Unable to read /etc/hosts file.", e); - } - - sessionServiceContainer = new GenericContainer(DockerImageName.parse(SESSION_IMAGE_VERSION)) - .withAccessToHost(true) - .withEnv("SERVER_PORT", "5000") - .withEnv("JAVA_OPTS", "-Dspring.data.mongodb.uri=mongodb://host.testcontainers.internal:27017/session-service"); - sessionServiceContainer.setPortBindings(ImmutableList.of(String.format("%s:5000", SESSION_SERVICE_PORT))); - - mongoContainer = new GenericContainer(DockerImageName.parse(MONGO_IMAGE_VERSION)) - .withEnv("MONGO_INITDB_DATABASE", "session_service"); - mongoContainer.setPortBindings(ImmutableList.of(String.format("%s:27017", MONGO_PORT, MONGO_PORT))); - keycloakContainer = new KeycloakContainer(KEYCLOAK_IMAGE_VERSION) .withRealmImportFile("security/keycloak-configuration-generated.json") .withAdminUsername("admin") @@ -89,25 +54,20 @@ public class ContainerConfig { .withStartupTimeout(Duration.ofMinutes(10)); ChromeOptions options = new ChromeOptions(); + options.addArguments("--no-sandbox"); + options.addArguments("--disable-dev-shm-usage"); + options.addArguments("--headless"); Map prefs = new HashMap<>(); prefs.put("download.default_directory", DOWNLOAD_FOLDER); prefs.put("profile.default_content_settings.popups", 0); prefs.put("download.prompt_for_download", "false"); prefs.put("download.directory_upgrade", "true"); options.setExperimentalOption("prefs", prefs); - - chromedriverContainer = new BrowserWebDriverContainer<>() - .withCapabilities(options) - // activate this to record movies of the tests (great for debugging) - .withRecordingMode(RECORD_ALL, new File("/home/pnp300/")) - .withAccessToHost(true); + chromeDriver = new ChromeDriver(options); mysqlContainer.start(); - sessionServiceContainer.start(); - mongoContainer.start(); mockServerContainer.start(); keycloakContainer.start(); - chromedriverContainer.start(); } // Update application properties with connection info on Keycloak container @@ -156,11 +116,6 @@ public void initialize(ConfigurableApplicationContext applicationContext) { "server.port=" + CBIO_PORT ); values.applyTo(applicationContext); - applicationContext.addApplicationListener( - (ApplicationListener) event -> { - Testcontainers.exposeHostPorts(CBIO_PORT, keycloakContainer.getHttpPort(), MONGO_PORT); - keycloakContainer.setPortBindings(ImmutableList.of(String.format("%s:8080", keycloakContainer.getHttpPort()))); - }); } } diff --git a/src/test/java/org/cbioportal/test/integration/security/OAuth2AuthIntegrationTest.java b/src/test/java/org/cbioportal/test/integration/security/OAuth2AuthIntegrationTest.java index fae45791315..de36edef511 100644 --- a/src/test/java/org/cbioportal/test/integration/security/OAuth2AuthIntegrationTest.java +++ b/src/test/java/org/cbioportal/test/integration/security/OAuth2AuthIntegrationTest.java @@ -2,12 +2,9 @@ import org.cbioportal.PortalApplication; import org.cbioportal.test.integration.security.util.Util; -import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -41,7 +38,7 @@ "dat.oauth2.clientId=cbioportal_oauth2", "dat.oauth2.clientSecret=client_secret", // Redirect URL to cBiopPortal application from perspective of browser - "dat.oauth2.redirectUri=http://host.testcontainers.internal:8080/api/data-access-token/oauth2", + "dat.oauth2.redirectUri=http://localhost:8080/api/data-access-token/oauth2", "dat.oauth2.jwtRolesPath=resource_access::cbioportal::roles", "session.service.url=http://localhost:5000/api/sessions/my_portal/", "filter_groups_by_appname=false" @@ -53,31 +50,29 @@ MyOAuth2KeycloakInitializer.class, PortInitializer.class }) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@DirtiesContext // needed to reuse port 8080 for multiple tests public class OAuth2AuthIntegrationTest extends ContainerConfig { public final static String CBIO_URL_FROM_BROWSER = - String.format("http://host.testcontainers.internal:%d", CBIO_PORT); + String.format("http://localhost:%d", CBIO_PORT); @Test public void a_loginSuccess() { - Util.testLogin(CBIO_URL_FROM_BROWSER, chromedriverContainer); + Util.testLogin(CBIO_URL_FROM_BROWSER, chromeDriver); } @Test public void b_downloadOfflineToken() throws Exception { - Util.testDownloadOfflineToken(CBIO_URL_FROM_BROWSER, chromedriverContainer); + Util.testDownloadOfflineToken(CBIO_URL_FROM_BROWSER, chromeDriver); } @Test public void c_logoutSuccess() { - Util.testLogout(CBIO_URL_FROM_BROWSER, chromedriverContainer); + Util.testOAuthLogout(CBIO_URL_FROM_BROWSER, chromeDriver); } @Test public void d_loginAgainSuccess() { - Util.testLoginAgain(CBIO_URL_FROM_BROWSER, chromedriverContainer); + Util.testLoginAgain(CBIO_URL_FROM_BROWSER, chromeDriver); } } \ No newline at end of file diff --git a/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java b/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java index 4ddb4b409be..3db4fa912bc 100644 --- a/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java +++ b/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java @@ -24,7 +24,6 @@ package org.cbioportal.test.integration.security; -import org.cbioportal.PortalApplication; import org.cbioportal.test.integration.security.util.HttpHelper; import org.json.JSONArray; import org.json.JSONException; @@ -36,7 +35,6 @@ import org.mockserver.model.HttpResponse; import org.mockserver.model.StringBody; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -55,8 +53,7 @@ */ @RunWith(SpringRunner.class) @SpringBootTest( - webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, - classes = {PortalApplication.class} + webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT ) @TestPropertySource( properties = { @@ -71,7 +68,7 @@ "spring.security.saml2.relyingparty.registration.keycloak.signing.credentials[0].private-key-location=classpath:dev/security/signing-key.pem", "dat.oauth2.clientId=client_id", "dat.oauth2.clientSecret=client_secret", - "dat.oauth2.redirectUri=http://host.testcontainers.internal:8080/api/data-access-token/oauth2", + "dat.oauth2.redirectUri=http://localhost:8080/api/data-access-token/oauth2", // host is the mock server that fakes the oidc idp "dat.oauth2.accessTokenUri=http://host.testcontainers.internal:8085/realms/cbio/protocol/openid-connect/token", "dat.oauth2.userAuthorizationUri=http://host.testcontainers.internal:8085/realms/cbio/protocol/openid-connect/auth", @@ -83,11 +80,11 @@ MyMysqlInitializer.class, MyOAuth2ResourceServerKeycloakInitializer.class }) -@DirtiesContext // needed to reuse port 8080 for multiple tests public class OAuth2ResourceServerIntegrationTest extends ContainerConfig { public final static String CBIO_URL_FROM_BROWSER = String.format("http://localhost:%d", CBIO_PORT); + private final static String tokenUriPath = "/realms/cbio/protocol/openid-connect/token"; @Test diff --git a/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java b/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java index dea0b471bdf..77859fa9034 100644 --- a/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java +++ b/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java @@ -1,13 +1,9 @@ package org.cbioportal.test.integration.security; -import org.cbioportal.PortalApplication; import org.cbioportal.test.integration.security.util.Util; -import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -18,8 +14,7 @@ @RunWith(SpringRunner.class) @SpringBootTest( - webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, - classes = {PortalApplication.class} + webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT ) @TestPropertySource( properties = { @@ -42,7 +37,7 @@ //"dat.oauth2.redirectUri=http://host.testcontainers.internal:8080/api/data-access-token/oauth2", //"dat.oauth2.jwtRolesPath=resource_access::cbioportal::roles", "security.cors.allowed-origins=*", - "session.service.url=http://localhost:5000/api/sessions/my_portal/", + "session.service.url=", "filter_groups_by_appname=false" } ) @@ -51,26 +46,24 @@ MySamlKeycloakInitializer.class, PortInitializer.class }) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@DirtiesContext // needed to reuse port 8080 for multiple tests public class SamlAuthIntegrationTest extends ContainerConfig { public final static String CBIO_URL_FROM_BROWSER = - String.format("http://host.testcontainers.internal:%d", CBIO_PORT); + String.format("http://localhost:%d", CBIO_PORT); @Test public void a_loginSuccess() { - Util.testLogin(CBIO_URL_FROM_BROWSER, chromedriverContainer); + Util.testLogin(CBIO_URL_FROM_BROWSER, chromeDriver); } @Test public void b_testAuthorizedStudy() { - Util.testLoginAndVerifyStudyNotPresent(CBIO_URL_FROM_BROWSER,chromedriverContainer ); + Util.testLoginAndVerifyStudyNotPresent(CBIO_URL_FROM_BROWSER,chromeDriver ); } @Test public void c_logoutSuccess() { - Util.testLogout(CBIO_URL_FROM_BROWSER, chromedriverContainer); + Util.testSamlLogout(CBIO_URL_FROM_BROWSER, chromeDriver); } } \ No newline at end of file diff --git a/src/test/java/org/cbioportal/test/integration/security/util/Util.java b/src/test/java/org/cbioportal/test/integration/security/util/Util.java index e92e95c179d..d81dc0f2420 100644 --- a/src/test/java/org/cbioportal/test/integration/security/util/Util.java +++ b/src/test/java/org/cbioportal/test/integration/security/util/Util.java @@ -5,113 +5,96 @@ import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; -import org.springframework.util.Assert; -import org.testcontainers.containers.BrowserWebDriverContainer; -import org.testcontainers.containers.Container; -import org.testcontainers.containers.GenericContainer; -import javax.annotation.Nonnull; -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; +import java.io.File; import java.time.Duration; -import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import static org.testcontainers.shaded.org.awaitility.Awaitility.await; public class Util { - public static boolean isHostMappingPresent(String host, String ipAddress) throws IOException { - String hostsFilePath = "/etc/hosts"; - BufferedReader reader = new BufferedReader(new FileReader(hostsFilePath)); - String line; - - try { - while ((line = reader.readLine()) != null) { - if (line.contains(host) && line.contains(ipAddress)) { - return true; - } - } - } finally { - reader.close(); - } - - return false; - } - - public static void testLogin(String cbioUrl, BrowserWebDriverContainer chromedriverContainer) { - RemoteWebDriver driver = chromedriverContainer.getWebDriver(); - performLogin(cbioUrl, driver); - WebElement loggedInButton = driver.findElement(By.id("dat-dropdown")); + public static void testLogin(String cbioUrl, ChromeDriver chromedriver) { + performLogin(cbioUrl, chromedriver); + WebElement loggedInButton = chromedriver.findElement(By.id("dat-dropdown")); Assertions.assertEquals("Logged in as testuser@thehyve.nl", loggedInButton.getText()); - new WebDriverWait(driver, Duration.ofSeconds(20)).until( + new WebDriverWait(chromedriver, Duration.ofSeconds(20)).until( ExpectedConditions.presenceOfElementLocated(By.xpath("//span[.='Breast Invasive Carcinoma (TCGA,Nature 2012)']"))); Assertions.assertDoesNotThrow( - () -> driver.findElement(By.xpath("//span[.='Breast Invasive Carcinoma (TCGA,Nature 2012)']")), + () -> chromedriver.findElement(By.xpath("//span[.='Breast Invasive Carcinoma (TCGA,Nature 2012)']")), "Study could not be found on the landing page. Permissions are not correctly passed from IDP to client."); } - public static void testLoginAndVerifyStudyNotPresent(String cbioUrl, BrowserWebDriverContainer chromedriverContainer) { - RemoteWebDriver driver = chromedriverContainer.getWebDriver(); - performLogin(cbioUrl, driver); - WebElement loggedInButton = driver.findElement(By.id("dat-dropdown")); + public static void testLoginAndVerifyStudyNotPresent(String cbioUrl, ChromeDriver chromeDriver) { + performLogin(cbioUrl, chromeDriver); + WebElement loggedInButton = chromeDriver.findElement(By.id("dat-dropdown")); Assertions.assertEquals("Logged in as testuser@thehyve.nl", loggedInButton.getText()); - new WebDriverWait(driver, Duration.ofSeconds(20)).until( + new WebDriverWait(chromeDriver, Duration.ofSeconds(20)).until( ExpectedConditions.presenceOfElementLocated(By.xpath("//span[.='Breast Invasive Carcinoma (TCGA,Nature 2012)']"))); Assertions.assertThrows( NoSuchElementException.class, - () -> driver.findElement(By.xpath("//span[.='Adrenocortical Carcinoma (TCGA, Provisional)']")), + () -> chromeDriver.findElement(By.xpath("//span[.='Adrenocortical Carcinoma (TCGA, Provisional)']")), "Study could not be found on the landing page. Permissions are not correctly passed from IDP to client."); } - public static void testDownloadOfflineToken(String cbioUrl, BrowserWebDriverContainer chromedriverContainer) throws Exception { - RemoteWebDriver driver = chromedriverContainer.getWebDriver(); - performLogin(cbioUrl, driver); + public static void testDownloadOfflineToken(String cbioUrl, ChromeDriver chromeDriver) throws Exception { + performLogin(cbioUrl, chromeDriver); Assertions.assertDoesNotThrow( - () -> driver.findElement(By.id("dat-dropdown")).click(), + () -> chromeDriver.findElement(By.id("dat-dropdown")).click(), "Logged-in menu could not be found on the page."); - driver.findElement(By.linkText("Data Access Token")).click(); - driver.findElement(By.xpath("//button[text()='Download Token']")).click(); - - await().atMost(Duration.ofSeconds(5)).until(downloadedFile(chromedriverContainer)); + chromeDriver.findElement(By.linkText("Data Access Token")).click(); + chromeDriver.findElement(By.xpath("//button[text()='Download Token']")).click(); - Assertions.assertTrue(downloadedFile(chromedriverContainer ).call()); + var file = new File(String.format("%s/cbioportal_data_access_token.txt", + ContainerConfig.DOWNLOAD_FOLDER)); + await().atMost(Duration.ofSeconds(5)).until(file::exists); + Assertions.assertTrue(file.exists()); } - public static void testLogout(String cbioUrl, BrowserWebDriverContainer chromedriverContainer) { - RemoteWebDriver driver = chromedriverContainer.getWebDriver(); - performLogin(cbioUrl, driver); + public static void testOAuthLogout(String cbioUrl, ChromeDriver chromeDriver) { + performLogin(cbioUrl, chromeDriver); Assertions.assertDoesNotThrow( - () -> driver.findElement(By.id("dat-dropdown")).click(), + () -> chromeDriver.findElement(By.id("dat-dropdown")).click(), "Logout menu could not be found on the page."); - driver.findElement(By.linkText("Sign out")).click(); + //chromeDriver.findElement(By.linkText("Sign out")).click(); // TODO: Remove when sync'd with frontend - driver.get(cbioUrl + "/logout"); + chromeDriver.get(cbioUrl + "/logout"); Assertions.assertDoesNotThrow( - () -> driver.findElement(By.id("username")), - "IDP login screen not visible on the page. Logout did not work correctly." - ); + () -> chromeDriver.findElement(By.id("username")), + "IDP login screen not visible on the page. Logout did not work correctly."); } + + public static void testSamlLogout(String cbioUrl, ChromeDriver chromeDriver) { + performLogin(cbioUrl, chromeDriver); + Assertions.assertDoesNotThrow( + () -> chromeDriver.findElement(By.id("dat-dropdown")).click(), + "Logout menu could not be found on the page."); + //chromeDriver.findElement(By.linkText("Sign out")).click(); + // TODO: Remove when sync'd with frontend + chromeDriver.get(cbioUrl + "/logout"); + Assertions.assertEquals(chromeDriver.getCurrentUrl(), cbioUrl + "/login?logout_success"); + } + - public static void testLoginAgain(String cbioUrl, BrowserWebDriverContainer chromedriverContainer) { - RemoteWebDriver driver = chromedriverContainer.getWebDriver(); - performLogin(cbioUrl, driver); + + public static void testLoginAgain(String cbioUrl, ChromeDriver chromeDriver) { + performLogin(cbioUrl, chromeDriver); Assertions.assertDoesNotThrow( - () -> driver.findElement(By.id("dat-dropdown")).click(), + () -> chromeDriver.findElement(By.id("dat-dropdown")).click(), "Logout menu could not be found on the page."); - driver.get(cbioUrl + "/logout"); - driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); + chromeDriver.get(cbioUrl + "/logout"); + chromeDriver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); Assertions.assertDoesNotThrow( - () -> driver.findElement(By.id("username")), + () -> chromeDriver.findElement(By.id("username")), "IDP login screen not visible on the page. Logout did not work correctly." ); - performLogin(cbioUrl, driver); + performLogin(cbioUrl, chromeDriver); Assertions.assertDoesNotThrow( - () -> driver.findElement(By.id("dat-dropdown")), + () -> chromeDriver.findElement(By.id("dat-dropdown")), "Logged-in menu could not be found on the page. Login did not work correctly."); } @@ -129,29 +112,8 @@ private static void performLogin(String url, RemoteWebDriver driver) { passwordInput.sendKeys("P@ssword1"); loginButton.click(); } - // wait for the page to load -// driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); new WebDriverWait(driver, Duration.ofSeconds(20)).until( ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@data-test='cancerTypeListContainer']"))); } - private static boolean containerFileExists( - @Nonnull final GenericContainer container, @Nonnull String path) - throws IOException, InterruptedException { - Assert.notNull(container, "Containers is null"); - Assert.isTrue(!path.isEmpty(), "Path string is empty"); - Container.ExecResult r = container.execInContainer("/bin/sh", "-c", - "if [ -f " + path - + " ] ; then echo '0' ; else (>&2 echo '1') ; fi"); - boolean fileNotFound = r.getStderr().contains("1"); - container.execInContainer("rm -f " + path); - return !fileNotFound; - } - - private static Callable downloadedFile(GenericContainer chromedriverContainer) { - return () -> containerFileExists(chromedriverContainer, - String.format("%s/cbioportal_data_access_token.txt", - ContainerConfig.DOWNLOAD_FOLDER)); - } - } diff --git a/src/test/resources/security/keycloak-configuration-generated.json b/src/test/resources/security/keycloak-configuration-generated.json index b13e59f45aa..6aa760d1f49 100644 --- a/src/test/resources/security/keycloak-configuration-generated.json +++ b/src/test/resources/security/keycloak-configuration-generated.json @@ -282,18 +282,16 @@ { "id": "4b5c2aa6-bc44-458d-ac1f-1a2166520f4d", "clientId": "cbioportal", - "adminUrl": "http://host.testcontainers.internal:8084/saml", + "adminUrl": "", "surrogateAuthRequired": false, "enabled": true, "alwaysDisplayInConsole": false, "clientAuthenticatorType": "client-secret", "redirectUris": [ - "http://host.testcontainers.internal:8080/*", - "http://host.testcontainers.internal:8088/*", - "http://host.testcontainers.internal:8089/*" + "http://localhost:8080/*" ], "webOrigins": [ - "http://host.testcontainers.internal:8080" + "http://localhost:8080" ], "notBefore": 0, "bearerOnly": false, @@ -308,7 +306,7 @@ "attributes": { "saml.assertion.signature": "false", "saml.force.post.binding": "false", - "saml_single_logout_service_url_post": "http://host.testcontainers.internal:8080/logout/saml2/slo", + "saml_single_logout_service_url_post": "http://localhost:8080/login?logout_success", "signing.private.key": "MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDJTDNHzHv19kM4tVLOIjpR/vez4QJk70PMbghQBdCp1Er1yU8GkQRMx0QtumQB2ML1p2f63EEd7WsAPMEVYNQv6MHJDhAIDt+npWmYrGl3PrkVA3GNzZcD+GQEMZdGcECvfocOy2tB6iMOhdnFqu4L/QfFG2yJ+CpimpijvW78cJ35oYmOTnD7R9LBAJQuBlQDpOvB+I/dFeCiNKw61HQy0nMf6oe0pBy4E7bImQ0HY/soxBnzbvPUzbBvnhb2d97l3wn6ElUMrZuQSyI+OyVgBMyv9gcgV4Wq16oEuNkWFIdY2j8GeiDlqy9KJAttgLXBjGua2lRML0a+nrfF1VbBLgyzAZZP2IS/P3QYcSE2GbPWiWXjov2vF63/VnARzQhPhuLGilWp1Nxqr0HztgSiAyx0D3wqEBic0ERAQDVuHQZdjPd7RJaJ6MBnZH9mMVQOrjspIP5Sc6Z7omou26LPTjWNwmNWnfrq1sU8ADg4Uj09PWYcuWhPKxe6K9Zm4PLGXA0fR/fCVPDKaJPXIC7FGzDDdh/uSb9OURlgHwe319FCdvm1k7xD6tEfsyORjWJFoYvyT015j9LdBuO5fwt40EPCzNezqWCaimES7u3Puyg+4mbnRDh1UuouHOHVZ4jWySrrEktI0l6JkxrqdT2ilw7ICtmFx2fsjO9qso4tGwIDAQABAoICAFT7iprBRYQtl2uVgYPtB1oenkyerfgW2zSvL2s5SUKpkYv6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secret", "secret": "client_secret", "redirectUris": [ - "http://host.testcontainers.internal:8080/*", - "http://host.testcontainers.internal:8088/*", - "http://host.testcontainers.internal:8089/*" + "http://localhost:8080/*" ], "webOrigins": [ - "http://host.testcontainers.internal:8080" + "http://localhost:8080" ], "notBefore": 0, "bearerOnly": false, From 6863504c025c27293530e464487152dea68bb73b Mon Sep 17 00:00:00 2001 From: haynescd Date: Fri, 9 Feb 2024 17:26:38 -0500 Subject: [PATCH 2/5] Fix yml file --- .github/workflows/security-integration-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/security-integration-test.yml b/.github/workflows/security-integration-test.yml index c43d35e4e8b..5fd20693a50 100644 --- a/.github/workflows/security-integration-test.yml +++ b/.github/workflows/security-integration-test.yml @@ -24,8 +24,8 @@ jobs: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - - uses: browser-actions/setup-chrome@latest - - run: chrome --version + - name: 'Download Chrome' + uses: browser-actions/setup-chrome@latest - name: 'Copy Application.Properties' working-directory: ./cbioportal run: | From 9f406041cc765b0c45b3c7fab9bd7e56d1aef997 Mon Sep 17 00:00:00 2001 From: haynescd Date: Fri, 9 Feb 2024 17:38:29 -0500 Subject: [PATCH 3/5] Add DirtiesContext annotation --- .../test/integration/security/OAuth2AuthIntegrationTest.java | 2 ++ .../security/OAuth2ResourceServerIntegrationTest.java | 2 ++ .../test/integration/security/SamlAuthIntegrationTest.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/test/java/org/cbioportal/test/integration/security/OAuth2AuthIntegrationTest.java b/src/test/java/org/cbioportal/test/integration/security/OAuth2AuthIntegrationTest.java index de36edef511..1b580f2a2eb 100644 --- a/src/test/java/org/cbioportal/test/integration/security/OAuth2AuthIntegrationTest.java +++ b/src/test/java/org/cbioportal/test/integration/security/OAuth2AuthIntegrationTest.java @@ -5,6 +5,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -50,6 +51,7 @@ MyOAuth2KeycloakInitializer.class, PortInitializer.class }) +@DirtiesContext public class OAuth2AuthIntegrationTest extends ContainerConfig { public final static String CBIO_URL_FROM_BROWSER = diff --git a/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java b/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java index 3db4fa912bc..953d70c79db 100644 --- a/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java +++ b/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java @@ -35,6 +35,7 @@ import org.mockserver.model.HttpResponse; import org.mockserver.model.StringBody; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -80,6 +81,7 @@ MyMysqlInitializer.class, MyOAuth2ResourceServerKeycloakInitializer.class }) +@DirtiesContext public class OAuth2ResourceServerIntegrationTest extends ContainerConfig { public final static String CBIO_URL_FROM_BROWSER = diff --git a/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java b/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java index 77859fa9034..ad7cc08bacc 100644 --- a/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java +++ b/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java @@ -4,6 +4,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; @@ -46,6 +47,7 @@ MySamlKeycloakInitializer.class, PortInitializer.class }) +@DirtiesContext public class SamlAuthIntegrationTest extends ContainerConfig { public final static String CBIO_URL_FROM_BROWSER = From f32e49a5c0a60b35748b765984ec6048348289b3 Mon Sep 17 00:00:00 2001 From: haynescd Date: Fri, 9 Feb 2024 17:50:56 -0500 Subject: [PATCH 4/5] Remove internal.test.host --- .../test/integration/OAuth2KeycloakInitializer.java | 2 +- .../cbioportal/test/integration/security/ContainerConfig.java | 2 +- .../security/OAuth2ResourceServerIntegrationTest.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/cbioportal/test/integration/OAuth2KeycloakInitializer.java b/src/test/java/org/cbioportal/test/integration/OAuth2KeycloakInitializer.java index 78943a9439d..ea8b64b507f 100644 --- a/src/test/java/org/cbioportal/test/integration/OAuth2KeycloakInitializer.java +++ b/src/test/java/org/cbioportal/test/integration/OAuth2KeycloakInitializer.java @@ -18,7 +18,7 @@ public void initializeImpl(ConfigurableApplicationContext configurableApplicatio try { String keycloakUrlForCBioportal = keycloakContainer.getAuthServerUrl(); - String keycloakUrlForBrowser = String.format("http://host.testcontainers.internal:%s", keycloakContainer.getHttpPort()); + String keycloakUrlForBrowser = String.format("http://localhost:%s", keycloakContainer.getHttpPort()); TestPropertyValues values = TestPropertyValues.of( diff --git a/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java b/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java index e2ba358c31f..4c50e1adc88 100644 --- a/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java +++ b/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java @@ -41,7 +41,7 @@ public class ContainerConfig { .withRealmImportFile("security/keycloak-configuration-generated.json") .withAdminUsername("admin") .withAdminPassword("admin") - .withEnv("KC_HOSTNAME", "host.testcontainers.internal") + .withEnv("KC_HOSTNAME", "localhost") .withEnv("KC_HOSTNAME_ADMIN", "localhost"); mockServerContainer = new GenericContainer(MOCKSERVER_IMAGE_VERSION) diff --git a/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java b/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java index 953d70c79db..bdb48da1146 100644 --- a/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java +++ b/src/test/java/org/cbioportal/test/integration/security/OAuth2ResourceServerIntegrationTest.java @@ -71,8 +71,8 @@ "dat.oauth2.clientSecret=client_secret", "dat.oauth2.redirectUri=http://localhost:8080/api/data-access-token/oauth2", // host is the mock server that fakes the oidc idp - "dat.oauth2.accessTokenUri=http://host.testcontainers.internal:8085/realms/cbio/protocol/openid-connect/token", - "dat.oauth2.userAuthorizationUri=http://host.testcontainers.internal:8085/realms/cbio/protocol/openid-connect/auth", + "dat.oauth2.accessTokenUri=http://localhost:8085/realms/cbio/protocol/openid-connect/token", + "dat.oauth2.userAuthorizationUri=http://localhost:8085/realms/cbio/protocol/openid-connect/auth", "dat.oauth2.jwtRolesPath=resource_access::cbioportal::roles", "filter_groups_by_appname=false" } From 5e58c7506d105e349fe2cd0985127b39da063ae5 Mon Sep 17 00:00:00 2001 From: haynescd Date: Thu, 15 Feb 2024 10:23:23 -0500 Subject: [PATCH 5/5] Add mongo and session service --- .../integration/security/ContainerConfig.java | 38 ++++++++++++++++++- .../security/SamlAuthIntegrationTest.java | 4 +- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java b/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java index 4c50e1adc88..b74ff9c542d 100644 --- a/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java +++ b/src/test/java/org/cbioportal/test/integration/security/ContainerConfig.java @@ -8,12 +8,17 @@ import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.boot.web.context.WebServerInitializedEvent; import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; +import org.testcontainers.Testcontainers; import org.testcontainers.containers.BindMode; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.containers.Network; import org.testcontainers.shaded.com.google.common.collect.ImmutableList; +import org.testcontainers.utility.DockerImageName; import java.time.Duration; import java.util.HashMap; @@ -22,10 +27,15 @@ public class ContainerConfig { public final static int CBIO_PORT = 8080; - + public final static int SESSION_SERVICE_PORT = 5000; + public final static int MONGO_PORT = 27017; + + public final static String MONGO_NETWORK = "mongo-network"; public final static int MOCKSERVER_PORT = 8085; public final static String DOWNLOAD_FOLDER = "/tmp/browser_downloads"; - + + private static final String SESSION_IMAGE_VERSION = "docker.io/cbioportal/session-service:0.6.1"; + private static final String MONGO_IMAGE_VERSION = "docker.io/mongo:3.7.9"; private static final String KEYCLOAK_IMAGE_VERSION = "quay.io/keycloak/keycloak:22.0.5"; private static final String MYSQL_IMAGE_VERSION = "mysql:5.7"; private static final String MOCKSERVER_IMAGE_VERSION = "docker.io/mockserver/mockserver:5.15.0"; @@ -35,7 +45,25 @@ public class ContainerConfig { static final KeycloakContainer keycloakContainer; static final ChromeDriver chromeDriver; + static final GenericContainer sessionServiceContainer; + static final GenericContainer mongoContainer; + static { + + Network mongoNetwork = Network.newNetwork(); + mongoContainer = new GenericContainer(DockerImageName.parse(MONGO_IMAGE_VERSION)) + .withNetwork(mongoNetwork) + .withNetworkAliases(MONGO_NETWORK) + .withAccessToHost(true) + .withEnv("MONGO_INITDB_DATABASE", "session_service"); + + String mongoConnectionString = String.format("-Dspring.data.mongodb.uri=mongodb://%s:%s/session-service",MONGO_NETWORK, MONGO_PORT); + sessionServiceContainer = new GenericContainer(DockerImageName.parse(SESSION_IMAGE_VERSION)) + .withNetwork(mongoNetwork) + .withAccessToHost(true) + .withEnv("SERVER_PORT", "5000") + .withEnv("JAVA_OPTS", mongoConnectionString); + sessionServiceContainer.setPortBindings(ImmutableList.of(String.format("%s:5000", SESSION_SERVICE_PORT))); keycloakContainer = new KeycloakContainer(KEYCLOAK_IMAGE_VERSION) .withRealmImportFile("security/keycloak-configuration-generated.json") @@ -65,6 +93,8 @@ public class ContainerConfig { options.setExperimentalOption("prefs", prefs); chromeDriver = new ChromeDriver(options); + mongoContainer.start(); + sessionServiceContainer.start(); mysqlContainer.start(); mockServerContainer.start(); keycloakContainer.start(); @@ -116,6 +146,10 @@ public void initialize(ConfigurableApplicationContext applicationContext) { "server.port=" + CBIO_PORT ); values.applyTo(applicationContext); + applicationContext.addApplicationListener( + (ApplicationListener) event -> { + Testcontainers.exposeHostPorts(CBIO_PORT, MONGO_PORT); + }); } } diff --git a/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java b/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java index ad7cc08bacc..cefa6844f2c 100644 --- a/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java +++ b/src/test/java/org/cbioportal/test/integration/security/SamlAuthIntegrationTest.java @@ -38,7 +38,7 @@ //"dat.oauth2.redirectUri=http://host.testcontainers.internal:8080/api/data-access-token/oauth2", //"dat.oauth2.jwtRolesPath=resource_access::cbioportal::roles", "security.cors.allowed-origins=*", - "session.service.url=", + "session.service.url=http://localhost:5000/api/sessions/my_portal/", "filter_groups_by_appname=false" } ) @@ -52,7 +52,7 @@ public class SamlAuthIntegrationTest extends ContainerConfig { public final static String CBIO_URL_FROM_BROWSER = String.format("http://localhost:%d", CBIO_PORT); - + @Test public void a_loginSuccess() { Util.testLogin(CBIO_URL_FROM_BROWSER, chromeDriver);