Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/GZCTF.Integration.Test/Base/GZCTFApplicationFactory.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Net.Http.Json;
using GZCTF.Models;
using GZCTF.Services.Container.Manager;
using GZCTF.Services.Container.Provider;
Expand Down Expand Up @@ -262,6 +263,25 @@ public async Task InitializeAsync()
await context.Database.MigrateAsync();
}

/// <summary>
/// Create an authenticated HTTP client for the given user
/// </summary>
public HttpClient CreateAuthenticatedClient(TestDataSeeder.SeededUser user)
{
var client = CreateClient();

// Login the user
var loginResponse = client.PostAsJsonAsync("/api/Account/LogIn", new
{
UserName = user.UserName,
Password = user.Password
}).Result;

loginResponse.EnsureSuccessStatusCode();

return client;
}

public new async Task DisposeAsync()
{
// Dispose containers
Expand Down
21 changes: 19 additions & 2 deletions src/GZCTF.Integration.Test/Base/TestDataSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public static async Task<int> GetOrCreateInviteGameAsync(IServiceProvider servic
// Set game invite code
using var scope = services.CreateScope();
var gameRepo = scope.ServiceProvider.GetRequiredService<IGameRepository>();
var gameEntity = await gameRepo.GetGameById(game.Id, default);
var gameEntity = await gameRepo.GetGameById(game.Id);
if (gameEntity != null)
{
gameEntity.InviteCode = "SHARED_INVITE_2025";
await gameRepo.SaveAsync(default);
await gameRepo.SaveAsync();
}

_sharedInviteGameId = game.Id;
Expand Down Expand Up @@ -398,6 +398,23 @@ private static string NormalizeTeamName(string? teamName)
return trimmed;
}

/// <summary>
/// Create a user with specific role
/// </summary>
public static async Task<(SeededUser user, string password)> CreateUserWithRoleAsync(
IServiceProvider services,
Role role = Role.User,
CancellationToken token = default)
{
var password = $"Test{role}Pass123!";
var userName = RandomName();
var email = $"{userName}@test.com";

var user = await CreateUserAsync(services, userName, password, email, role, token);

return (user, password);
}

public record SeededUser(Guid Id, string UserName, string Email, string Password, Role Role);

public record SeededTeam(int Id, string Name, Guid OwnerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task ChallengeSubmissionLimit_ShouldPreventExcessiveSubmissions()
Content = "Challenge with submission limit",
Category = ChallengeCategory.Misc,
Type = ChallengeType.StaticAttachment,
Hints = new List<string>(),
Hints = [],
IsEnabled = true,
SubmissionLimit = 3, // Limit to 3 submissions
OriginalScore = 100,
Expand Down Expand Up @@ -131,7 +131,7 @@ public async Task ChallengeDeadline_ShouldPreventSubmissionsAfterDeadline()
Content = "Challenge with past deadline",
Category = ChallengeCategory.Misc,
Type = ChallengeType.StaticAttachment,
Hints = new List<string>(),
Hints = [],
IsEnabled = true,
SubmissionLimit = 0, // No submission limit
DeadlineUtc = DateTimeOffset.UtcNow.AddMinutes(-5), // Deadline 5 minutes ago
Expand Down Expand Up @@ -375,7 +375,7 @@ public async Task ChallengeDisabling_ShouldUpdateScoreboard()
Content = "Challenge to toggle",
Category = ChallengeCategory.Misc,
Type = ChallengeType.StaticAttachment,
Hints = new List<string>(),
Hints = [],
IsEnabled = true,
SubmissionLimit = 0,
OriginalScore = 200,
Expand Down Expand Up @@ -565,7 +565,7 @@ public async Task ChallengeReEnabling_ShouldRestoreChallengeAvailability()
Content = "Challenge to re-enable",
Category = ChallengeCategory.Misc,
Type = ChallengeType.StaticAttachment,
Hints = new List<string>(),
Hints = [],
IsEnabled = true,
SubmissionLimit = 0,
OriginalScore = 150,
Expand Down
Loading