mirror of
https://github.com/hubHarmony/Csharp-API-Template.git
synced 2024-11-17 21:40:31 +00:00
Separated authorization unit tests.
This commit is contained in:
parent
130943a052
commit
767f47aa7d
@ -79,7 +79,7 @@ namespace Simple_API.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("Test/")]
|
[Route("[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class Test : ControllerBase
|
public class Test : ControllerBase
|
||||||
{
|
{
|
||||||
@ -113,30 +113,34 @@ namespace Simple_API.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DELETE: test/delete
|
// DELETE: test/delete
|
||||||
[Authorize]
|
|
||||||
[HttpDelete("Delete")]
|
[HttpDelete("Delete")]
|
||||||
public IActionResult TestDelete([FromBody] TestPayload testPayload)
|
public IActionResult TestDelete([FromBody] TestPayload testPayload)
|
||||||
{
|
{
|
||||||
return Ok($"DELETE: {ProtocolOk} Deleted: {testPayload.Data}");
|
return Ok($"DELETE: {ProtocolOk} Deleted: {testPayload.Data}");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route("Test/Protected")]
|
||||||
|
[ApiController]
|
||||||
|
public class ProtectedTest : ControllerBase
|
||||||
|
{
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpGet("Protected")]
|
[HttpGet("Basic")]
|
||||||
public IActionResult Protected()
|
public IActionResult Basic()
|
||||||
{
|
{
|
||||||
return Ok("Successfully executed secured request.");
|
return Ok("Successfully executed secured request. (Any user)");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(Roles = Default.UserRoles.User)]
|
[Authorize(Roles = Default.UserRoles.User)]
|
||||||
[HttpGet("ProtectedUserOnly")]
|
[HttpGet("UserOnly")]
|
||||||
public IActionResult ProtectedUserOnly()
|
public IActionResult UserOnly()
|
||||||
{
|
{
|
||||||
return Ok("Successfully executed secured request. (User)");
|
return Ok("Successfully executed secured request. (User)");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(Roles = Default.UserRoles.Admin)]
|
[Authorize(Roles = Default.UserRoles.Admin)]
|
||||||
[HttpGet("ProtectedAdminOnly")]
|
[HttpGet("AdminOnly")]
|
||||||
public IActionResult ProtectedAdminOnly()
|
public IActionResult AdminOnly()
|
||||||
{
|
{
|
||||||
return Ok("Successfully executed secured request. (Admin)");
|
return Ok("Successfully executed secured request. (Admin)");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user