microsoft / microsoft/FeatureManagement-Dotnet
ConfigurationFeatureDefinitionProvider ignores False when there are exists RequirementType
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 129
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 5
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)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ParseDotnetSchemaFeatureDefinition, the method identified in the issue, and reproduce the supplied configuration with the test example. Verify how the direct FeatureManagement:FeatureA value is parsed when RequirementType and EnabledFor entries also exist; done means IsEnabledAsync("FeatureA") returns false and the regression test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100