mirror of
https://github.com/bitwarden/server.git
synced 2025-05-08 13:12:16 -05:00
Wire up automatic test
This commit is contained in:
parent
92553822f0
commit
a4418bb775
@ -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<ApiApplicationFactory>, 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<ListResponseModel<OrganizationUserUserDetailsResponseModel>>();
|
||||||
|
// Assert.NotNull(result?.Data);
|
||||||
|
// Assert.Equal(600001, result.Data.Count());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Api\Api.csproj" />
|
<ProjectReference Include="..\..\src\Api\Api.csproj" />
|
||||||
|
<ProjectReference Include="..\..\util\Seeder\Seeder.csproj" />
|
||||||
<ProjectReference Include="..\IntegrationTestCommon\IntegrationTestCommon.csproj" />
|
<ProjectReference Include="..\IntegrationTestCommon\IntegrationTestCommon.csproj" />
|
||||||
|
|
||||||
<Content Include="..\..\src\Api\appsettings.*.json">
|
<Content Include="..\..\src\Api\appsettings.*.json">
|
||||||
|
@ -7,7 +7,7 @@ namespace Bit.Seeder.Recipes;
|
|||||||
|
|
||||||
public class OrganizationWithUsersRecipe(DatabaseContext db)
|
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 organization = OrganizationSeeder.CreateEnterprise(name, domain, users);
|
||||||
var user = UserSeeder.CreateUser($"admin@{domain}");
|
var user = UserSeeder.CreateUser($"admin@{domain}");
|
||||||
@ -31,5 +31,7 @@ public class OrganizationWithUsersRecipe(DatabaseContext db)
|
|||||||
// Use LinqToDB's BulkCopy for significant better performance
|
// Use LinqToDB's BulkCopy for significant better performance
|
||||||
db.BulkCopy(additionalUsers);
|
db.BulkCopy(additionalUsers);
|
||||||
db.BulkCopy(additionalOrgUsers);
|
db.BulkCopy(additionalOrgUsers);
|
||||||
|
|
||||||
|
return organization.Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user