Fix JWT integration tests
This commit is contained in:
@ -236,12 +236,14 @@ public abstract class IntegrationTest {
|
||||
}
|
||||
|
||||
public void checkResults() {
|
||||
MatcherAssert.assertThat(RestAssured.given()
|
||||
var result = RestAssured.given()
|
||||
.when()
|
||||
.relaxedHTTPSValidation()
|
||||
.cookie("JSESSIONID", getWebGoatCookie())
|
||||
.get(url("service/lessonoverview.mvc"))
|
||||
.then()
|
||||
.andReturn();
|
||||
|
||||
MatcherAssert.assertThat(result.then()
|
||||
.statusCode(200).extract().jsonPath().getList("solved"), CoreMatchers.everyItem(CoreMatchers.is(true)));
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,8 @@ public class JWTLessonTest extends IntegrationTest {
|
||||
|
||||
deleteTom();
|
||||
|
||||
quiz();
|
||||
|
||||
checkResults("/JWT/");
|
||||
|
||||
}
|
||||
@ -76,25 +78,14 @@ public class JWTLessonTest extends IntegrationTest {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void decodingToken() throws IOException, NoSuchAlgorithmException, InvalidKeyException {
|
||||
|
||||
String accessToken = RestAssured.given()
|
||||
.when()
|
||||
.relaxedHTTPSValidation()
|
||||
.cookie("JSESSIONID", getWebGoatCookie())
|
||||
.get(url("/WebGoat/JWT/secret/gettoken"))
|
||||
.then()
|
||||
.extract().response().asString();
|
||||
|
||||
String secret = getSecretToken(accessToken);
|
||||
|
||||
private void decodingToken() {
|
||||
MatcherAssert.assertThat(
|
||||
RestAssured.given()
|
||||
.when()
|
||||
.relaxedHTTPSValidation()
|
||||
.cookie("JSESSIONID", getWebGoatCookie())
|
||||
.formParam("token", generateToken(secret))
|
||||
.post(url("/WebGoat/JWT/secret"))
|
||||
.formParam("jwt-encode-user", "user")
|
||||
.post(url("/WebGoat/JWT/decode"))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("lessonCompleted"), CoreMatchers.is(true));
|
||||
@ -216,4 +207,12 @@ public class JWTLessonTest extends IntegrationTest {
|
||||
.extract().path("lessonCompleted"), CoreMatchers.is(true));
|
||||
}
|
||||
|
||||
private void quiz() {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("question_0_solution", "Solution 1");
|
||||
params.put("question_1_solution", "Solution 2");
|
||||
|
||||
checkAssignment(url("/WebGoat/JWT/quiz"), params, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController
|
||||
public class JWTQuiz extends AssignmentEndpoint {
|
||||
@ -41,8 +40,6 @@ public class JWTQuiz extends AssignmentEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/JWT/quiz")
|
||||
@ResponseBody
|
||||
public boolean[] getResults() {
|
||||
|
Reference in New Issue
Block a user