Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test/RAPS/RapsControllerAuthorizationTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reflection;
using Microsoft.AspNetCore.Authorization;
using Viper.Areas.RAPS.Controllers;
using Viper.Classes;

namespace Viper.test.RAPS
{
Expand Down Expand Up @@ -38,6 +39,26 @@ public void EveryRapsController_RequiresARapsRole(Type controller)
Assert.False(string.IsNullOrEmpty(roles), $"{controller.Name} is missing an [Authorize(Roles = ...)] restriction");
}

/// <summary>
/// MembersController drifted onto ControllerBase and so missed the ApiController filters:
/// it returned bare arrays where every sibling returned the { success, result } envelope,
/// and its exceptions skipped the standard error shape and correlation id.
/// </summary>
[Theory]
[MemberData(nameof(RapsControllers))]
public void EveryRapsApiController_DerivesFromApiController(Type controller)
{
// The page controller renders views, so it is an AreaController, not an API controller.
if (typeof(AreaController).IsAssignableFrom(controller))
{
return;
}

Assert.True(typeof(ApiController).IsAssignableFrom(controller),
$"{controller.Name} does not derive from ApiController, so it misses [ApiResponse], "
+ "[ApiExceptionFilter] and [ApiSessionUpdateFilter]");
}

[Fact]
public void RapsControllersAreDiscovered()
{
Expand Down
4 changes: 2 additions & 2 deletions web/Areas/RAPS/Controllers/MembersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.EntityFrameworkCore;
using Viper.Areas.RAPS.Models;
using Viper.Areas.RAPS.Services;
using Viper.Classes;
using Viper.Classes.SQLContext;
using Web.Authorization;

Expand All @@ -11,9 +12,8 @@
namespace Viper.Areas.RAPS.Controllers
{
[Route("raps/{Instance=VIPER}/[controller]")]
[ApiController]
[Authorize(Roles = "VMDO SVM-IT,RAPS Users", Policy = "2faAuthentication")]
public class MembersController : ControllerBase
public class MembersController : ApiController
Comment thread
rlorenzo marked this conversation as resolved.
{
private readonly RAPSContext _context;
private readonly RAPSSecurityService _securityService;
Expand Down
5 changes: 2 additions & 3 deletions web/Areas/RAPS/Views/Permissions/Members.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,9 @@
}

update(() => {
fetch("Members?search=" + val)
.then(r => r.json())
viperFetch(this, "Members?search=" + val)
.then(data =>
this.memberSearchResults = data
this.memberSearchResults = (data ?? [])
.map(m => ({ label: m.displayLastName + ", " + m.displayFirstName, value: m.memberId }))
)
})
Expand Down
5 changes: 2 additions & 3 deletions web/Areas/RAPS/Views/Roles/Members.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,9 @@
}

update(() => {
fetch("Members?search=" + val)
.then(r => r.json())
viperFetch(this, "Members?search=" + val)
.then(data =>
this.memberSearchResults = data
this.memberSearchResults = (data ?? [])
.map(m => ({ label: m.displayLastName + ", " + m.displayFirstName, value: m.memberId }))
)
})
Expand Down
Loading