From b8b632905d7e17a4bc0b9e34128c82a87b68dfde Mon Sep 17 00:00:00 2001 From: Nanne Baars Date: Thu, 8 Dec 2016 21:49:43 +0100 Subject: [PATCH] Fixing failing unit test --- webgoat-container/pom.xml | 63 ++----- .../owasp/webgoat/plugins/PluginsLoader.java | 2 - .../org/owasp/webgoat/plugins/TestUtils.java | 57 ------- .../webgoat/service/LabelServiceTest.java | 156 +++++++++--------- webgoat-lessons/pom.xml | 5 + 5 files changed, 95 insertions(+), 188 deletions(-) delete mode 100644 webgoat-container/src/test/java/org/owasp/webgoat/plugins/TestUtils.java diff --git a/webgoat-container/pom.xml b/webgoat-container/pom.xml index f51c11ab59..2052b5c81c 100644 --- a/webgoat-container/pom.xml +++ b/webgoat-container/pom.xml @@ -111,9 +111,7 @@ maven-surefire-plugin ${maven-surefire-plugin.version} - - **/*IT.java - + never @@ -184,17 +182,16 @@ org.springframework.boot spring-boot-starter-actuator - - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - org.asciidoctor asciidoctorj 1.5.4 + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + javax.servlet jstl @@ -222,36 +219,11 @@ h2 ${h2.version} - - axis - axis - ${axis.version} - - - axis - axis-saaj - ${axis-saaj.version} - - - axis - axis-jaxrpc - ${axis-jaxrpc.version} - - - axis - axis-ant - ${axis-ant.version} - hsqldb hsqldb ${hsqldb.version} - - wsdl4j - wsdl4j - ${wsdl4j.version} - javax.transaction javax.transaction-api @@ -283,29 +255,18 @@ spring-boot-starter-test test - - - - - - + + org.springframework.security + spring-security-test + 4.1.3.RELEASE + test + junit junit ${junit.version} jar - - org.seleniumhq.selenium - selenium-java - ${selenium-java.version} - - - com.saucelabs - sauce_junit - ${sauce_junit.version} - test - diff --git a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java index 6806f6cc6f..7c2f1fae61 100644 --- a/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java +++ b/webgoat-container/src/main/java/org/owasp/webgoat/plugins/PluginsLoader.java @@ -63,8 +63,6 @@ public Course loadPlugins() { log.error("No lessons found if you downloaded an official release of WebGoat please take the time to"); log.error("create a new issue at https://github.com/WebGoat/WebGoat/issues/new"); log.error("For developers run 'mvn package' first from the root directory."); - log.error("Stopping WebGoat..."); - System.exit(1); //we always run standalone } return new Course(lessons); } diff --git a/webgoat-container/src/test/java/org/owasp/webgoat/plugins/TestUtils.java b/webgoat-container/src/test/java/org/owasp/webgoat/plugins/TestUtils.java deleted file mode 100644 index 89c95cebdc..0000000000 --- a/webgoat-container/src/test/java/org/owasp/webgoat/plugins/TestUtils.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.owasp.webgoat.plugins; - -import org.openqa.selenium.By; -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.StaleElementReferenceException; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.FluentWait; -import org.openqa.selenium.support.ui.WebDriverWait; - -import static java.util.concurrent.TimeUnit.SECONDS; - -/** - * ************************************************************************************************ - * This file is part of WebGoat, an Open Web Application Security Project utility. For details, - * please see http://www.owasp.org/ - *

- * Copyright (c) 2002 - 20014 Bruce Mayhew - *

- * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - *

- * You should have received a copy of the GNU General Public License along with this program; if - * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - *

- * Getting Source ============== - *

- * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software - * projects. - *

- * - * @author WebGoat - * @version $Id: $Id - * @since September 22, 2016 - */ -public class TestUtils { - - public static void assertTitlePresent(WebDriver webDriver, String title) { - FluentWait wait = new WebDriverWait(webDriver, 15); // wait for a maximum of 15 seconds - wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("lesson-title"), title)); - } - - public static FluentWait createDefaultWait(WebDriver webDriver) { - return new FluentWait(webDriver) - .withTimeout(10, SECONDS) - .pollingEvery(2, SECONDS) - .ignoring(NoSuchElementException.class) - .ignoring(StaleElementReferenceException.class); - - } -} diff --git a/webgoat-container/src/test/java/org/owasp/webgoat/service/LabelServiceTest.java b/webgoat-container/src/test/java/org/owasp/webgoat/service/LabelServiceTest.java index 51007722d8..fce5ae93e8 100644 --- a/webgoat-container/src/test/java/org/owasp/webgoat/service/LabelServiceTest.java +++ b/webgoat-container/src/test/java/org/owasp/webgoat/service/LabelServiceTest.java @@ -1,78 +1,78 @@ -//package org.owasp.webgoat.service; -// -//import org.assertj.core.util.Maps; -//import org.hamcrest.CoreMatchers; -//import org.junit.Test; -//import org.junit.runner.RunWith; -//import org.owasp.webgoat.i18n.LabelProvider; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -//import org.springframework.boot.test.mock.mockito.MockBean; -//import org.springframework.security.test.context.support.WithMockUser; -//import org.springframework.test.context.junit4.SpringRunner; -//import org.springframework.test.web.servlet.MockMvc; -//import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -// -//import java.util.Locale; -// -//import static org.mockito.Mockito.when; -//import static org.owasp.webgoat.service.LabelService.URL_LABELS_MVC; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -// -///** -// * ************************************************************************************************ -// * This file is part of WebGoat, an Open Web Application Security Project utility. For details, -// * please see http://www.owasp.org/ -// *

-// * Copyright (c) 2002 - 20014 Bruce Mayhew -// *

-// * This program is free software; you can redistribute it and/or modify it under the terms of the -// * GNU General Public License as published by the Free Software Foundation; either version 2 of the -// * License, or (at your option) any later version. -// *

-// * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without -// * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// * General Public License for more details. -// *

-// * You should have received a copy of the GNU General Public License along with this program; if -// * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// * 02111-1307, USA. -// *

-// * Getting Source ============== -// *

-// * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software -// * projects. -// *

-// * -// * @author nbaars -// * @version $Id: $Id -// * @since November 29, 2016 -// */ -//@WebMvcTest(value = {LabelService.class, LabelProvider.class}) -//@RunWith(SpringRunner.class) -//public class LabelServiceTest { -// -// @Autowired -// public MockMvc mockMvc; -// @MockBean -// private LabelProvider labelProvider; -// -// @Test -// @WithMockUser(username = "guest", password = "guest") -// public void withoutLocale() throws Exception { -// when(labelProvider.getLabels(Locale.ENGLISH)).thenReturn(Maps.newHashMap("key", "value")); -// mockMvc.perform(MockMvcRequestBuilders.get(URL_LABELS_MVC)) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("key", CoreMatchers.is("value"))); -// } -// -// @Test -// @WithMockUser(username = "guest", password = "guest") -// public void withLocale() throws Exception { -// when(labelProvider.getLabels(Locale.GERMAN)).thenReturn(Maps.newHashMap("key", "value")); -// mockMvc.perform(MockMvcRequestBuilders.get(URL_LABELS_MVC).param("lang", "de")) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("key", CoreMatchers.is("value"))); -// } -//} \ No newline at end of file +package org.owasp.webgoat.service; + +import org.assertj.core.util.Maps; +import org.hamcrest.CoreMatchers; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.owasp.webgoat.i18n.LabelProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import java.util.Locale; + +import static org.mockito.Mockito.when; +import static org.owasp.webgoat.service.LabelService.URL_LABELS_MVC; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * ************************************************************************************************ + * This file is part of WebGoat, an Open Web Application Security Project utility. For details, + * please see http://www.owasp.org/ + *

+ * Copyright (c) 2002 - 20014 Bruce Mayhew + *

+ * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License along with this program; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + *

+ * Getting Source ============== + *

+ * Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software + * projects. + *

+ * + * @author nbaars + * @version $Id: $Id + * @since November 29, 2016 + */ +@WebMvcTest(value = {LabelService.class, LabelProvider.class}) +@RunWith(SpringRunner.class) +public class LabelServiceTest { + + @Autowired + public MockMvc mockMvc; + @MockBean + private LabelProvider labelProvider; + + @Test + @WithMockUser(username = "guest", password = "guest") + public void withoutLocale() throws Exception { + when(labelProvider.getLabels(Locale.ENGLISH)).thenReturn(Maps.newHashMap("key", "value")); + mockMvc.perform(MockMvcRequestBuilders.get(URL_LABELS_MVC)) + .andExpect(status().isOk()) + .andExpect(jsonPath("key", CoreMatchers.is("value"))); + } + + @Test + @WithMockUser(username = "guest", password = "guest") + public void withLocale() throws Exception { + when(labelProvider.getLabels(Locale.GERMAN)).thenReturn(Maps.newHashMap("key", "value")); + mockMvc.perform(MockMvcRequestBuilders.get(URL_LABELS_MVC).param("lang", "de")) + .andExpect(status().isOk()) + .andExpect(jsonPath("key", CoreMatchers.is("value"))); + } +} \ No newline at end of file diff --git a/webgoat-lessons/pom.xml b/webgoat-lessons/pom.xml index 43928291db..0bae954366 100644 --- a/webgoat-lessons/pom.xml +++ b/webgoat-lessons/pom.xml @@ -29,6 +29,11 @@ provided jar + + org.apache.commons + commons-exec + 1.3 +