1
0
mirror of https://github.com/bitwarden/server synced 2026-02-08 20:50:13 +00:00

All feature state access through config API (#2785)

This commit is contained in:
Matt Bishop
2023-03-10 08:11:11 -05:00
committed by GitHub
parent efe7ae8d07
commit bd666841a5
8 changed files with 159 additions and 5 deletions

View File

@@ -0,0 +1,30 @@
using System.Net.Http.Headers;
using Bit.Api.IntegrationTest.Factories;
using Bit.Api.Models.Response;
using Xunit;
namespace Bit.Api.IntegrationTest.Controllers;
public class ConfigControllerTests : IClassFixture<ApiApplicationFactory>
{
private readonly ApiApplicationFactory _factory;
public ConfigControllerTests(ApiApplicationFactory factory) => _factory = factory;
[Fact]
public async Task GetConfigs()
{
var tokens = await _factory.LoginWithNewAccount();
var client = _factory.CreateClient();
using var message = new HttpRequestMessage(HttpMethod.Get, "/config");
message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.Token);
var response = await client.SendAsync(message);
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadFromJsonAsync<ConfigResponseModel>();
Assert.NotEmpty(content!.Version);
}
}

View File

@@ -0,0 +1,47 @@
using AutoFixture.Xunit2;
using Bit.Api.Controllers;
using Bit.Core.Context;
using Bit.Core.Services;
using Bit.Core.Settings;
using NSubstitute;
using Xunit;
namespace Bit.Api.Test.Controllers;
public class ConfigControllerTests : IDisposable
{
private readonly ConfigController _sut;
private readonly GlobalSettings _globalSettings;
private readonly IFeatureService _featureService;
private readonly ICurrentContext _currentContext;
public ConfigControllerTests()
{
_globalSettings = new GlobalSettings();
_currentContext = Substitute.For<ICurrentContext>();
_featureService = Substitute.For<IFeatureService>();
_sut = new ConfigController(
_globalSettings,
_currentContext,
_featureService
);
}
public void Dispose()
{
_sut?.Dispose();
}
[Theory, AutoData]
public void GetConfigs_WithFeatureStates(Dictionary<string, object> featureStates)
{
_featureService.GetAll(_currentContext).Returns(featureStates);
var response = _sut.GetConfigs();
Assert.NotNull(response);
Assert.NotNull(response.FeatureStates);
Assert.Equal(featureStates, response.FeatureStates);
}
}

View File

@@ -91,4 +91,18 @@ public class LaunchDarklyFeatureServiceTests
Assert.Null(sutProvider.Sut.GetStringVariation(FeatureFlagKeys.SecretsManager, currentContext));
}
[Fact(Skip = "For local development")]
public void GetAll()
{
var sutProvider = GetSutProvider(new Core.Settings.GlobalSettings());
var currentContext = Substitute.For<ICurrentContext>();
currentContext.UserId.Returns(Guid.NewGuid());
var results = sutProvider.Sut.GetAll(currentContext);
Assert.NotNull(results);
Assert.NotEmpty(results);
}
}