Skip to content

Commit db5eb49

Browse files
authored
Merge pull request #2 from mackowski/lint-update
style: apply dotnet format across codebase
2 parents 57777c9 + 25c23b5 commit db5eb49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1506
-1490
lines changed
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
using Hangfire.Dashboard;
2-
3-
namespace _10xGitHubPolicies.App.Authorization;
4-
5-
/// <summary>
6-
/// Custom authorization filter for Hangfire dashboard that requires user authentication.
7-
/// </summary>
8-
public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter
9-
{
10-
/// <summary>
11-
/// Determines whether the current user is authorized to access the Hangfire dashboard.
12-
/// </summary>
13-
/// <param name="context">The dashboard context containing HTTP context information.</param>
14-
/// <returns>True if the user is authenticated, false otherwise.</returns>
15-
public bool Authorize(DashboardContext context)
16-
{
17-
var httpContext = context.GetHttpContext();
18-
return httpContext.User.Identity?.IsAuthenticated == true;
19-
}
20-
}
1+
using Hangfire.Dashboard;
2+
3+
namespace _10xGitHubPolicies.App.Authorization;
4+
5+
/// <summary>
6+
/// Custom authorization filter for Hangfire dashboard that requires user authentication.
7+
/// </summary>
8+
public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter
9+
{
10+
/// <summary>
11+
/// Determines whether the current user is authorized to access the Hangfire dashboard.
12+
/// </summary>
13+
/// <param name="context">The dashboard context containing HTTP context information.</param>
14+
/// <returns>True if the user is authenticated, false otherwise.</returns>
15+
public bool Authorize(DashboardContext context)
16+
{
17+
var httpContext = context.GetHttpContext();
18+
return httpContext.User.Identity?.IsAuthenticated == true;
19+
}
20+
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
using Microsoft.AspNetCore.Authentication;
2-
using Microsoft.AspNetCore.Authentication.Cookies;
3-
using Microsoft.AspNetCore.Mvc;
4-
5-
namespace _10xGitHubPolicies.App.Controllers;
6-
7-
[Route("[controller]")]
8-
public class AccountController : Controller
9-
{
10-
[HttpGet("Logout")]
11-
public async Task<IActionResult> Logout()
12-
{
13-
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
14-
return RedirectToAction("Login", "Account");
15-
}
16-
17-
[HttpGet("Login")]
18-
public IActionResult Login()
19-
{
20-
return Redirect("/login");
21-
}
22-
}
1+
using Microsoft.AspNetCore.Authentication;
2+
using Microsoft.AspNetCore.Authentication.Cookies;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace _10xGitHubPolicies.App.Controllers;
6+
7+
[Route("[controller]")]
8+
public class AccountController : Controller
9+
{
10+
[HttpGet("Logout")]
11+
public async Task<IActionResult> Logout()
12+
{
13+
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
14+
return RedirectToAction("Login", "Account");
15+
}
16+
17+
[HttpGet("Login")]
18+
public IActionResult Login()
19+
{
20+
return Redirect("/login");
21+
}
22+
}
Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
using Microsoft.AspNetCore.Authentication;
2-
using Microsoft.Extensions.Options;
3-
using System.Security.Claims;
4-
using System.Text.Encodings.Web;
5-
6-
namespace _10xGitHubPolicies.App.Middleware;
7-
8-
/// <summary>
9-
/// Authentication handler for test mode that always succeeds with a fake user.
10-
/// </summary>
11-
public class TestModeAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
12-
{
13-
public TestModeAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
14-
: base(options, logger, encoder, clock)
15-
{
16-
}
17-
18-
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
19-
{
20-
// Create a fake authenticated user for testing - using real GitHub user that's part of mackowski-corp/appsec team
21-
var claims = new List<Claim>
22-
{
23-
new(ClaimTypes.NameIdentifier, "mackowski"),
24-
new(ClaimTypes.Name, "mackowski"),
25-
new("login", "mackowski"),
26-
new("avatar_url", "https://github.com/images/error/octocat_happy.gif"),
27-
new("html_url", "https://github.com/mackowski"),
28-
new("type", "User")
29-
};
30-
31-
var identity = new ClaimsIdentity(claims, Scheme.Name);
32-
var principal = new ClaimsPrincipal(identity);
33-
34-
// Create authentication properties (no access token needed in test mode)
35-
var properties = new AuthenticationProperties();
36-
37-
var ticket = new AuthenticationTicket(principal, properties, Scheme.Name);
38-
39-
return Task.FromResult(AuthenticateResult.Success(ticket));
40-
}
41-
}
1+
using System.Security.Claims;
2+
using System.Text.Encodings.Web;
3+
4+
using Microsoft.AspNetCore.Authentication;
5+
using Microsoft.Extensions.Options;
6+
7+
namespace _10xGitHubPolicies.App.Middleware;
8+
9+
/// <summary>
10+
/// Authentication handler for test mode that always succeeds with a fake user.
11+
/// </summary>
12+
public class TestModeAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
13+
{
14+
public TestModeAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
15+
: base(options, logger, encoder, clock)
16+
{
17+
}
18+
19+
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
20+
{
21+
// Create a fake authenticated user for testing - using real GitHub user that's part of mackowski-corp/appsec team
22+
var claims = new List<Claim>
23+
{
24+
new(ClaimTypes.NameIdentifier, "mackowski"),
25+
new(ClaimTypes.Name, "mackowski"),
26+
new("login", "mackowski"),
27+
new("avatar_url", "https://github.com/images/error/octocat_happy.gif"),
28+
new("html_url", "https://github.com/mackowski"),
29+
new("type", "User")
30+
};
31+
32+
var identity = new ClaimsIdentity(claims, Scheme.Name);
33+
var principal = new ClaimsPrincipal(identity);
34+
35+
// Create authentication properties (no access token needed in test mode)
36+
var properties = new AuthenticationProperties();
37+
38+
var ticket = new AuthenticationTicket(principal, properties, Scheme.Name);
39+
40+
return Task.FromResult(AuthenticateResult.Success(ticket));
41+
}
42+
}
Lines changed: 75 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,75 @@
1-
using Microsoft.AspNetCore.Authentication;
2-
using Microsoft.Extensions.Options;
3-
using System.Security.Claims;
4-
using _10xGitHubPolicies.App.Options;
5-
6-
namespace _10xGitHubPolicies.App.Middleware;
7-
8-
/// <summary>
9-
/// Middleware that bypasses authentication when test mode is enabled.
10-
/// Creates a fake authenticated user context for E2E testing.
11-
/// </summary>
12-
public class TestModeAuthenticationMiddleware
13-
{
14-
private readonly RequestDelegate _next;
15-
private readonly TestModeOptions _options;
16-
17-
public TestModeAuthenticationMiddleware(RequestDelegate next, IOptions<TestModeOptions> options)
18-
{
19-
_next = next;
20-
_options = options.Value;
21-
}
22-
23-
public async Task InvokeAsync(HttpContext context)
24-
{
25-
// Only bypass authentication if test mode is enabled
26-
if (_options.Enabled)
27-
{
28-
// Create a fake authenticated user for testing - using real GitHub user that's part of mackowski-corp/appsec team
29-
var claims = new List<Claim>
30-
{
31-
new(ClaimTypes.NameIdentifier, "mackowski"),
32-
new(ClaimTypes.Name, "mackowski"),
33-
new("login", "mackowski"),
34-
new("avatar_url", "https://github.com/images/error/octocat_happy.gif"),
35-
new("html_url", "https://github.com/mackowski"),
36-
new("type", "User")
37-
};
38-
39-
var identity = new ClaimsIdentity(claims, "TestMode");
40-
var principal = new ClaimsPrincipal(identity);
41-
42-
context.User = principal;
43-
44-
// Create authentication properties (no access token needed in test mode)
45-
var properties = new AuthenticationProperties();
46-
47-
// Set authentication result
48-
var authResult = AuthenticateResult.Success(new AuthenticationTicket(principal, properties, "TestMode"));
49-
context.Features.Set<IAuthenticateResultFeature>(new AuthenticateResultFeature { AuthenticateResult = authResult });
50-
}
51-
52-
await _next(context);
53-
}
54-
}
55-
56-
/// <summary>
57-
/// Feature to hold authentication result for test mode.
58-
/// </summary>
59-
public class AuthenticateResultFeature : IAuthenticateResultFeature
60-
{
61-
public AuthenticateResult? AuthenticateResult { get; set; }
62-
}
63-
64-
/// <summary>
65-
/// Extension method to register the test mode authentication middleware.
66-
/// </summary>
67-
public static class TestModeAuthenticationMiddlewareExtensions
68-
{
69-
public static IApplicationBuilder UseTestModeAuthentication(this IApplicationBuilder builder)
70-
{
71-
return builder.UseMiddleware<TestModeAuthenticationMiddleware>();
72-
}
73-
}
1+
using System.Security.Claims;
2+
3+
using _10xGitHubPolicies.App.Options;
4+
5+
using Microsoft.AspNetCore.Authentication;
6+
using Microsoft.Extensions.Options;
7+
8+
namespace _10xGitHubPolicies.App.Middleware;
9+
10+
/// <summary>
11+
/// Middleware that bypasses authentication when test mode is enabled.
12+
/// Creates a fake authenticated user context for E2E testing.
13+
/// </summary>
14+
public class TestModeAuthenticationMiddleware
15+
{
16+
private readonly RequestDelegate _next;
17+
private readonly TestModeOptions _options;
18+
19+
public TestModeAuthenticationMiddleware(RequestDelegate next, IOptions<TestModeOptions> options)
20+
{
21+
_next = next;
22+
_options = options.Value;
23+
}
24+
25+
public async Task InvokeAsync(HttpContext context)
26+
{
27+
// Only bypass authentication if test mode is enabled
28+
if (_options.Enabled)
29+
{
30+
// Create a fake authenticated user for testing - using real GitHub user that's part of mackowski-corp/appsec team
31+
var claims = new List<Claim>
32+
{
33+
new(ClaimTypes.NameIdentifier, "mackowski"),
34+
new(ClaimTypes.Name, "mackowski"),
35+
new("login", "mackowski"),
36+
new("avatar_url", "https://github.com/images/error/octocat_happy.gif"),
37+
new("html_url", "https://github.com/mackowski"),
38+
new("type", "User")
39+
};
40+
41+
var identity = new ClaimsIdentity(claims, "TestMode");
42+
var principal = new ClaimsPrincipal(identity);
43+
44+
context.User = principal;
45+
46+
// Create authentication properties (no access token needed in test mode)
47+
var properties = new AuthenticationProperties();
48+
49+
// Set authentication result
50+
var authResult = AuthenticateResult.Success(new AuthenticationTicket(principal, properties, "TestMode"));
51+
context.Features.Set<IAuthenticateResultFeature>(new AuthenticateResultFeature { AuthenticateResult = authResult });
52+
}
53+
54+
await _next(context);
55+
}
56+
}
57+
58+
/// <summary>
59+
/// Feature to hold authentication result for test mode.
60+
/// </summary>
61+
public class AuthenticateResultFeature : IAuthenticateResultFeature
62+
{
63+
public AuthenticateResult? AuthenticateResult { get; set; }
64+
}
65+
66+
/// <summary>
67+
/// Extension method to register the test mode authentication middleware.
68+
/// </summary>
69+
public static class TestModeAuthenticationMiddlewareExtensions
70+
{
71+
public static IApplicationBuilder UseTestModeAuthentication(this IApplicationBuilder builder)
72+
{
73+
return builder.UseMiddleware<TestModeAuthenticationMiddleware>();
74+
}
75+
}

10xGitHubPolicies.App/Options/GitHubAppOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class GitHubAppOptions
88
public string PrivateKey { get; set; } = string.Empty;
99
public long InstallationId { get; set; }
1010
public string OrganizationName { get; set; } = string.Empty;
11-
11+
1212
/// <summary>
1313
/// Optional base URL for GitHub API. If null, uses default GitHub API (https://api.github.com).
1414
/// Primarily used for testing with WireMock.
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
namespace _10xGitHubPolicies.App.Options;
2-
3-
/// <summary>
4-
/// Configuration options for test mode functionality.
5-
/// Used to enable authentication bypass for E2E testing.
6-
/// </summary>
7-
public class TestModeOptions
8-
{
9-
public const string TestMode = "TestMode";
10-
11-
/// <summary>
12-
/// Enables test mode which bypasses user authentication for E2E testing.
13-
/// When enabled, all routes become accessible without OAuth authentication.
14-
/// GitHub App functionality remains intact for repository operations.
15-
/// </summary>
16-
public bool Enabled { get; set; } = false;
17-
}
1+
namespace _10xGitHubPolicies.App.Options;
2+
3+
/// <summary>
4+
/// Configuration options for test mode functionality.
5+
/// Used to enable authentication bypass for E2E testing.
6+
/// </summary>
7+
public class TestModeOptions
8+
{
9+
public const string TestMode = "TestMode";
10+
11+
/// <summary>
12+
/// Enables test mode which bypasses user authentication for E2E testing.
13+
/// When enabled, all routes become accessible without OAuth authentication.
14+
/// GitHub App functionality remains intact for repository operations.
15+
/// </summary>
16+
public bool Enabled { get; set; } = false;
17+
}

0 commit comments

Comments
 (0)