File tree Expand file tree Collapse file tree
XtremeIdiots.Portal.Web.Tests/ApiControllers
XtremeIdiots.Portal.Web/ApiControllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments