|
@@ -21,18 +21,19 @@ import java.util.List;
|
|
|
|
|
|
import org.htmlunit.ElementNotFoundException;
|
|
|
import org.htmlunit.WebClient;
|
|
|
+import org.htmlunit.html.HtmlButton;
|
|
|
import org.htmlunit.html.HtmlElement;
|
|
|
import org.htmlunit.html.HtmlForm;
|
|
|
import org.htmlunit.html.HtmlInput;
|
|
|
import org.htmlunit.html.HtmlPage;
|
|
|
import org.htmlunit.html.HtmlPasswordInput;
|
|
|
-import org.htmlunit.html.HtmlSubmitInput;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.boot.test.web.server.LocalServerPort;
|
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
@@ -40,10 +41,13 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl;
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
|
|
-@SpringBootTest
|
|
|
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
|
|
@AutoConfigureMockMvc
|
|
|
public class CustomUrlsApplicationITests {
|
|
|
|
|
|
+ @LocalServerPort
|
|
|
+ int port;
|
|
|
+
|
|
|
@Autowired
|
|
|
MockMvc mvc;
|
|
|
|
|
@@ -59,7 +63,7 @@ public class CustomUrlsApplicationITests {
|
|
|
void authenticationAttemptWhenValidThenShowsUserEmailAddress() throws Exception {
|
|
|
performLogin();
|
|
|
HtmlPage home = (HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage();
|
|
|
- assertThat(home.asNormalizedText()).contains("You're email address is testuser2@spring.security.saml");
|
|
|
+ assertThat(home.asNormalizedText()).contains("You're email address is user1@example.org");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -83,14 +87,14 @@ public class CustomUrlsApplicationITests {
|
|
|
}
|
|
|
|
|
|
private void performLogin() throws Exception {
|
|
|
- HtmlPage login = this.webClient.getPage("/");
|
|
|
+ HtmlPage login = this.webClient.getPage("http://localhost:" + this.port + "/saml/login");
|
|
|
this.webClient.waitForBackgroundJavaScript(10000);
|
|
|
HtmlForm form = findForm(login);
|
|
|
HtmlInput username = form.getInputByName("username");
|
|
|
HtmlPasswordInput password = form.getInputByName("password");
|
|
|
- HtmlSubmitInput submit = login.getHtmlElementById("okta-signin-submit");
|
|
|
- username.type("testuser2@spring.security.saml");
|
|
|
- password.type("12345678");
|
|
|
+ HtmlButton submit = (HtmlButton) form.getElementsByTagName("button").iterator().next();
|
|
|
+ username.type("user1");
|
|
|
+ password.type("user1pass");
|
|
|
submit.click();
|
|
|
this.webClient.waitForBackgroundJavaScript(10000);
|
|
|
}
|
|
@@ -98,7 +102,7 @@ public class CustomUrlsApplicationITests {
|
|
|
private HtmlForm findForm(HtmlPage login) {
|
|
|
for (HtmlForm form : login.getForms()) {
|
|
|
try {
|
|
|
- if (form.getId().equals("form19")) {
|
|
|
+ if (form.getNameAttribute().equals("f")) {
|
|
|
return form;
|
|
|
}
|
|
|
}
|