From 2e2b22f87ecbd40e3328a089efb3189a3b9cdd99 Mon Sep 17 00:00:00 2001 From: "Michael J. Simons" Date: Thu, 11 Jan 2018 11:19:28 +0100 Subject: [PATCH] Migrate xml-insecure groovy->java See #4939. --- ...pring-security-samples-xml-insecure.gradle | 18 ++++++- .../samples/HelloInsecureTests.groovy | 36 ------------- .../security/samples/pages/HomePage.groovy | 31 ----------- .../security/samples/HelloInsecureTests.java | 51 ++++++++++++++++++ .../security/samples/pages/HomePage.java | 54 +++++++++++++++++++ 5 files changed, 122 insertions(+), 68 deletions(-) delete mode 100644 samples/xml/insecure/src/integration-test/groovy/org/springframework/security/samples/HelloInsecureTests.groovy delete mode 100644 samples/xml/insecure/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy create mode 100644 samples/xml/insecure/src/integration-test/java/org/springframework/security/samples/HelloInsecureTests.java create mode 100644 samples/xml/insecure/src/integration-test/java/org/springframework/security/samples/pages/HomePage.java diff --git a/samples/xml/insecure/spring-security-samples-xml-insecure.gradle b/samples/xml/insecure/spring-security-samples-xml-insecure.gradle index 9710669975..6e9e855f1a 100644 --- a/samples/xml/insecure/spring-security-samples-xml-insecure.gradle +++ b/samples/xml/insecure/spring-security-samples-xml-insecure.gradle @@ -1,3 +1,19 @@ +/* + * Copyright 2002-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + apply plugin: 'io.spring.convention.spring-sample-war' dependencies { @@ -7,5 +23,5 @@ dependencies { providedCompile 'javax.servlet:javax.servlet-api' providedCompile 'javax.servlet.jsp:javax.servlet.jsp-api' - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies } diff --git a/samples/xml/insecure/src/integration-test/groovy/org/springframework/security/samples/HelloInsecureTests.groovy b/samples/xml/insecure/src/integration-test/groovy/org/springframework/security/samples/HelloInsecureTests.groovy deleted file mode 100644 index a7d0d3101d..0000000000 --- a/samples/xml/insecure/src/integration-test/groovy/org/springframework/security/samples/HelloInsecureTests.groovy +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2002-2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.security.samples - -import geb.spock.* -import spock.lang.Stepwise -import org.springframework.security.samples.pages.* - -/** - * - * @author Rob Winch - */ -@Stepwise -class HelloInsecureTests extends GebReportingSpec { - def 'The HomePage is accessible'() { - when: 'Unauthenticated user accesses the Home Page' - to HomePage - then: 'The HomePage is displayed' - at HomePage - and: 'We can see the message' - message == 'We would like to secure this page' - } -} diff --git a/samples/xml/insecure/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy b/samples/xml/insecure/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy deleted file mode 100644 index afdb5eb7d6..0000000000 --- a/samples/xml/insecure/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2002-2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.security.samples.pages; - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Hello World'; true} - static content = { - message { $('p').text() } - } -} diff --git a/samples/xml/insecure/src/integration-test/java/org/springframework/security/samples/HelloInsecureTests.java b/samples/xml/insecure/src/integration-test/java/org/springframework/security/samples/HelloInsecureTests.java new file mode 100644 index 0000000000..715e2b7711 --- /dev/null +++ b/samples/xml/insecure/src/integration-test/java/org/springframework/security/samples/HelloInsecureTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2002-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.security.samples; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import org.springframework.security.samples.pages.HomePage; + +/** + * @author Michael Simons + */ +public class HelloInsecureTests { + + private WebDriver driver; + + private int port; + + @Before + public void setup() { + this.port = Integer.parseInt(System.getProperty("app.httpPort")); + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void theHomePageIsAccessible() { + HomePage.to(this.driver, this.port) + .assertAt() + .andWeCanSeeTheMessage(); + } +} diff --git a/samples/xml/insecure/src/integration-test/java/org/springframework/security/samples/pages/HomePage.java b/samples/xml/insecure/src/integration-test/java/org/springframework/security/samples/pages/HomePage.java new file mode 100644 index 0000000000..b8d11bdf93 --- /dev/null +++ b/samples/xml/insecure/src/integration-test/java/org/springframework/security/samples/pages/HomePage.java @@ -0,0 +1,54 @@ +/* + * Copyright 2002-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.security.samples.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Michael Simons + */ +public class HomePage { + private final WebDriver webDriver; + + public HomePage(WebDriver webDriver) { + this.webDriver = webDriver; + } + + public static HomePage to(WebDriver driver, int port) { + driver.get("http://localhost:" + port +"/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public Content assertAt() { + assertThat(this.webDriver.getTitle()).isEqualTo("Hello World"); + return PageFactory.initElements(this.webDriver, Content.class); + } + + public static class Content { + @FindBy(css = "p") + private WebElement message; + + public Content andWeCanSeeTheMessage() { + assertThat(message.getText()).isEqualTo("We would like to secure this page"); + return this; + } + } +}