* Some initial refactoring * Make it one application * Got it working * Fix problem on Windows * Move WebWolf * Move first lesson * Moved all lessons * Fix pom.xml * Fix tests * Add option to initialize a lesson This way we can create content for each user inside a lesson. The initialize method will be called when a new user is created or when a lesson reset happens * Clean up pom.xml files * Remove fetching labels based on language. We only support English at the moment, all the lesson explanations are written in English which makes it very difficult to translate. If we only had labels it would make sense to support multiple languages * Fix SonarLint issues * And move it all to the main project * Fix for documentation paths * Fix pom warnings * Remove PMD as it does not work * Update release notes about refactoring Update release notes about refactoring Update release notes about refactoring * Fix lesson template * Update release notes * Keep it in the same repo in Dockerhub * Update documentation to show how the connection is obtained. Resolves: #1180 * Rename all integration tests * Remove command from Dockerfile * Simplify GitHub actions Currently, we use a separate actions for pull-requests and branch build. This is now consolidated in one action. The PR action triggers always, it now only trigger when the PR is opened and not in draft. Running all platforms on a branch build is a bit too much, it is better to only run all platforms when someone opens a PR. * Remove duplicate entry from release notes * Add explicit registry for base image * Lesson scanner not working when fat jar When running the fat jar we have to take into account we are reading from the jar file and not the filesystem. In this case you cannot use `getFile` for example. * added info in README and fixed release docker * changed base image and added ignore file Co-authored-by: Zubcevic.com <rene@zubcevic.com>
119 lines
4.4 KiB
Java
119 lines
4.4 KiB
Java
package org.owasp.webgoat;
|
|
|
|
import io.restassured.RestAssured;
|
|
import lombok.SneakyThrows;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.assertj.core.api.Assertions;
|
|
import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.DynamicTest;
|
|
import org.junit.jupiter.api.TestFactory;
|
|
|
|
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Map;
|
|
|
|
public class PasswordResetLessonIntegrationTest extends IntegrationTest {
|
|
|
|
@BeforeEach
|
|
@SneakyThrows
|
|
public void init() {
|
|
startLesson("/PasswordReset");
|
|
}
|
|
|
|
@TestFactory
|
|
Iterable<DynamicTest> passwordResetLesson() {
|
|
return Arrays.asList(
|
|
dynamicTest("assignment 6 - check email link",()-> sendEmailShouldBeAvailableInWebWolf()),
|
|
dynamicTest("assignment 6 - solve assignment",()-> solveAssignment()),
|
|
dynamicTest("assignment 2 - simple reset",()-> assignment2()),
|
|
dynamicTest("assignment 4 - guess questions",()-> assignment4()),
|
|
dynamicTest("assignment 5 - simple questions",()-> assignment5())
|
|
);
|
|
}
|
|
public void assignment2() {
|
|
checkAssignment(url("PasswordReset/simple-mail/reset"), Map.of("emailReset", this.getUser()+"@webgoat.org"), false);
|
|
checkAssignment(url("PasswordReset/simple-mail"), Map.of("email", this.getUser()+"@webgoat.org", "password", StringUtils.reverse(this.getUser())), true);
|
|
}
|
|
|
|
public void assignment4() {
|
|
checkAssignment(url("PasswordReset/questions"), Map.of("username", "tom", "securityQuestion", "purple"), true);
|
|
}
|
|
|
|
public void assignment5() {
|
|
checkAssignment(url("PasswordReset/SecurityQuestions"), Map.of("question", "What is your favorite animal?"), false);
|
|
checkAssignment(url("PasswordReset/SecurityQuestions"), Map.of("question", "What is your favorite color?"), true);
|
|
}
|
|
|
|
|
|
public void solveAssignment() {
|
|
//WebGoat
|
|
clickForgotEmailLink("tom@webgoat-cloud.org");
|
|
|
|
//WebWolf
|
|
var link = getPasswordResetLinkFromLandingPage();
|
|
|
|
//WebGoat
|
|
changePassword(link);
|
|
checkAssignment(url("PasswordReset/reset/login"), Map.of("email", "tom@webgoat-cloud.org", "password", "123456"), true);
|
|
}
|
|
|
|
public void sendEmailShouldBeAvailableInWebWolf() {
|
|
clickForgotEmailLink(this.getUser() + "@webgoat.org");
|
|
|
|
var responseBody = RestAssured.given()
|
|
.when()
|
|
.relaxedHTTPSValidation()
|
|
.cookie("WEBWOLFSESSION", getWebWolfCookie())
|
|
.get(webWolfUrl("/WebWolf/mail"))
|
|
.then()
|
|
.extract().response().getBody().asString();
|
|
|
|
Assertions.assertThat(responseBody).contains("Hi, you requested a password reset link");
|
|
}
|
|
|
|
@AfterEach
|
|
public void shutdown() {
|
|
//this will run only once after the list of dynamic tests has run, this is to test if the lesson is marked complete
|
|
checkResults("/PasswordReset");
|
|
}
|
|
|
|
private void changePassword(String link) {
|
|
RestAssured.given()
|
|
.when()
|
|
.relaxedHTTPSValidation()
|
|
.cookie("JSESSIONID", getWebGoatCookie())
|
|
.formParams("resetLink", link, "password", "123456")
|
|
.post(url("PasswordReset/reset/change-password"))
|
|
.then()
|
|
.statusCode(200);
|
|
}
|
|
|
|
private String getPasswordResetLinkFromLandingPage() {
|
|
var responseBody = RestAssured.given()
|
|
.when()
|
|
.relaxedHTTPSValidation()
|
|
.cookie("WEBWOLFSESSION", getWebWolfCookie())
|
|
.get(webWolfUrl("/WebWolf/requests"))
|
|
.then()
|
|
.extract().response().getBody().asString();
|
|
int startIndex = responseBody.lastIndexOf("/PasswordReset/reset/reset-password/");
|
|
var link = responseBody.substring(startIndex + "/PasswordReset/reset/reset-password/".length(), responseBody.indexOf(",", startIndex) - 1);
|
|
return link;
|
|
}
|
|
|
|
private void clickForgotEmailLink(String user) {
|
|
RestAssured.given()
|
|
.when()
|
|
.header("host", String.format("%s:%s", "localhost", getWebWolfPort()))
|
|
.relaxedHTTPSValidation()
|
|
.cookie("JSESSIONID", getWebGoatCookie())
|
|
.formParams("email", user)
|
|
.post(url("PasswordReset/ForgotPassword/create-password-reset-link"))
|
|
.then()
|
|
.statusCode(200);
|
|
}
|
|
}
|