Skip to content

Commit 70e6343

Browse files
Restore homepage XI servers widget by allowing anonymous access to GET /Banners/GetGameServers (#168)
* Initial plan * Allow anonymous access to Banners/GetGameServers Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com> * Harden BannersController authorization test scope Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
1 parent b7a2d37 commit 70e6343

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using System.Reflection;
3+
using XtremeIdiots.Portal.Web.ApiControllers;
4+
5+
namespace XtremeIdiots.Portal.Web.Tests.ApiControllers;
6+
7+
public class BannersControllerTests
8+
{
9+
[Fact]
10+
public void BannersController_HasClassLevelAuthorizeAttribute()
11+
{
12+
var authorizeAttribute = typeof(BannersController).GetCustomAttributes(typeof(AuthorizeAttribute), true).SingleOrDefault();
13+
14+
Assert.NotNull(authorizeAttribute);
15+
}
16+
17+
[Fact]
18+
public void GetGameServers_HasAllowAnonymousAttribute_OnlyAnonymousActionInController()
19+
{
20+
var methods = typeof(BannersController).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
21+
var allowAnonymousMethods = methods
22+
.Where(method => method.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length > 0)
23+
.ToList();
24+
25+
Assert.Single(allowAnonymousMethods);
26+
Assert.Equal(nameof(BannersController.GetGameServers), allowAnonymousMethods[0].Name);
27+
}
28+
}

src/XtremeIdiots.Portal.Web/ApiControllers/BannersController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class BannersController(
4848
/// <param name="cancellationToken">Cancellation token for the request</param>
4949
/// <returns>List of HTML banner content</returns>
5050
[HttpGet("GetGameServers")]
51+
[AllowAnonymous]
5152
[EnableCors("CorsPolicy")]
5253
public async Task<IActionResult> GetGameServers(CancellationToken cancellationToken = default)
5354
{

0 commit comments

Comments
 (0)