From 3d564e7658860c91b8b1d0dba62f974cf7b53339 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 26 Mar 2025 14:08:29 +1000 Subject: [PATCH] Add integration test --- .../OrganizationUsersControllerTests.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/Api.IntegrationTest/AdminConsole/Authorization/OrganizationUsersControllerTests.cs diff --git a/test/Api.IntegrationTest/AdminConsole/Authorization/OrganizationUsersControllerTests.cs b/test/Api.IntegrationTest/AdminConsole/Authorization/OrganizationUsersControllerTests.cs new file mode 100644 index 0000000000..fc1a578b3f --- /dev/null +++ b/test/Api.IntegrationTest/AdminConsole/Authorization/OrganizationUsersControllerTests.cs @@ -0,0 +1,66 @@ +using System.Net; +using Bit.Api.IntegrationTest.Factories; +using Bit.Api.IntegrationTest.Helpers; +using Bit.Core.AdminConsole.Entities; +using Bit.Core.Billing.Enums; +using Bit.Core.Entities; +using Bit.Core.Enums; +using Xunit; + +namespace Bit.Api.IntegrationTest.AdminConsole.Authorization; + +public class OrganizationUsersControllerTests : IClassFixture, IAsyncLifetime +{ + private readonly HttpClient _client; + private readonly ApiApplicationFactory _factory; + private readonly LoginHelper _loginHelper; + + // These will get set in `InitializeAsync` which is run before all tests + private Organization _organization = null!; + private OrganizationUser _organizationUser = null!; + private string _ownerEmail = null!; + + public OrganizationUsersControllerTests(ApiApplicationFactory factory) + { + _factory = factory; + _client = factory.CreateClient(); + _loginHelper = new LoginHelper(_factory, _client); + } + + public async Task InitializeAsync() + { + // Create the owner account + _ownerEmail = $"integration-test{Guid.NewGuid()}@bitwarden.com"; + await _factory.LoginWithNewAccount(_ownerEmail); + + // Create the organization + (_organization, _organizationUser) = await OrganizationTestHelpers.SignUpAsync(_factory, plan: PlanType.EnterpriseAnnually2023, + ownerEmail: _ownerEmail, passwordManagerSeats: 10, paymentMethod: PaymentMethodType.Card); + + // Login as the user + await _loginHelper.LoginAsync(_ownerEmail); + } + + public Task DisposeAsync() + { + _client.Dispose(); + return Task.CompletedTask; + } + + [Fact] + public async Task GetMiniDetails_Authorization_Fail() + { + // Request is for a random organizationId not in their claims + var organizationId = Guid.NewGuid(); + var response = await _client.GetAsync($"/organizations/{organizationId}/users/mini-details"); + Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); + } + + [Fact] + public async Task GetMiniDetails_Authorization_Success() + { + // Request is for their organization + var response = await _client.GetAsync($"/organizations/{_organization.Id}/users/mini-details"); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } +}