mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
[BEEEP][SM-893] Add the ability to run SM integration tests as a service account (#3187)
* Add the ability to run SM integration tests as a service account
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using Bit.Api.IntegrationTest.Factories;
|
||||
using Bit.Api.IntegrationTest.SecretsManager.Helpers;
|
||||
using Bit.Api.SecretsManager.Models.Response;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.SecretsManager.Repositories;
|
||||
@ -17,6 +17,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
private readonly HttpClient _client;
|
||||
private readonly ApiApplicationFactory _factory;
|
||||
private readonly ISecretRepository _secretRepository;
|
||||
private readonly LoginHelper _loginHelper;
|
||||
|
||||
private string _email = null!;
|
||||
private SecretsManagerOrganizationHelper _organizationHelper = null!;
|
||||
@ -26,6 +27,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
_factory = factory;
|
||||
_client = _factory.CreateClient();
|
||||
_secretRepository = _factory.GetService<ISecretRepository>();
|
||||
_loginHelper = new LoginHelper(_factory, _client);
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
@ -41,12 +43,6 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task LoginAsync(string email)
|
||||
{
|
||||
var tokens = await _factory.LoginAsync(email);
|
||||
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false, false, false)]
|
||||
[InlineData(false, false, true)]
|
||||
@ -58,7 +54,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
public async Task ListByOrganization_SmAccessDenied_NotFound(bool useSecrets, bool accessSecrets, bool organizationEnabled)
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets, organizationEnabled);
|
||||
await LoginAsync(_email);
|
||||
await _loginHelper.LoginAsync(_email);
|
||||
|
||||
var response = await _client.GetAsync($"/secrets/{org.Id}/trash");
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
@ -69,7 +65,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(true, true, true);
|
||||
var (email, _) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
||||
await LoginAsync(email);
|
||||
await _loginHelper.LoginAsync(email);
|
||||
|
||||
var response = await _client.GetAsync($"/secrets/{org.Id}/trash");
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||
@ -79,7 +75,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
public async Task ListByOrganization_Success()
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(true, true, true);
|
||||
await LoginAsync(_email);
|
||||
await _loginHelper.LoginAsync(_email);
|
||||
|
||||
await _secretRepository.CreateAsync(new Secret
|
||||
{
|
||||
@ -114,7 +110,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
public async Task Empty_SmAccessDenied_NotFound(bool useSecrets, bool accessSecrets, bool organizationEnabled)
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets, organizationEnabled);
|
||||
await LoginAsync(_email);
|
||||
await _loginHelper.LoginAsync(_email);
|
||||
|
||||
var ids = new List<Guid> { Guid.NewGuid() };
|
||||
var response = await _client.PostAsJsonAsync($"/secrets/{org.Id}/trash/empty", ids);
|
||||
@ -126,7 +122,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(true, true, true);
|
||||
var (email, _) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
||||
await LoginAsync(email);
|
||||
await _loginHelper.LoginAsync(email);
|
||||
|
||||
var ids = new List<Guid> { Guid.NewGuid() };
|
||||
var response = await _client.PostAsJsonAsync($"/secrets/{org.Id}/trash/empty", ids);
|
||||
@ -137,7 +133,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
public async Task Empty_Invalid_NotFound()
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(true, true, true);
|
||||
await LoginAsync(_email);
|
||||
await _loginHelper.LoginAsync(_email);
|
||||
|
||||
var secret = await _secretRepository.CreateAsync(new Secret
|
||||
{
|
||||
@ -155,7 +151,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
public async Task Empty_Success()
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(true, true, true);
|
||||
await LoginAsync(_email);
|
||||
await _loginHelper.LoginAsync(_email);
|
||||
|
||||
var secret = await _secretRepository.CreateAsync(new Secret
|
||||
{
|
||||
@ -181,7 +177,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
public async Task Restore_SmAccessDenied_NotFound(bool useSecrets, bool accessSecrets, bool organizationEnabled)
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets, organizationEnabled);
|
||||
await LoginAsync(_email);
|
||||
await _loginHelper.LoginAsync(_email);
|
||||
|
||||
var ids = new List<Guid> { Guid.NewGuid() };
|
||||
var response = await _client.PostAsJsonAsync($"/secrets/{org.Id}/trash/restore", ids);
|
||||
@ -193,7 +189,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(true, true, true);
|
||||
var (email, _) = await _organizationHelper.CreateNewUser(OrganizationUserType.User, true);
|
||||
await LoginAsync(email);
|
||||
await _loginHelper.LoginAsync(email);
|
||||
|
||||
var ids = new List<Guid> { Guid.NewGuid() };
|
||||
var response = await _client.PostAsJsonAsync($"/secrets/{org.Id}/trash/restore", ids);
|
||||
@ -204,7 +200,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
public async Task Restore_Invalid_NotFound()
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(true, true, true);
|
||||
await LoginAsync(_email);
|
||||
await _loginHelper.LoginAsync(_email);
|
||||
|
||||
var secret = await _secretRepository.CreateAsync(new Secret
|
||||
{
|
||||
@ -222,7 +218,7 @@ public class SecretsTrashControllerTests : IClassFixture<ApiApplicationFactory>,
|
||||
public async Task Restore_Success()
|
||||
{
|
||||
var (org, _) = await _organizationHelper.Initialize(true, true, true);
|
||||
await LoginAsync(_email);
|
||||
await _loginHelper.LoginAsync(_email);
|
||||
|
||||
var secret = await _secretRepository.CreateAsync(new Secret
|
||||
{
|
||||
|
Reference in New Issue
Block a user