Skip to content
Ameen Abozaid
Planned lessonJNR-046-L04

Testing secured endpoints

  • Lesson 4 of 5
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

test authentication and authorization.

Planned topics

  • Get a real token by logging in during the test (or from a test Keycloak) and send it in the Authorization header.
  • With MockMvc you can use @WithMockUser or JWT post-processors from Spring Security Test.
  • Test each role: allowed, forbidden, and anonymous.
  • Test that a user cannot read another user's data.
  • Never put real credentials in test code; use test users.
Draft outline details

Demonstration

java
given().port(port).header("Authorization", "Bearer " + token)
.when().get("/api/orders/" + otherUsersOrderId)
.then().statusCode(403);

Check your understanding

A logged-in user opens an admin endpoint. Which status?

Show answer

403.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.