-
Notifications
You must be signed in to change notification settings - Fork 124
Open
Description
Faced with the issue when due to the overriding configuration ConfigurationFeatureDefinitionProvider will falsely enable a feature flag.
Example setup:
appsettings.json
{
"FeatureManagement":{
"FeatureA": {
"RequirementType": "All",
"EnabledFor": [{
"Name":"AlwaysOn"
}]
}
}
}Overriden by production configuration:
appsettings.production.json
{
"FeatureManagement:FeatureA": "False" // Disable feature
}That produces the following configuration key-values pairs:
["FeatureManagement:FeatureA"] = "False",
["FeatureManagement:FeatureA:RequirementType"] = "All",
["FeatureManagement:FeatureA:EnabledFor:0:Name"] = "AlwaysOn"
Expected result: feature manager returns False for IsEnabledAsync("FeatureA")
Test example:
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FeatureManagement;
namespace TestProject
{
public class Tests
{
[Test]
public async Task FeatureWithDirectValueMustBeDisabled()
{
var configKeys = new Dictionary<string, string?>
{
["FeatureManagement:FeatureA"] = "False",
["FeatureManagement:FeatureA:RequirementType"] = "All",
["FeatureManagement:FeatureA:EnabledFor:0:Name"] = "AlwaysOn"
};
var cfg = new ConfigurationBuilder()
.AddInMemoryCollection(configKeys)
.Build();
var sc = new ServiceCollection();
sc.AddFeatureManagement();
sc.AddSingleton<IConfiguration>(cfg);
var serviceProvider = sc.BuildServiceProvider();
var featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
var featureState = await featureManager.IsEnabledAsync("FeatureA");
Assert.IsFalse(featureState, "FeatureA must be disabled as it's Value is False");
}
}
}Actual result:: featureManager.IsEnabledAsync("FeatureA") returns True
Root cause: ConfigurationFeatureDefinitionProvider doesn't distinguish if there is an actual False value set or value can't be parsed in the method ParseDotnetSchemaFeatureDefinition:
61: if (!string.IsNullOrEmpty(val) && bool.TryParse(val, out bool result) && result)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels