2023-03-15 16:51:01 +01:00
|
|
|
|
using System.Net;
|
|
|
|
|
using Bit.Api.IntegrationTest.Factories;
|
2024-03-29 17:00:30 +01:00
|
|
|
|
using Bit.Api.IntegrationTest.SecretsManager.Helpers;
|
2023-03-15 16:51:01 +01:00
|
|
|
|
using Bit.Api.SecretsManager.Models.Request;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.IntegrationTest.SecretsManager.Controllers;
|
|
|
|
|
|
2023-03-22 16:04:50 +01:00
|
|
|
|
public class SecretsManagerPortingControllerTests : IClassFixture<ApiApplicationFactory>, IAsyncLifetime
|
2023-03-15 16:51:01 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly HttpClient _client;
|
|
|
|
|
private readonly ApiApplicationFactory _factory;
|
2024-03-29 17:00:30 +01:00
|
|
|
|
private readonly LoginHelper _loginHelper;
|
2023-03-15 16:51:01 +01:00
|
|
|
|
|
|
|
|
|
private string _email = null!;
|
|
|
|
|
private SecretsManagerOrganizationHelper _organizationHelper = null!;
|
|
|
|
|
|
2023-03-22 16:04:50 +01:00
|
|
|
|
public SecretsManagerPortingControllerTests(ApiApplicationFactory factory)
|
2023-03-15 16:51:01 +01:00
|
|
|
|
{
|
|
|
|
|
_factory = factory;
|
|
|
|
|
_client = _factory.CreateClient();
|
2024-03-29 17:00:30 +01:00
|
|
|
|
_loginHelper = new LoginHelper(_factory, _client);
|
2023-03-15 16:51:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task InitializeAsync()
|
|
|
|
|
{
|
|
|
|
|
_email = $"integration-test{Guid.NewGuid()}@bitwarden.com";
|
|
|
|
|
await _factory.LoginWithNewAccount(_email);
|
|
|
|
|
_organizationHelper = new SecretsManagerOrganizationHelper(_factory, _email);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task DisposeAsync()
|
|
|
|
|
{
|
|
|
|
|
_client.Dispose();
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
2023-10-16 16:29:02 +02:00
|
|
|
|
[InlineData(false, false, false)]
|
|
|
|
|
[InlineData(false, false, true)]
|
|
|
|
|
[InlineData(false, true, false)]
|
|
|
|
|
[InlineData(false, true, true)]
|
|
|
|
|
[InlineData(true, false, false)]
|
|
|
|
|
[InlineData(true, false, true)]
|
|
|
|
|
[InlineData(true, true, false)]
|
|
|
|
|
public async Task Import_SmAccessDenied_NotFound(bool useSecrets, bool accessSecrets, bool organizationEnabled)
|
2023-03-15 16:51:01 +01:00
|
|
|
|
{
|
2023-10-16 16:29:02 +02:00
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets, organizationEnabled);
|
2024-03-29 17:00:30 +01:00
|
|
|
|
await _loginHelper.LoginAsync(_email);
|
2023-03-15 16:51:01 +01:00
|
|
|
|
|
|
|
|
|
var projectsList = new List<SMImportRequestModel.InnerProjectImportRequestModel>();
|
|
|
|
|
var secretsList = new List<SMImportRequestModel.InnerSecretImportRequestModel>();
|
|
|
|
|
var request = new SMImportRequestModel { Projects = projectsList, Secrets = secretsList };
|
|
|
|
|
|
|
|
|
|
var response = await _client.PostAsJsonAsync($"sm/{org.Id}/import", request);
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
2023-10-16 16:29:02 +02:00
|
|
|
|
[InlineData(false, false, false)]
|
|
|
|
|
[InlineData(false, false, true)]
|
|
|
|
|
[InlineData(false, true, false)]
|
|
|
|
|
[InlineData(false, true, true)]
|
|
|
|
|
[InlineData(true, false, false)]
|
|
|
|
|
[InlineData(true, false, true)]
|
|
|
|
|
[InlineData(true, true, false)]
|
|
|
|
|
public async Task Export_SmAccessDenied_NotFound(bool useSecrets, bool accessSecrets, bool organizationEnabled)
|
2023-03-15 16:51:01 +01:00
|
|
|
|
{
|
2023-10-16 16:29:02 +02:00
|
|
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets, organizationEnabled);
|
2024-03-29 17:00:30 +01:00
|
|
|
|
await _loginHelper.LoginAsync(_email);
|
2023-03-15 16:51:01 +01:00
|
|
|
|
|
|
|
|
|
var response = await _client.GetAsync($"sm/{org.Id}/export");
|
|
|
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
}
|