refactor: small updates and improvements in HTTP Basic lesson (#2024)

* refactor: cleanup attack result and builder

* refactor: solve compiler warnings

* feature: improve HTTP basics lesson

Closes: #494
This commit is contained in:
Nanne Baars
2025-02-18 14:26:21 +01:00
committed by GitHub
parent 00f3538be2
commit c3c520f487
13 changed files with 31 additions and 59 deletions

View File

@ -12,13 +12,13 @@ import org.owasp.webgoat.container.i18n.PluginMessages;
@Getter
public class AttackResult {
private boolean lessonCompleted;
private String feedback;
private final boolean lessonCompleted;
private final String feedback;
private Object[] feedbackArgs;
private String output;
private final String output;
private Object[] outputArgs;
private final String assignment;
private boolean attemptWasMade;
private final boolean attemptWasMade;
private AttackResult(
boolean lessonCompleted,

View File

@ -8,7 +8,6 @@ import org.owasp.webgoat.container.i18n.PluginMessages;
public class AttackResultBuilder {
private PluginMessages messages;
private boolean lessonCompleted;
private Object[] feedbackArgs;
private String feedbackResourceBundleKey;
@ -16,13 +15,6 @@ public class AttackResultBuilder {
private Object[] outputArgs;
private AssignmentEndpoint assignment;
private boolean attemptWasMade = false;
private boolean assignmentCompleted;
public AttackResultBuilder(PluginMessages messages) {
this.messages = messages;
}
public AttackResultBuilder() {}
public AttackResultBuilder lessonCompleted(boolean lessonCompleted) {
this.lessonCompleted = lessonCompleted;
@ -36,19 +28,6 @@ public class AttackResultBuilder {
return this;
}
public AttackResultBuilder assignmentCompleted(boolean assignmentCompleted) {
this.assignmentCompleted = assignmentCompleted;
this.feedbackResourceBundleKey = "assignment.completed";
return this;
}
public AttackResultBuilder assignmentCompleted(
boolean assignmentCompleted, String resourceBundleKey) {
this.assignmentCompleted = assignmentCompleted;
this.feedbackResourceBundleKey = resourceBundleKey;
return this;
}
public AttackResultBuilder feedbackArgs(Object... args) {
this.feedbackArgs = args;
return this;
@ -95,15 +74,14 @@ public class AttackResultBuilder {
*
* <p>- Assignment is set to solved - Feedback message is set to 'assignment.solved'
*
* <p>Of course you can overwrite these values in a specific lesson
* <p>Of course, you can overwrite these values in a specific lesson
*
* @param assignment the assignment that was solved
* @return a builder for creating a result from a lesson
* @param assignment
*/
public static AttackResultBuilder success(AssignmentEndpoint assignment) {
return new AttackResultBuilder()
.lessonCompleted(true)
.assignmentCompleted(true)
.attemptWasMade()
.feedback("assignment.solved")
.assignment(assignment);
@ -114,15 +92,14 @@ public class AttackResultBuilder {
*
* <p>- Assignment is set to not solved - Feedback message is set to 'assignment.not.solved'
*
* <p>Of course you can overwrite these values in a specific lesson
* <p>Of course, you can overwrite these values in a specific lesson
*
* @param assignment the assignment that was not solved
* @return a builder for creating a result from a lesson
* @param assignment
*/
public static AttackResultBuilder failed(AssignmentEndpoint assignment) {
return new AttackResultBuilder()
.lessonCompleted(false)
.assignmentCompleted(true)
.attemptWasMade()
.feedback("assignment.not.solved")
.assignment(assignment);

View File

@ -13,9 +13,6 @@ import org.springframework.web.servlet.LocaleResolver;
/**
* Wrapper around the LocaleResolver from Spring so we do not need to bother with passing the
* HttpRequest object when asking for a Locale.
*
* @author nbaars
* @date 2/7/17
*/
@AllArgsConstructor
public class Language {

View File

@ -11,9 +11,6 @@ import org.springframework.core.io.support.ResourcePatternResolver;
/**
* Message resource bundle for plugins.
*
* @author nbaars
* @date 2/4/17
*/
public class PluginMessages extends ReloadableResourceBundleMessageSource {
private static final String PROPERTIES_SUFFIX = ".properties";

View File

@ -1,7 +0,0 @@
/*
* SPDX-FileCopyrightText: Copyright © 2024 WebGoat authors
* SPDX-License-Identifier: GPL-2.0-or-later
*/
package org.owasp.webgoat.container.report;
record LessonStatistics(String name, boolean solved, int numberOfAttempts) {}

View File

@ -54,12 +54,12 @@ public class ReportCardController {
lessonStatistics);
}
private record ReportCard(
public record ReportCard(
int totalNumberOfLessons,
int totalNumberOfAssignments,
long numberOfAssignmentsSolved,
long numberOfLessonsSolved,
List<LessonStatistics> lessonStatistics) {}
private record LessonStatistics(String name, boolean solved, int numberOfAttempts) {}
public record LessonStatistics(String name, boolean solved, int numberOfAttempts) {}
}

View File

@ -16,7 +16,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@AssignmentHints({"http-basics.hints.http_basic_quiz.1", "http-basics.hints.http_basic_quiz.2"})
@AssignmentHints({
"http-basics.hints.http_basic_quiz.1",
"http-basics.hints.http_basic_quiz.2",
"http-basics.hints.http_basic_quiz.3"
})
public class HttpBasicsQuiz implements AssignmentEndpoint {
@PostMapping("/HttpBasics/attack2")