Skip to content

Commit 1469a83

Browse files
committed
fix: resolve integration test issues
1 parent 527735e commit 1469a83

10 files changed

Lines changed: 14 additions & 59 deletions

File tree

user-management/src/Stickerlandia.UserManagement.Agnostic/MicrsoftIdentityAuthService.cs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public class MicrosoftIdentityAuthService(
2020
IOpenIddictApplicationManager applicationManager,
2121
IOpenIddictScopeManager scopeManager,
2222
UserManagementDbContext dbContext,
23-
SignInManager<PostgresUserAccount> signInManager,
2423
UserManager<PostgresUserAccount> userManager) : IAuthService
2524
{
2625
public async Task<ClaimsIdentity?> VerifyClient(string clientId)
@@ -56,34 +55,15 @@ OpenIddictConstants.Claims.Name when claim.Subject.HasScope(OpenIddictConstants.
5655
{
5756
var identity = new ClaimsIdentity(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
5857
OpenIddictConstants.Claims.Name, OpenIddictConstants.Claims.Role);
59-
PostgresUserAccount? user = await userManager.FindByEmailAsync(username);
58+
var user = await userManager.FindByEmailAsync(username);
6059
AuthenticationProperties properties = new();
6160

6261
if (user == null)
6362
return null;
6463

65-
// Check that the user can sign in and is not locked out.
66-
// If two-factor authentication is supported, it would also be appropriate to check that 2FA is enabled for the user
67-
if (!await signInManager.CanSignInAsync(user) ||
68-
(userManager.SupportsUserLockout && await userManager.IsLockedOutAsync(user)))
69-
// Return bad request is the user can't sign in
70-
return null;
71-
7264
// Validate the username/password parameters and ensure the account is not locked out.
73-
var result = await signInManager.CheckPasswordSignInAsync(user, password, false);
74-
if (!result.Succeeded)
75-
{
76-
if (result.IsNotAllowed)
77-
return null;
78-
79-
if (result.RequiresTwoFactor)
80-
return null;
81-
82-
if (result.IsLockedOut)
83-
return null;
84-
else
85-
return null;
86-
}
65+
var result = await userManager.CheckPasswordAsync(user, password);
66+
if (!result) return null;
8767

8868
// The user is now validated, so reset lockout counts, if necessary
8969
if (userManager.SupportsUserLockout) await userManager.ResetAccessFailedCountAsync(user);
@@ -95,6 +75,7 @@ OpenIddictConstants.Claims.Name when claim.Subject.HasScope(OpenIddictConstants.
9575
identity.SetResources(resources);
9676

9777
// Add Custom claims
78+
identity.AddClaim(new Claim(OpenIddictConstants.Claims.Name, user.Id));
9879
identity.AddClaim(new Claim(OpenIddictConstants.Claims.Subject, user.Id));
9980
identity.AddClaim(new Claim(OpenIddictConstants.Claims.Audience, "Resource"));
10081
identity.AddClaim(new Claim(OpenIddictConstants.Claims.Email, user.Email));

user-management/src/Stickerlandia.UserManagement.Agnostic/ServiceExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static IServiceCollection AddPostgresAuthServices(this IServiceCollection
6969
options.UseOpenIddict();
7070
});
7171

72-
services.AddIdentity<PostgresUserAccount, IdentityRole>()
72+
services.AddIdentityCore<PostgresUserAccount>()
7373
.AddEntityFrameworkStores<UserManagementDbContext>()
7474
.AddDefaultTokenProviders();
7575

user-management/src/Stickerlandia.UserManagement.AspNet/ApiResponse.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public ApiResponse(bool isSuccess, T body, string message, HttpStatusCode status
4040
internal async Task<HttpResponseData> WriteResponse(HttpRequestData req)
4141
{
4242
var response = req.CreateResponse(StatusCode);
43+
response.StatusCode = StatusCode;
4344
await response.WriteAsJsonAsync(this);
4445
return response;
4546
}

user-management/src/Stickerlandia.UserManagement.AspNet/GetUserDetailsEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static class GetUserDetails
1414
[FromServices] IAuthService authService,
1515
[FromServices] GetUserDetailsQueryHandler handler)
1616
{
17-
if (user.Identity?.Name == null)
17+
if (user.Identity.Name == null)
1818
{
1919
return new ApiResponse<UserAccountDTO?>(false, null, "User not authenticated", HttpStatusCode.Unauthorized);
2020
}

user-management/src/Stickerlandia.UserManagement.AspNet/Program.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@
8282
});
8383
});
8484
builder.Services.AddEndpointsApiExplorer();
85-
// Add response compression for improved performance
8685
builder.Services.AddResponseCompression(options => { options.EnableForHttps = true; });
8786

8887
builder.Services.AddHostedService<OutboxWorker>();
89-
//builder.Services.AddHostedService<StickerClaimedWorker>();
9088

