Migrate xml-insecure groovy->java

See #4939.
This commit is contained in:
Michael J. Simons 2018-01-11 11:19:28 +01:00 committed by Rob Winch
parent 6ba225b62d
commit 2e2b22f87e
5 changed files with 122 additions and 68 deletions

View File

@ -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
}

View File

@ -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'
}
}

View File

@ -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() }
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}
}