mirror of
https://github.com/bitwarden/server.git
synced 2025-07-30 22:16:53 -05:00
.checkmarx
.config
.devcontainer
.git-hooks
.github
.run
.vscode
bitwarden_license
dev
perf
scripts
src
test
Admin.Test
Api.IntegrationTest
Controllers
AccountsControllerTest.cs
ConfigControllerTests.cs
Factories
Helpers
Properties
SecretsManager
Api.IntegrationTest.csproj
Api.Test
Billing.Test
Common
Core.Test
Events.Test
EventsProcessor.Test
Icons.Test
Identity.IntegrationTest
Identity.Test
Infrastructure.EFIntegration.Test
Infrastructure.IntegrationTest
IntegrationTestCommon
Notifications.Test
bitwarden.tests.sln
util
.dockerignore
.editorconfig
.git-blame-ignore-revs
.gitattributes
.gitignore
CONTRIBUTING.md
Directory.Build.props
LICENSE.txt
LICENSE_AGPL.txt
LICENSE_BITWARDEN.txt
LICENSE_FAQ.md
README.md
SECURITY.md
TRADEMARK_GUIDELINES.md
bitwarden-server.sln
global.json
95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
using System.Net.Http.Headers;
|
|
using Bit.Api.IntegrationTest.Factories;
|
|
using Bit.Api.IntegrationTest.Helpers;
|
|
using Bit.Api.Models.Response;
|
|
using Bit.Core.AdminConsole.Entities;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.IntegrationTest.Controllers;
|
|
|
|
public class ConfigControllerTests : IClassFixture<ApiApplicationFactory>, IAsyncLifetime
|
|
{
|
|
private readonly HttpClient _client;
|
|
private readonly ApiApplicationFactory _factory;
|
|
|
|
private string _email = null!;
|
|
|
|
public ConfigControllerTests(ApiApplicationFactory factory)
|
|
{
|
|
_factory = factory;
|
|
_client = _factory.CreateClient();
|
|
}
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
_email = $"integration-test{Guid.NewGuid()}@bitwarden.com";
|
|
|
|
var tokens = await _factory.LoginWithNewAccount(_email);
|
|
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token);
|
|
}
|
|
|
|
public Task DisposeAsync()
|
|
{
|
|
_client.Dispose();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private async Task LoginAsync()
|
|
{
|
|
var tokens = await _factory.LoginAsync(_email);
|
|
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetConfigs_Unauthenticated()
|
|
{
|
|
_client.DefaultRequestHeaders.Authorization = null;
|
|
|
|
var response = await _client.GetAsync("/config");
|
|
response.EnsureSuccessStatusCode();
|
|
var result = await response.Content.ReadFromJsonAsync<ConfigResponseModel>();
|
|
|
|
Assert.NotNull(result);
|
|
Assert.NotEmpty(result!.Version);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetConfigs_Authenticated()
|
|
{
|
|
await LoginAsync();
|
|
|
|
var response = await _client.GetAsync("/config");
|
|
response.EnsureSuccessStatusCode();
|
|
var result = await response.Content.ReadFromJsonAsync<ConfigResponseModel>();
|
|
|
|
Assert.NotNull(result);
|
|
Assert.NotEmpty(result!.Version);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(1)]
|
|
[InlineData(3)]
|
|
public async Task GetConfigs_WithOrganizations(int orgCount)
|
|
{
|
|
for (var i = 0; i < orgCount; i++)
|
|
{
|
|
var ownerEmail = $"integration-test{Guid.NewGuid()}@bitwarden.com";
|
|
await _factory.LoginWithNewAccount(ownerEmail);
|
|
|
|
Organization org;
|
|
(org, _) = await OrganizationTestHelpers.SignUpAsync(_factory, plan: Core.Enums.PlanType.Free, ownerEmail: ownerEmail,
|
|
name: i.ToString(), billingEmail: ownerEmail, ownerKey: i.ToString());
|
|
await OrganizationTestHelpers.CreateUserAsync(_factory, org.Id, _email, Core.Enums.OrganizationUserType.User);
|
|
}
|
|
|
|
await LoginAsync();
|
|
|
|
var response = await _client.GetAsync("/config");
|
|
response.EnsureSuccessStatusCode();
|
|
var result = await response.Content.ReadFromJsonAsync<ConfigResponseModel>();
|
|
|
|
Assert.NotNull(result);
|
|
Assert.NotEmpty(result!.Version);
|
|
}
|
|
}
|