mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
Establish IFeatureService as scoped (#3679)
* Establish IFeatureService as scoped * Lint * Feedback around injection
This commit is contained in:
@ -14,7 +14,6 @@ using Bit.Core.Auth.Models.Api.Request.Accounts;
|
||||
using Bit.Core.Auth.Services;
|
||||
using Bit.Core.Auth.UserFeatures.UserKey;
|
||||
using Bit.Core.Auth.UserFeatures.UserMasterPassword.Interfaces;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
@ -54,7 +53,6 @@ public class AccountsControllerTests : IDisposable
|
||||
private readonly ISetInitialMasterPasswordCommand _setInitialMasterPasswordCommand;
|
||||
private readonly IRotateUserKeyCommand _rotateUserKeyCommand;
|
||||
private readonly IFeatureService _featureService;
|
||||
private readonly ICurrentContext _currentContext;
|
||||
|
||||
private readonly IRotationValidator<IEnumerable<CipherWithIdRequestModel>, IEnumerable<Cipher>> _cipherValidator;
|
||||
private readonly IRotationValidator<IEnumerable<FolderWithIdRequestModel>, IEnumerable<Folder>> _folderValidator;
|
||||
@ -84,7 +82,6 @@ public class AccountsControllerTests : IDisposable
|
||||
_setInitialMasterPasswordCommand = Substitute.For<ISetInitialMasterPasswordCommand>();
|
||||
_rotateUserKeyCommand = Substitute.For<IRotateUserKeyCommand>();
|
||||
_featureService = Substitute.For<IFeatureService>();
|
||||
_currentContext = Substitute.For<ICurrentContext>();
|
||||
_cipherValidator =
|
||||
Substitute.For<IRotationValidator<IEnumerable<CipherWithIdRequestModel>, IEnumerable<Cipher>>>();
|
||||
_folderValidator =
|
||||
@ -113,7 +110,6 @@ public class AccountsControllerTests : IDisposable
|
||||
_setInitialMasterPasswordCommand,
|
||||
_rotateUserKeyCommand,
|
||||
_featureService,
|
||||
_currentContext,
|
||||
_cipherValidator,
|
||||
_folderValidator,
|
||||
_sendValidator,
|
||||
|
@ -1,6 +1,5 @@
|
||||
using AutoFixture.Xunit2;
|
||||
using Bit.Api.Controllers;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
using NSubstitute;
|
||||
@ -13,17 +12,14 @@ 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
|
||||
);
|
||||
}
|
||||
@ -36,7 +32,7 @@ public class ConfigControllerTests : IDisposable
|
||||
[Theory, AutoData]
|
||||
public void GetConfigs_WithFeatureStates(Dictionary<string, object> featureStates)
|
||||
{
|
||||
_featureService.GetAll(_currentContext).Returns(featureStates);
|
||||
_featureService.GetAll().Returns(featureStates);
|
||||
|
||||
var response = _sut.GetConfigs();
|
||||
|
||||
|
@ -114,7 +114,7 @@ public class CollectionServiceTest
|
||||
collection.Id = default;
|
||||
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
|
||||
sutProvider.GetDependency<IFeatureService>()
|
||||
.IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1, Arg.Any<ICurrentContext>(), Arg.Any<bool>())
|
||||
.IsEnabled(FeatureFlagKeys.FlexibleCollectionsV1, Arg.Any<bool>())
|
||||
.Returns(true);
|
||||
organization.AllowAdminAccessToAllCollectionItems = false;
|
||||
|
||||
|
@ -4,6 +4,7 @@ using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using LaunchDarkly.Sdk.Server.Interfaces;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
@ -19,9 +20,16 @@ public class LaunchDarklyFeatureServiceTests
|
||||
{
|
||||
globalSettings.ProjectName = "LaunchDarkly Tests";
|
||||
|
||||
var currentContext = Substitute.For<ICurrentContext>();
|
||||
currentContext.UserId.Returns(Guid.NewGuid());
|
||||
|
||||
var client = Substitute.For<ILdClient>();
|
||||
|
||||
var fixture = new Fixture();
|
||||
return new SutProvider<LaunchDarklyFeatureService>(fixture)
|
||||
.SetDependency(globalSettings)
|
||||
.SetDependency(currentContext)
|
||||
.SetDependency(client)
|
||||
.Create();
|
||||
}
|
||||
|
||||
@ -30,10 +38,7 @@ public class LaunchDarklyFeatureServiceTests
|
||||
{
|
||||
var sutProvider = GetSutProvider(new Settings.GlobalSettings { SelfHosted = true });
|
||||
|
||||
var currentContext = Substitute.For<ICurrentContext>();
|
||||
currentContext.UserId.Returns(Guid.NewGuid());
|
||||
|
||||
Assert.False(sutProvider.Sut.IsEnabled(key, currentContext));
|
||||
Assert.False(sutProvider.Sut.IsEnabled(key));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -41,10 +46,7 @@ public class LaunchDarklyFeatureServiceTests
|
||||
{
|
||||
var sutProvider = GetSutProvider(new Settings.GlobalSettings());
|
||||
|
||||
var currentContext = Substitute.For<ICurrentContext>();
|
||||
currentContext.UserId.Returns(Guid.NewGuid());
|
||||
|
||||
Assert.False(sutProvider.Sut.IsEnabled(_fakeFeatureKey, currentContext));
|
||||
Assert.False(sutProvider.Sut.IsEnabled(_fakeFeatureKey));
|
||||
}
|
||||
|
||||
[Fact(Skip = "For local development")]
|
||||
@ -54,10 +56,7 @@ public class LaunchDarklyFeatureServiceTests
|
||||
|
||||
var sutProvider = GetSutProvider(settings);
|
||||
|
||||
var currentContext = Substitute.For<ICurrentContext>();
|
||||
currentContext.UserId.Returns(Guid.NewGuid());
|
||||
|
||||
Assert.False(sutProvider.Sut.IsEnabled(_fakeFeatureKey, currentContext));
|
||||
Assert.False(sutProvider.Sut.IsEnabled(_fakeFeatureKey));
|
||||
}
|
||||
|
||||
[Fact(Skip = "For local development")]
|
||||
@ -67,10 +66,7 @@ public class LaunchDarklyFeatureServiceTests
|
||||
|
||||
var sutProvider = GetSutProvider(settings);
|
||||
|
||||
var currentContext = Substitute.For<ICurrentContext>();
|
||||
currentContext.UserId.Returns(Guid.NewGuid());
|
||||
|
||||
Assert.Equal(0, sutProvider.Sut.GetIntVariation(_fakeFeatureKey, currentContext));
|
||||
Assert.Equal(0, sutProvider.Sut.GetIntVariation(_fakeFeatureKey));
|
||||
}
|
||||
|
||||
[Fact(Skip = "For local development")]
|
||||
@ -80,10 +76,7 @@ public class LaunchDarklyFeatureServiceTests
|
||||
|
||||
var sutProvider = GetSutProvider(settings);
|
||||
|
||||
var currentContext = Substitute.For<ICurrentContext>();
|
||||
currentContext.UserId.Returns(Guid.NewGuid());
|
||||
|
||||
Assert.Null(sutProvider.Sut.GetStringVariation(_fakeFeatureKey, currentContext));
|
||||
Assert.Null(sutProvider.Sut.GetStringVariation(_fakeFeatureKey));
|
||||
}
|
||||
|
||||
[Fact(Skip = "For local development")]
|
||||
@ -91,10 +84,7 @@ public class LaunchDarklyFeatureServiceTests
|
||||
{
|
||||
var sutProvider = GetSutProvider(new Settings.GlobalSettings());
|
||||
|
||||
var currentContext = Substitute.For<ICurrentContext>();
|
||||
currentContext.UserId.Returns(Guid.NewGuid());
|
||||
|
||||
var results = sutProvider.Sut.GetAll(currentContext);
|
||||
var results = sutProvider.Sut.GetAll();
|
||||
|
||||
Assert.NotNull(results);
|
||||
Assert.NotEmpty(results);
|
||||
|
@ -64,7 +64,7 @@ public class RequireFeatureAttributeTests
|
||||
var featureService = Substitute.For<IFeatureService>();
|
||||
var currentContext = Substitute.For<ICurrentContext>();
|
||||
|
||||
featureService.IsEnabled(_testFeature, Arg.Any<ICurrentContext>()).Returns(enabled);
|
||||
featureService.IsEnabled(_testFeature).Returns(enabled);
|
||||
|
||||
services.AddSingleton(featureService);
|
||||
services.AddSingleton(currentContext);
|
||||
|
Reference in New Issue
Block a user