|
@@ -21,28 +21,28 @@ import java.util.List;
|
|
|
|
|
|
import org.htmlunit.ElementNotFoundException;
|
|
import org.htmlunit.ElementNotFoundException;
|
|
import org.htmlunit.WebClient;
|
|
import org.htmlunit.WebClient;
|
|
|
|
+import org.htmlunit.html.HtmlButton;
|
|
import org.htmlunit.html.HtmlElement;
|
|
import org.htmlunit.html.HtmlElement;
|
|
import org.htmlunit.html.HtmlForm;
|
|
import org.htmlunit.html.HtmlForm;
|
|
import org.htmlunit.html.HtmlInput;
|
|
import org.htmlunit.html.HtmlInput;
|
|
import org.htmlunit.html.HtmlPage;
|
|
import org.htmlunit.html.HtmlPage;
|
|
import org.htmlunit.html.HtmlPasswordInput;
|
|
import org.htmlunit.html.HtmlPasswordInput;
|
|
-import org.htmlunit.html.HtmlSubmitInput;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
-import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
|
|
+import org.springframework.boot.test.web.server.LocalServerPort;
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
-@SpringBootTest
|
|
|
|
|
|
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
|
@AutoConfigureMockMvc
|
|
@AutoConfigureMockMvc
|
|
public class Saml2LoginApplicationITests {
|
|
public class Saml2LoginApplicationITests {
|
|
|
|
|
|
- @Autowired
|
|
|
|
- MockMvc mvc;
|
|
|
|
|
|
+ @LocalServerPort
|
|
|
|
+ int port;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
WebClient webClient;
|
|
WebClient webClient;
|
|
@@ -56,7 +56,7 @@ public class Saml2LoginApplicationITests {
|
|
void authenticationAttemptWhenValidThenShowsUserEmailAddress() throws Exception {
|
|
void authenticationAttemptWhenValidThenShowsUserEmailAddress() throws Exception {
|
|
performLogin();
|
|
performLogin();
|
|
HtmlPage home = (HtmlPage) this.webClient.getCurrentWindow().getEnclosedPage();
|
|
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
|
|
@Test
|
|
@@ -82,14 +82,14 @@ public class Saml2LoginApplicationITests {
|
|
}
|
|
}
|
|
|
|
|
|
private void performLogin() throws Exception {
|
|
private void performLogin() throws Exception {
|
|
- HtmlPage login = this.webClient.getPage("/");
|
|
|
|
|
|
+ HtmlPage login = this.webClient.getPage("http://localhost:" + this.port + "/saml2/authenticate/one");
|
|
this.webClient.waitForBackgroundJavaScript(10000);
|
|
this.webClient.waitForBackgroundJavaScript(10000);
|
|
HtmlForm form = findForm(login);
|
|
HtmlForm form = findForm(login);
|
|
HtmlInput username = form.getInputByName("username");
|
|
HtmlInput username = form.getInputByName("username");
|
|
HtmlPasswordInput password = form.getInputByName("password");
|
|
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();
|
|
submit.click();
|
|
this.webClient.waitForBackgroundJavaScript(10000);
|
|
this.webClient.waitForBackgroundJavaScript(10000);
|
|
}
|
|
}
|
|
@@ -97,7 +97,7 @@ public class Saml2LoginApplicationITests {
|
|
private HtmlForm findForm(HtmlPage login) {
|
|
private HtmlForm findForm(HtmlPage login) {
|
|
for (HtmlForm form : login.getForms()) {
|
|
for (HtmlForm form : login.getForms()) {
|
|
try {
|
|
try {
|
|
- if (form.getId().equals("form19")) {
|
|
|
|
|
|
+ if (form.getNameAttribute().equals("f")) {
|
|
return form;
|
|
return form;
|
|
}
|
|
}
|
|
}
|
|
}
|