Solution: Method-Level Security
Review the solution to the challenge you attempted in the previous lesson.
We'll cover the following...
We'll cover the following...
Here’s the solution to the previous challenge. We’ll discuss it in detail.
The main difference in this challenge when compared to the DELETE Operation challenge is the URI for deleting the item.
The deletingInventoryWithoutProperRoleFails test function
Let’s take a look at the first test function deletingInventoryWithoutProperRoleFails() in the code snippet below
@Test@WithMockUser(username = "carol", roles = { "SOME_OTHER_ROLE" }) //1void deletingInventoryWithoutProperRoleFails() {this.webTestClient.delete().uri("/api/items/delete/some-item") //2.exchange() //3.expectStatus().isForbidden(); //4}
Here’s a breakdown of the code above:
-
In line 2, this time, the user
carolhas the ...