From 80c0f5fa17723bbf7b48592dd420ff59377aed70 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Thu, 12 Jun 2014 17:05:39 -0500 Subject: [PATCH] SEC-2626: Add Geb integration tests for form-jc --- samples/form-jc/build.gradle | 2 + samples/form-jc/pom.xml | 48 ++++++++++++++++ .../security/samples/FormJcTests.groovy | 56 +++++++++++++++++++ .../security/samples/pages/HomePage.groovy | 32 +++++++++++ .../security/samples/pages/LoginPage.groovy | 37 ++++++++++++ .../src/main/resources/views/login.html | 2 +- 6 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/FormJcTests.groovy create mode 100644 samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy create mode 100644 samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy diff --git a/samples/form-jc/build.gradle b/samples/form-jc/build.gradle index 685bbbe62a..79830964f4 100644 --- a/samples/form-jc/build.gradle +++ b/samples/form-jc/build.gradle @@ -22,4 +22,6 @@ dependencies { runtime "opensymphony:sitemesh:2.4.2", 'cglib:cglib-nodep:2.2.2', 'ch.qos.logback:logback-classic:0.9.30' + + integrationTestCompile gebDependencies } \ No newline at end of file diff --git a/samples/form-jc/pom.xml b/samples/form-jc/pom.xml index 7d7d2d68f7..5f90bf2220 100644 --- a/samples/form-jc/pom.xml +++ b/samples/form-jc/pom.xml @@ -190,24 +190,72 @@ 0.9.29 test + + commons-httpclient + commons-httpclient + 3.1 + test + junit junit 4.11 test + + org.codehaus.groovy + groovy + 2.0.5 + test + org.easytesting fest-assert 1.4 test + + org.gebish + geb-spock + 0.9.0 + test + org.mockito mockito-core 1.9.5 test + + org.seleniumhq.selenium + selenium-htmlunit-driver + 2.33.0 + test + + + org.spockframework + spock-core + 0.7-groovy-2.0 + test + + + junit-dep + junit + + + + + org.spockframework + spock-spring + 0.7-groovy-2.0 + test + + + junit-dep + junit + + + org.springframework spring-test diff --git a/samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/FormJcTests.groovy b/samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/FormJcTests.groovy new file mode 100644 index 0000000000..85bc256e72 --- /dev/null +++ b/samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/FormJcTests.groovy @@ -0,0 +1,56 @@ +/* + * Copyright 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.Shared +import spock.lang.Stepwise +import org.springframework.security.samples.pages.* + +/** + * Tests the CAS sample application using service tickets. + * + * @author Rob Winch + */ +@Stepwise +class FormJcTests extends GebReportingSpec { + def 'access home page with unauthenticated user sends to login page'() { + when: 'Unauthenticated user accesses the Home Page' + via HomePage + then: 'The login page is displayed' + at LoginPage + } + + def 'authenticated user is sent to original page'() { + when: 'user authenticates' + login() + then: 'The home page is displayed' + at HomePage + and: 'The username is displayed' + user == 'user' + } + + def 'authenticated user logs out'() { + when: 'user logs out' + logout() + then: 'the login page is displayed' + at LoginPage + when: 'Unauthenticated user accesses the Home Page' + via HomePage + then: 'The login page is displayed' + at LoginPage + } +} \ No newline at end of file diff --git a/samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy b/samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy new file mode 100644 index 0000000000..25ce258a34 --- /dev/null +++ b/samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy @@ -0,0 +1,32 @@ +/* + * Copyright 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 == 'Messages : View All'; true} + static content = { + user { $('p.navbar-text').text() } + logout { $('input', type: 'submit').click() } + } +} \ No newline at end of file diff --git a/samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy b/samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy new file mode 100644 index 0000000000..2c23499763 --- /dev/null +++ b/samples/form-jc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy @@ -0,0 +1,37 @@ +/* + * Copyright 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 login page. + * + * @author Rob Winch + */ +class LoginPage extends Page { + static url = 'login' + static at = { assert driver.title == 'Please Login'; true} + static content = { + login(required:false) { user='user', password='password' -> + loginForm.username = user + loginForm.password = password + submit.click() + } + loginForm { $('form') } + submit { $('button', type: 'submit') } + } +} \ No newline at end of file diff --git a/samples/form-jc/src/main/resources/views/login.html b/samples/form-jc/src/main/resources/views/login.html index 6ed3046bf5..91481608a5 100644 --- a/samples/form-jc/src/main/resources/views/login.html +++ b/samples/form-jc/src/main/resources/views/login.html @@ -1,6 +1,6 @@ - Messages : Create + Please Login