Skip to content

Commit bc74f74

Browse files
Allow anonymous access to Banners/GetGameServers
Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
1 parent a58a0d4 commit bc74f74

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

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

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)