From 767f47aa7d3b1c9b8c44603873fecac0469b4b0b Mon Sep 17 00:00:00 2001 From: Charles Le Maux Date: Thu, 3 Oct 2024 23:30:14 +0200 Subject: [PATCH] Separated authorization unit tests. --- Controllers/Default.cs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Controllers/Default.cs b/Controllers/Default.cs index 2012d6a..27f00b1 100644 --- a/Controllers/Default.cs +++ b/Controllers/Default.cs @@ -79,7 +79,7 @@ namespace Simple_API.Controllers } } - [Route("Test/")] + [Route("[controller]")] [ApiController] public class Test : ControllerBase { @@ -113,30 +113,34 @@ namespace Simple_API.Controllers } // DELETE: test/delete - [Authorize] [HttpDelete("Delete")] public IActionResult TestDelete([FromBody] TestPayload testPayload) { return Ok($"DELETE: {ProtocolOk} Deleted: {testPayload.Data}"); } + } + [Route("Test/Protected")] + [ApiController] + public class ProtectedTest : ControllerBase + { [Authorize] - [HttpGet("Protected")] - public IActionResult Protected() + [HttpGet("Basic")] + public IActionResult Basic() { - return Ok("Successfully executed secured request."); + return Ok("Successfully executed secured request. (Any user)"); } [Authorize(Roles = Default.UserRoles.User)] - [HttpGet("ProtectedUserOnly")] - public IActionResult ProtectedUserOnly() + [HttpGet("UserOnly")] + public IActionResult UserOnly() { return Ok("Successfully executed secured request. (User)"); } [Authorize(Roles = Default.UserRoles.Admin)] - [HttpGet("ProtectedAdminOnly")] - public IActionResult ProtectedAdminOnly() + [HttpGet("AdminOnly")] + public IActionResult AdminOnly() { return Ok("Successfully executed secured request. (Admin)"); }