From 9f6b38bf33c9519e3a0ce974fbc934a0c634135f Mon Sep 17 00:00:00 2001 From: Marcus Da Coregio Date: Mon, 19 Sep 2022 08:47:46 -0300 Subject: [PATCH] Polish SAML2 tests --- .../example/Saml2JavaConfigurationITests.java | 18 +++++++++++++++++- .../example/Saml2LoginApplicationITests.java | 18 +++++++++++++++++- .../example/Saml2LoginApplicationITests.java | 18 +++++++++++++++++- .../integTest/java/example/Saml2XmlITests.java | 18 +++++++++++++++++- 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/servlet/java-configuration/saml2/login/src/integTest/java/example/Saml2JavaConfigurationITests.java b/servlet/java-configuration/saml2/login/src/integTest/java/example/Saml2JavaConfigurationITests.java index fbf0cc9..b664155 100644 --- a/servlet/java-configuration/saml2/login/src/integTest/java/example/Saml2JavaConfigurationITests.java +++ b/servlet/java-configuration/saml2/login/src/integTest/java/example/Saml2JavaConfigurationITests.java @@ -16,6 +16,9 @@ package example; +import java.util.ArrayList; +import java.util.List; + import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlElement; @@ -78,7 +81,20 @@ public class Saml2JavaConfigurationITests { HtmlPage home = (HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage(); HtmlElement rpLogoutButton = home.getHtmlElementById("rp_logout_button"); HtmlPage loginPage = rpLogoutButton.click(); - assertThat(loginPage.getUrl().getFile()).isEqualTo("/login?logout"); + this.webClient.waitForBackgroundJavaScript(10000); + List urls = new ArrayList<>(); + urls.add(loginPage.getUrl().getFile()); + urls.add(((HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage()).getUrl().getFile()); + assertThat(urls).withFailMessage(() -> { + // @formatter:off + String builder = loginPage.asXml() + + "\n\n\n" + + "Enclosing Page" + + "\n\n\n" + + ((HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage()).asXml(); + // @formatter:on + return builder; + }).contains("/login?logout"); } private void performLogin() throws Exception { diff --git a/servlet/spring-boot/java/saml2/login-single-tenant/src/integTest/java/example/Saml2LoginApplicationITests.java b/servlet/spring-boot/java/saml2/login-single-tenant/src/integTest/java/example/Saml2LoginApplicationITests.java index 5382a08..01369dd 100644 --- a/servlet/spring-boot/java/saml2/login-single-tenant/src/integTest/java/example/Saml2LoginApplicationITests.java +++ b/servlet/spring-boot/java/saml2/login-single-tenant/src/integTest/java/example/Saml2LoginApplicationITests.java @@ -16,6 +16,9 @@ package example; +import java.util.ArrayList; +import java.util.List; + import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlElement; @@ -62,7 +65,20 @@ public class Saml2LoginApplicationITests { HtmlPage home = (HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage(); HtmlElement rpLogoutButton = home.getHtmlElementById("rp_logout_button"); HtmlPage loginPage = rpLogoutButton.click(); - assertThat(loginPage.getUrl().getFile()).isEqualTo("/login?logout"); + this.webClient.waitForBackgroundJavaScript(10000); + List urls = new ArrayList<>(); + urls.add(loginPage.getUrl().getFile()); + urls.add(((HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage()).getUrl().getFile()); + assertThat(urls).withFailMessage(() -> { + // @formatter:off + String builder = loginPage.asXml() + + "\n\n\n" + + "Enclosing Page" + + "\n\n\n" + + ((HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage()).asXml(); + // @formatter:on + return builder; + }).contains("/login?logout"); } private void performLogin() throws Exception { diff --git a/servlet/spring-boot/java/saml2/login/src/integTest/java/example/Saml2LoginApplicationITests.java b/servlet/spring-boot/java/saml2/login/src/integTest/java/example/Saml2LoginApplicationITests.java index 38052f2..f99961a 100644 --- a/servlet/spring-boot/java/saml2/login/src/integTest/java/example/Saml2LoginApplicationITests.java +++ b/servlet/spring-boot/java/saml2/login/src/integTest/java/example/Saml2LoginApplicationITests.java @@ -16,6 +16,9 @@ package example; +import java.util.ArrayList; +import java.util.List; + import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlElement; @@ -62,7 +65,20 @@ public class Saml2LoginApplicationITests { HtmlPage home = (HtmlPage) Saml2LoginApplicationITests.this.webClient.getCurrentWindow().getEnclosedPage(); HtmlElement rpLogoutButton = home.getHtmlElementById("rp_logout_button"); HtmlPage loginPage = rpLogoutButton.click(); - assertThat(loginPage.getUrl().getFile()).isEqualTo("/login?logout"); + this.webClient.waitForBackgroundJavaScript(10000); + List urls = new ArrayList<>(); + urls.add(loginPage.getUrl().getFile()); + urls.add(((HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage()).getUrl().getFile()); + assertThat(urls).withFailMessage(() -> { + // @formatter:off + String builder = loginPage.asXml() + + "\n\n\n" + + "Enclosing Page" + + "\n\n\n" + + ((HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage()).asXml(); + // @formatter:on + return builder; + }).contains("/login?logout"); } private void performLogin() throws Exception { diff --git a/servlet/xml/java/saml2/login-logout/src/integTest/java/example/Saml2XmlITests.java b/servlet/xml/java/saml2/login-logout/src/integTest/java/example/Saml2XmlITests.java index fb72938..670af6a 100644 --- a/servlet/xml/java/saml2/login-logout/src/integTest/java/example/Saml2XmlITests.java +++ b/servlet/xml/java/saml2/login-logout/src/integTest/java/example/Saml2XmlITests.java @@ -16,6 +16,9 @@ package example; +import java.util.ArrayList; +import java.util.List; + import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlElement; @@ -79,7 +82,20 @@ public class Saml2XmlITests { HtmlPage home = (HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage(); HtmlElement rpLogoutButton = home.getHtmlElementById("rp_logout_button"); HtmlPage loginPage = rpLogoutButton.click(); - assertThat(loginPage.getUrl().getFile()).isEqualTo("/login?logout"); + this.webClient.waitForBackgroundJavaScript(10000); + List urls = new ArrayList<>(); + urls.add(loginPage.getUrl().getFile()); + urls.add(((HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage()).getUrl().getFile()); + assertThat(urls).withFailMessage(() -> { + // @formatter:off + String builder = loginPage.asXml() + + "\n\n\n" + + "Enclosing Page" + + "\n\n\n" + + ((HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage()).asXml(); + // @formatter:on + return builder; + }).contains("/login?logout"); } private void performLogin() throws Exception {