9189
builder.Services.AddControllers();
9290
builder.Services.AddCors(options =>
@@ -124,8 +122,6 @@
124122
.UseAuthentication()
125123
.UseAuthorization();
126124

127-
app.MapControllers();
128-
129125
var api = app.NewVersionedApi("api");
130126
var v1ApiEndpoints = api.MapGroup("api/users/v{version:apiVersion}")
131127
.HasApiVersion(1.0);

user-management/src/Stickerlandia.UserManagement.Auth/AuthServiceExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ public static IServiceCollection AddCoreAuthentication(this IServiceCollection s
4747

4848
// Register the ASP.NET Core host and configure the ASP.NET Core options.
4949
options.UseAspNetCore()
50-
.EnableAuthorizationEndpointPassthrough()
51-
.EnableTokenEndpointPassthrough()
52-
.EnableEndSessionEndpointPassthrough();
50+
.EnableTokenEndpointPassthrough();
5351

5452
options.AddEventHandler<OpenIddictServerEvents.HandleUserInfoRequestContext>(options => options.UseInlineHandler(context =>
5553
{

user-management/src/Stickerlandia.UserManagement.Auth/DynamoDbIdentityAuthService.cs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ namespace Stickerlandia.UserManagement.Auth;
2323
/// DynamoDB-specific implementation of IAuthService using AWS DynamoDB for persistence
2424
/// </summary>
2525
public class DynamoDbIdentityAuthService(
26-
SignInManager<IdentityUser> signInManager,
2726
UserManager<IdentityUser> userManager,
2827
IOpenIddictApplicationManager applicationManager,
2928
ILogger<DynamoDbIdentityAuthService> logger,
@@ -74,29 +73,9 @@ OpenIddictConstants.Claims.Name when claim.Subject.HasScope(OpenIddictConstants.
7473
if (user == null)
7574
return null;
7675

77-
// Check that the user can sign in and is not locked out.
78-
// If two-factor authentication is supported, it would also be appropriate to check that 2FA is enabled for the user
79-
if (!await signInManager.CanSignInAsync(user) ||
80-
(userManager.SupportsUserLockout && await userManager.IsLockedOutAsync(user)))
81-
// Return bad request is the user can't sign in
82-
return null;
83-
8476
// Validate the username/password parameters and ensure the account is not locked out.
85-
var result = await signInManager.PasswordSignInAsync(user.UserName, password, false,
86-
false);
87-
if (!result.Succeeded)
88-
{
89-
if (result.IsNotAllowed)
90-
return null;
91-
92-
if (result.RequiresTwoFactor)
93-
return null;
94-
95-
if (result.IsLockedOut)
96-
return null;
97-
else
98-
return null;
99-
}
77+
var result = await userManager.CheckPasswordAsync(user, password);
78+
if (!result) return null;
10079

10180
// The user is now validated, so reset lockout counts, if necessary
10281
if (userManager.SupportsUserLockout) await userManager.ResetAccessFailedCountAsync(user);

user-management/src/Stickerlandia.UserManagement.Auth/DynamoDbServiceExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static IServiceCollection AddDynamoDbAuthServices(this IServiceCollection
4242
services.AddSingleton<IOpenIddictScopeStore<DynamoDbScope>, DynamoDbScopeStore>();
4343

4444
// Configure Identity with DynamoDB stores
45-
services.AddIdentity<IdentityUser, IdentityRole>(options =>
45+
services.AddIdentityCore<IdentityUser>(options =>
4646
{
4747
options.ClaimsIdentity.UserNameClaimType = OpenIddictConstants.Claims.Name;
4848
options.ClaimsIdentity.UserIdClaimType = OpenIddictConstants.Claims.Subject;

user-management/tests/Stickerlandia.UserManagement.IntegrationTest/Drivers/AccountDriver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public AccountDriver(ITestOutputHelper testOutputHelper, HttpClient httpClient,
7070
new("grant_type", "password"),
7171
new("username", emailAddress),
7272
new("password", password),
73-
new("client_id", "user-authentication"), // Replace with your client_id
74-
new("client_secret", "388D45FA-B36B-4988-BA59-B187D329C207") // Replace with your client_secret
73+
new("client_id", "user-authentication"),
74+
new("client_secret", "388D45FA-B36B-4988-BA59-B187D329C207")
7575
};
7676

7777
var requestContent = new FormUrlEncodedContent(requestBody);

user-management/tests/Stickerlandia.UserManagement.IntegrationTest/Hooks/TestSetupFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public TestSetupFixture()
5050

5151
var messagingConnectionString = App.GetConnectionStringAsync("messaging").GetAwaiter().GetResult();
5252

53-
HttpClient = App.CreateHttpClient("api");
53+
HttpClient = App.CreateHttpClient("api", "https");
5454
Messaging = MessagingProviderFactory.From(drivenAdapter, messagingConnectionString);
5555
}
5656
else

0 commit comments

Comments
 (0)