mirror of
https://github.com/bitwarden/server.git
synced 2024-11-29 13:25:17 +01:00
53327b1993
* Warnings cleanup * One-line response with null Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> * Remove condition * Fix lint from suggestion --------- Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com>
77 lines
2.8 KiB
C#
77 lines
2.8 KiB
C#
using System.Net;
|
|
using System.Net.Http.Headers;
|
|
using Bit.Api.IntegrationTest.Factories;
|
|
using Bit.Api.SecretsManager.Models.Request;
|
|
using Bit.Core.SecretsManager.Repositories;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.IntegrationTest.SecretsManager.Controllers;
|
|
|
|
public class SecretsManagerPortingControllerTests : IClassFixture<ApiApplicationFactory>, IAsyncLifetime
|
|
{
|
|
private readonly HttpClient _client;
|
|
private readonly ApiApplicationFactory _factory;
|
|
private readonly IProjectRepository _projectRepository;
|
|
private readonly IAccessPolicyRepository _accessPolicyRepository;
|
|
|
|
private string _email = null!;
|
|
private SecretsManagerOrganizationHelper _organizationHelper = null!;
|
|
|
|
public SecretsManagerPortingControllerTests(ApiApplicationFactory factory)
|
|
{
|
|
_factory = factory;
|
|
_client = _factory.CreateClient();
|
|
_projectRepository = _factory.GetService<IProjectRepository>();
|
|
_accessPolicyRepository = _factory.GetService<IAccessPolicyRepository>();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
private async Task LoginAsync(string email)
|
|
{
|
|
var tokens = await _factory.LoginAsync(email);
|
|
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(false, false)]
|
|
[InlineData(true, false)]
|
|
[InlineData(false, true)]
|
|
public async Task Import_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
{
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
await LoginAsync(_email);
|
|
|
|
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]
|
|
[InlineData(false, false)]
|
|
[InlineData(true, false)]
|
|
[InlineData(false, true)]
|
|
public async Task Export_SmNotEnabled_NotFound(bool useSecrets, bool accessSecrets)
|
|
{
|
|
var (org, _) = await _organizationHelper.Initialize(useSecrets, accessSecrets);
|
|
await LoginAsync(_email);
|
|
|
|
var response = await _client.GetAsync($"sm/{org.Id}/export");
|
|
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
|
}
|
|
}
|