diff --git a/test/Api.IntegrationTest/AdminConsole/Controllers/OrganizationUsersControllerTests.cs b/test/Api.IntegrationTest/AdminConsole/Controllers/OrganizationUsersControllerTests.cs new file mode 100644 index 0000000000..dcb270b7bc --- /dev/null +++ b/test/Api.IntegrationTest/AdminConsole/Controllers/OrganizationUsersControllerTests.cs @@ -0,0 +1,84 @@ +using System.Net; +using System.Net.Http.Headers; +using Bit.Api.IntegrationTest.Factories; +using Bit.Seeder.Recipes; +using Xunit; +using Xunit.Abstractions; + +namespace Bit.Api.IntegrationTest.AdminConsole.Controllers; + +public class OrganizationUsersControllerTest : IClassFixture, IAsyncLifetime +{ + private readonly HttpClient _client; + private readonly ApiApplicationFactory _factory; + private readonly ITestOutputHelper _testOutputHelper; + + public OrganizationUsersControllerTest(ApiApplicationFactory factory, ITestOutputHelper testOutputHelper) + { + _factory = factory; + _testOutputHelper = testOutputHelper; + _client = _factory.CreateClient(); + } + + public Task InitializeAsync() + { + return Task.CompletedTask; + } + + public Task DisposeAsync() + { + _client.Dispose(); + return Task.CompletedTask; + } + + [Fact] + public async Task Get_SmallOrg() + { + var db = _factory.GetDatabaseContext(); + var seeder = new OrganizationWithUsersRecipe(db); + + var orgId = seeder.Seed("Org", 100, "large.test"); + + var tokens = await _factory.LoginAsync("admin@large.test", "c55hlJ/cfdvTd4awTXUqow6X3cOQCfGwn11o3HblnPs="); + _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token); + + var stopwatch = System.Diagnostics.Stopwatch.StartNew(); + + var response = await _client.GetAsync($"/organizations/{orgId}/users?includeCollections=true"); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + var result = await response.Content.ReadAsStringAsync(); + Assert.NotEmpty(result); + + stopwatch.Stop(); + _testOutputHelper.WriteLine($"Request duration: {stopwatch.ElapsedMilliseconds} ms"); + } + + [Fact] + public async Task Get_LargeOrg() + { + var db = _factory.GetDatabaseContext(); + var seeder = new OrganizationWithUsersRecipe(db); + + var orgId = seeder.Seed("Org", 60000, "large.test"); + + var tokens = await _factory.LoginAsync("admin@large.test", "c55hlJ/cfdvTd4awTXUqow6X3cOQCfGwn11o3HblnPs="); + _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token); + + var stopwatch = System.Diagnostics.Stopwatch.StartNew(); + + var response = await _client.GetAsync($"/organizations/{orgId}/users?includeCollections=true"); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + var result = await response.Content.ReadAsStringAsync(); + Assert.NotEmpty(result); + + stopwatch.Stop(); + _testOutputHelper.WriteLine($"Request duration: {stopwatch.ElapsedMilliseconds} ms"); + + // var result = await response.Content.ReadFromJsonAsync>(); + // Assert.NotNull(result?.Data); + // Assert.Equal(600001, result.Data.Count()); + } + +} diff --git a/test/Api.IntegrationTest/Api.IntegrationTest.csproj b/test/Api.IntegrationTest/Api.IntegrationTest.csproj index 8fa74f98d4..a9d7fd502e 100644 --- a/test/Api.IntegrationTest/Api.IntegrationTest.csproj +++ b/test/Api.IntegrationTest/Api.IntegrationTest.csproj @@ -18,6 +18,7 @@ + diff --git a/util/Seeder/Recipes/OrganizationWithUsersRecipe.cs b/util/Seeder/Recipes/OrganizationWithUsersRecipe.cs index 0b9dd44a26..fb06c091ae 100644 --- a/util/Seeder/Recipes/OrganizationWithUsersRecipe.cs +++ b/util/Seeder/Recipes/OrganizationWithUsersRecipe.cs @@ -7,7 +7,7 @@ namespace Bit.Seeder.Recipes; public class OrganizationWithUsersRecipe(DatabaseContext db) { - public void Seed(string name, int users, string domain) + public Guid Seed(string name, int users, string domain) { var organization = OrganizationSeeder.CreateEnterprise(name, domain, users); var user = UserSeeder.CreateUser($"admin@{domain}"); @@ -31,5 +31,7 @@ public class OrganizationWithUsersRecipe(DatabaseContext db) // Use LinqToDB's BulkCopy for significant better performance db.BulkCopy(additionalUsers); db.BulkCopy(additionalOrgUsers); + + return organization.Id; } }