diff --git a/vaadin-spring-tests/test-ts-services-custom-client/src/test/java/com/vaadin/flow/connect/AppViewIT.java b/vaadin-spring-tests/test-ts-services-custom-client/src/test/java/com/vaadin/flow/connect/AppViewIT.java index c37b230fe..248cd76dd 100644 --- a/vaadin-spring-tests/test-ts-services-custom-client/src/test/java/com/vaadin/flow/connect/AppViewIT.java +++ b/vaadin-spring-tests/test-ts-services-custom-client/src/test/java/com/vaadin/flow/connect/AppViewIT.java @@ -17,9 +17,11 @@ import java.util.regex.Pattern; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import com.vaadin.flow.testutil.ChromeBrowserTest; @@ -60,4 +62,29 @@ public void should_requestAnonymously_connect_service() { "\\[LOG] AppEndpoint/helloAnonymous took \\d+ ms")), 25); } + + @Test + public void should_requestAnonymously_after_logout() throws Exception { + String originalCsrfToken = executeScript( + "return self.Vaadin.TypeScript.csrfToken").toString(); + + openTestUrl("/logout"); + openTestUrl("/"); + + String csrfToken = executeScript( + "return self.Vaadin.TypeScript.csrfToken").toString(); + Assert.assertNotEquals("CSRF token should change for the new session", + originalCsrfToken, csrfToken); + + mainView = $("main-view").waitForFirst(); + + TestBenchElement button = mainView.$(TestBenchElement.class) + .id("helloAnonymous"); + button.click(); + + // Wait for the server connect response + waitUntil(ExpectedConditions.textToBePresentInElement( + mainView.$(TestBenchElement.class).id("content"), + "Hello, stranger!"), 25); + } } diff --git a/vaadin-spring-tests/test-ts-services/src/test/java/com/vaadin/flow/connect/AppViewIT.java b/vaadin-spring-tests/test-ts-services/src/test/java/com/vaadin/flow/connect/AppViewIT.java index 8ee564668..243c8c531 100644 --- a/vaadin-spring-tests/test-ts-services/src/test/java/com/vaadin/flow/connect/AppViewIT.java +++ b/vaadin-spring-tests/test-ts-services/src/test/java/com/vaadin/flow/connect/AppViewIT.java @@ -41,14 +41,12 @@ private void openTestUrl(String url) { @Before public void setup() throws Exception { super.setup(); - openTestUrl("/"); - testComponent = $("test-component").first(); - content = testComponent.$(TestBenchElement.class).id("content"); + load(); } @After public void tearDown() { - openTestUrl("/logout"); + logout(); } /** @@ -193,6 +191,32 @@ public void should_updateTitleInDOMWithInjectedService(){ driver.findElement(By.tagName("title")).getAttribute("textContent")); } + @Test + public void should_requestAnonymously_after_logout() throws Exception { + String originalCsrfToken = executeScript( + "return self.Vaadin.TypeScript.csrfToken").toString(); + logout(); + load(); + + String csrfToken = executeScript( + "return self.Vaadin.TypeScript.csrfToken").toString(); + Assert.assertNotEquals("CSRF token should change for the new session", + originalCsrfToken, csrfToken); + + WebElement button = testComponent.$(TestBenchElement.class).id( + "helloAnonymous"); + button.click(); + + // Wait for the server connect response + verifyContent("Hello, stranger!"); + } + + private void load() { + openTestUrl("/"); + testComponent = $("test-component").waitForFirst(); + content = testComponent.$(TestBenchElement.class).id("content"); + } + private void login(String user) { // Use form in the test component testComponent.$(TestBenchElement.class).id("username").sendKeys(user); @@ -202,6 +226,10 @@ private void login(String user) { content = testComponent.$(TestBenchElement.class).id("content"); } + private void logout() { + openTestUrl("/logout"); + } + private void verifyCallingAdminService(String expectedMessage) { testComponent.$(TestBenchElement.class).id("helloAdmin").click(); verifyContent(expectedMessage);