From 5382670baafd10a028830dd911c04a9b1f628ed9 Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Sun, 22 Nov 2026 12:16:17 +0000 Subject: [PATCH] fix: keep server-only flags out of protocol-v2 bootstrap --- .../ExampleAppTests.cs | 8 +- .../Internal/FlagSecretJsonConverter.cs | 19 ++ src/Reflag/Internal/PreparedFlagCollection.cs | 1 + src/Reflag/ReflagClient.cs | 38 ++- src/Reflag/ReflagFlagModels.cs | 5 + tests/Reflag.Tests/BootstrapPrivacyTests.cs | 227 ++++++++++++++++++ .../EvaluationDiagnosticsTelemetryTests.cs | 3 +- .../JsonValueSerializationTests.cs | 34 ++- tests/Reflag.Tests/ReflagClientTests.cs | 9 +- tests/Reflag.Tests/ReflagEndToEndTests.cs | 3 + tests/Reflag.Tests/StartupOverridesTests.cs | 9 +- tests/Reflag.Tests/TestDoubles.cs | 3 + 12 files changed, 325 insertions(+), 34 deletions(-) create mode 100644 src/Reflag/Internal/FlagSecretJsonConverter.cs create mode 100644 tests/Reflag.Tests/BootstrapPrivacyTests.cs diff --git a/examples/Reflag.MinimalApiExample.Tests/ExampleAppTests.cs b/examples/Reflag.MinimalApiExample.Tests/ExampleAppTests.cs index b04dd28..80456e7 100644 --- a/examples/Reflag.MinimalApiExample.Tests/ExampleAppTests.cs +++ b/examples/Reflag.MinimalApiExample.Tests/ExampleAppTests.cs @@ -58,7 +58,7 @@ public async Task FlagsEndpointCanBeToggledInTestsWithPushFlagOverrides() [Theory] [InlineData("new-dashboard", true)] [InlineData("demo-flag", false)] - public async Task BootstrapEndpointReflectsScopedOverrideValues(string key, bool expected) + public async Task BootstrapEndpointOmitsUnclassifiedOfflineOverrides(string key, bool expected) { await using var harness = await ExampleAppHarness.StartAsync(); var reflagClient = harness.App.Services.GetRequiredService(); @@ -72,10 +72,8 @@ public async Task BootstrapEndpointReflectsScopedOverrideValues(string key, bool Assert.Equal(2, bootstrapped.RootElement.GetProperty("protocolVersion").GetInt32()); Assert.Equal("test-user", bootstrapped.RootElement.GetProperty("context").GetProperty("user").GetProperty("id").GetString()); - var flag = bootstrapped.RootElement.GetProperty("flags").GetProperty(key); - Assert.Equal(expected, flag.GetProperty("value").GetBoolean()); - // Overrides are not authored selections. - Assert.False(flag.GetProperty("resolved").GetBoolean()); + Assert.Empty(bootstrapped.RootElement.GetProperty("flags").EnumerateObject()); + Assert.Equal(expected, reflagClient.GetFlag(key, new ReflagContext(), new ReflagTelemetryOptions { EnableTelemetry = false })); } [Fact] diff --git a/src/Reflag/Internal/FlagSecretJsonConverter.cs b/src/Reflag/Internal/FlagSecretJsonConverter.cs new file mode 100644 index 0000000..517f62d --- /dev/null +++ b/src/Reflag/Internal/FlagSecretJsonConverter.cs @@ -0,0 +1,19 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Reflag.Internal; + +/// Only an explicit JSON false permits a flag to leave the server. +internal sealed class FlagSecretJsonConverter : JsonConverter +{ + public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + using var value = JsonDocument.ParseValue(ref reader); + return value.RootElement.ValueKind != JsonValueKind.False; + } + + public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) + { + writer.WriteBooleanValue(value); + } +} diff --git a/src/Reflag/Internal/PreparedFlagCollection.cs b/src/Reflag/Internal/PreparedFlagCollection.cs index fb40474..cb1e873 100644 --- a/src/Reflag/Internal/PreparedFlagCollection.cs +++ b/src/Reflag/Internal/PreparedFlagCollection.cs @@ -61,6 +61,7 @@ rule is not null && copiedFlags.Add(new FlagDefinition { Key = flag.Key, + Secret = flag.Secret, SourceVersionId = flag.SourceVersionId, // Detach variant values from any caller-owned JsonDocument. Variants = new System.Collections.ObjectModel.ReadOnlyDictionary( diff --git a/src/Reflag/ReflagClient.cs b/src/Reflag/ReflagClient.cs index 25bf6c6..37f7384 100644 --- a/src/Reflag/ReflagClient.cs +++ b/src/Reflag/ReflagClient.cs @@ -257,8 +257,9 @@ public T GetFlag( } /// - /// Evaluates all flags for a client SDK bootstrap payload (protocol v2). Serialization is not a read, - /// so no check events are registered. + /// Evaluates public flags for a client SDK bootstrap payload (protocol v2). Secret dependencies stay + /// available for evaluation but are not exported. Missing visibility metadata is server-only. + /// Serialization is not a read, so no check events are registered. /// public ReflagBootstrappedFlags GetFlagsForBootstrap( ReflagContext context, @@ -269,10 +270,36 @@ public ReflagBootstrappedFlags GetFlagsForBootstrap( var normalizedTelemetry = NormalizeTelemetryOptions(telemetryOptions); var evaluation = EvaluateFlags(normalizedContext, normalizedTelemetry, null); + // An override callback can refresh the cache; visibility must belong to the evaluated snapshot. + var publicKeys = new HashSet( + evaluation.Collection?.Definitions.Flags.Where(flag => !flag.Secret).Select(flag => flag.Key) + ?? Enumerable.Empty(), + StringComparer.Ordinal); return new ReflagBootstrappedFlags { Context = normalizedContext, - Flags = evaluation.Flags, + Flags = evaluation.Flags.Where(pair => publicKeys.Contains(pair.Key)).ToDictionary( + pair => pair.Key, + pair => new RawReflagFlag + { + FlagKey = pair.Value.FlagKey, + Value = pair.Value.Value, + Resolved = pair.Value.Resolved, + SourceVersionId = pair.Value.SourceVersionId, + VariantKey = pair.Value.VariantKey, + MatchedRuleId = pair.Value.MatchedRuleId, + AllocationIndex = pair.Value.AllocationIndex, + RuleResults = pair.Value.RuleResults, + // Dependency origins may name private flags or segments. + Errors = pair.Value.Errors.Select(error => new ReflagEvaluationError + { + Code = error.Code, + Message = error.Message, + Field = error.Field, + Operator = error.Operator, + }).ToArray(), + }, + StringComparer.Ordinal), FlagStateVersion = evaluation.FlagStateVersion, }; } @@ -747,7 +774,7 @@ private FlagsEvaluation EvaluateFlags( flags[key] = LocalResult(key, null); } - return new FlagsEvaluation(flags, snapshot?.FlagStateVersion, evaluatedBeforeInitialization); + return new FlagsEvaluation(flags, snapshot?.FlagStateVersion, evaluatedBeforeInitialization, collection); } private static RawReflagFlag LocalResult(string key, JsonElement? value) @@ -1549,7 +1576,8 @@ private sealed record FeatureFlagEventBulkItem : BulkItem private sealed record FlagsEvaluation( Dictionary Flags, int? FlagStateVersion, - bool EvaluatedBeforeInitialization); + bool EvaluatedBeforeInitialization, + PreparedFlagCollection? Collection); private sealed class FlagOverrideScope(ReflagClient client, int layerId) : IDisposable { diff --git a/src/Reflag/ReflagFlagModels.cs b/src/Reflag/ReflagFlagModels.cs index 0c7ee8d..186e129 100644 --- a/src/Reflag/ReflagFlagModels.cs +++ b/src/Reflag/ReflagFlagModels.cs @@ -144,6 +144,11 @@ public sealed class FlagDefinition [JsonRequired] public string Key { get; init; } = string.Empty; + /// Server-only unless the definition explicitly declares secret: false. + [JsonPropertyName("secret")] + [JsonConverter(typeof(FlagSecretJsonConverter))] + public bool Secret { get; init; } = true; + /// Identifies the published flag version that produced this definition. [JsonPropertyName("sourceVersionId")] [JsonRequired] diff --git a/tests/Reflag.Tests/BootstrapPrivacyTests.cs b/tests/Reflag.Tests/BootstrapPrivacyTests.cs new file mode 100644 index 0000000..42f6c52 --- /dev/null +++ b/tests/Reflag.Tests/BootstrapPrivacyTests.cs @@ -0,0 +1,227 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using Xunit; + +namespace Reflag.Tests; + +public sealed class BootstrapPrivacyTests +{ + private static readonly ReflagContext Context = new() { User = new ReflagUserContext { Id = "synthetic-user" } }; + private static readonly ReflagTelemetryOptions Quiet = new() { EnableTelemetry = false }; + + [Theory] + [InlineData(null, false)] + [InlineData("false", true)] + [InlineData("true", false)] + [InlineData("null", false)] + [InlineData("0", false)] + [InlineData("1", false)] + [InlineData("\"false\"", false)] + [InlineData("{}", false)] + [InlineData("[]", false)] + public async Task Bootstrap_requires_explicit_public_visibility(string? secret, bool expectedPublic) + { + var flag = TestDefinitions.CreateMultivariateFlag("flag", "on", new Dictionary + { + ["on"] = new { marker = "synthetic-server-only" }, + }); + var body = JsonNode.Parse(TestDefinitions.FlagsResponse(1, flag))!; + var definition = body["flags"]![0]!.AsObject(); + definition.Remove("secret"); + if (secret is not null) + { + definition["secret"] = JsonNode.Parse(secret); + } + + var transport = new TestTransport(); + transport.EnqueueGetJson(body.ToJsonString()); + await using var client = new ReflagClient(Options(transport)); + await client.InitializeAsync(); + var bootstrap = client.BindClient(Context, Quiet).GetFlagsForBootstrap(); + Assert.Equal(expectedPublic, bootstrap.Flags.ContainsKey("flag")); + Assert.Equal(1, bootstrap.FlagStateVersion); + Assert.Equal("synthetic-server-only", client.GetFlag("flag", Context, default, Quiet).GetProperty("marker").GetString()); + Assert.Empty(transport.PostCalls); + } + + [Fact] + public async Task Overrides_do_not_publish_private_or_unknown_keys_and_private_dependencies_still_work() + { + var privateFlag = TestDefinitions.CreateMultivariateFlag("private", "on", new Dictionary { ["on"] = new { marker = "private" } }); + var publicFlag = TestDefinitions.CreateFlag("public", 1, new FlagReferenceFilterDefinition { Key = "private", VariantKey = "on" }); + var transport = new TestTransport(); + transport.EnqueueGetJson(Response((publicFlag, false), (privateFlag, true))); + await using var client = new ReflagClient(Options(transport)); + await client.InitializeAsync(); + Assert.True(client.GetFlagsForBootstrap(Context, Quiet).Flags["public"].Value!.Value.GetBoolean()); + client.SetFlagOverrides(new Dictionary + { + ["public"] = new { visible = true }, + ["private"] = "still-private", + ["override-only"] = true, + }); + var bootstrap = client.GetFlagsForBootstrap(Context, Quiet); + var flag = Assert.Single(bootstrap.Flags).Value; + Assert.Equal("public", flag.FlagKey); + Assert.True(flag.Value!.Value.GetProperty("visible").GetBoolean()); + Assert.False(flag.Resolved); + Assert.Null(flag.SourceVersionId); + Assert.Null(flag.VariantKey); + Assert.Equal("still-private", client.GetFlag("private", Context, "", Quiet)); + Assert.True(client.GetFlag("override-only", Context, Quiet)); + } + + [Theory] + [InlineData("flag")] + [InlineData("segment")] + public async Task Bootstrap_redacts_dependency_sources_without_changing_server_checks(string kind) + { + var condition = new FlagContextFilterDefinition { Field = "company.plan", Operator = FlagContextFilterOperator.Is, Values = ["pro"] }; + var privateFlag = TestDefinitions.CreateFlag("private-dependency", 1, condition); + FlagFilterDefinition reference = kind == "flag" + ? new FlagReferenceFilterDefinition { Key = "private-dependency", VariantKey = "on" } + : new SegmentReferenceFilterDefinition { Key = "private-dependency" }; + var publicFlag = TestDefinitions.CreateFlag("public", 1, reference); + var body = JsonNode.Parse(Response((publicFlag, false), (privateFlag, true)))!; + if (kind == "segment") + { + body["segments"] = JsonSerializer.SerializeToNode(new[] { new SegmentDefinition { Key = "private-dependency", Filter = condition } }, Reflag.Internal.ReflagJson.Options); + } + + var transport = new TestTransport(); + transport.EnqueueGetJson(body.ToJsonString()); + await using var client = new ReflagClient(Options(transport)); + await client.InitializeAsync(); + var bootstrap = client.GetFlagsForBootstrap(new ReflagContext(), Quiet); + var error = Assert.Single(Assert.Single(bootstrap.Flags).Value.Errors); + Assert.Equal("MISSING_CONTEXT_FIELD", error.Code); + Assert.Null(error.Source); + Assert.DoesNotContain("private-dependency", JsonSerializer.Serialize(bootstrap)); + client.GetFlag("public", new ReflagContext()); + await client.FlushAsync(); + using var bulk = JsonDocument.Parse(Assert.Single(transport.PostCalls).Body); + var source = Assert.Single(bulk.RootElement.EnumerateArray()).GetProperty("evalErrors")[0].GetProperty("source"); + Assert.Equal(kind, source.GetProperty("type").GetString()); + Assert.Equal("private-dependency", source.GetProperty("key").GetString()); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task Bootstrap_visibility_comes_from_the_evaluated_snapshot(bool oldPublic) + { + var flag = TestDefinitions.CreateFlag("flag", 1, new FlagConstantFilterDefinition { Value = true }); + var transport = new TestTransport(); + transport.EnqueueGetJson(Response((flag, !oldPublic))); + var newer = JsonNode.Parse(Response((flag, oldPublic)))!; + newer["flagStateVersion"] = 2; + transport.EnqueueGetJson(newer.ToJsonString()); + await using var client = new ReflagClient(Options(transport)); + await client.InitializeAsync(); + var changed = false; + client.SetFlagOverrides(_ => + { + if (!changed) + { + changed = true; + client.RefreshFlagsAsync(2).GetAwaiter().GetResult(); + } + + return new Dictionary(); + }); + var bootstrap = client.GetFlagsForBootstrap(Context, Quiet); + Assert.Equal(1, bootstrap.FlagStateVersion); + Assert.Equal(oldPublic, bootstrap.Flags.ContainsKey("flag")); + bootstrap = client.GetFlagsForBootstrap(Context, Quiet); + Assert.Equal(2, bootstrap.FlagStateVersion); + Assert.Equal(!oldPublic, bootstrap.Flags.ContainsKey("flag")); + } + + [Fact] + public async Task File_fallback_preserves_visibility_and_old_snapshots_fail_closed() + { + var directory = Path.Combine(Path.GetTempPath(), $"reflag-privacy-{Guid.NewGuid():N}"); + try + { + var provider = ReflagFallbackProviders.File(new FileFallbackProviderOptions { Directory = directory }); + var transport = new TestTransport(); + var publicFlag = TestDefinitions.CreateFlag("public", 1, new FlagConstantFilterDefinition { Value = true }); + var privateFlag = TestDefinitions.CreateFlag("private", 1, new FlagConstantFilterDefinition { Value = true }); + transport.EnqueueGetJson(Response((publicFlag, false), (privateFlag, true))); + await using (var client = new ReflagClient(Options(transport, provider))) + { + await client.InitializeAsync(); + await client.FlushAsync(); + } + + var file = Assert.Single(Directory.GetFiles(directory)); + var saved = JsonNode.Parse(File.ReadAllText(file))!; + Assert.False(saved["flags"]![0]!["secret"]!.GetValue()); + Assert.True(saved["flags"]![1]!["secret"]!.GetValue()); + var failing = new TestTransport(); + failing.EnqueueGetFailure(new HttpRequestException("offline")); + await using (var restored = new ReflagClient(Options(failing, provider))) + { + await restored.InitializeAsync(); + Assert.Equal("public", Assert.Single(restored.GetFlagsForBootstrap(Context, Quiet).Flags).Key); + Assert.True(restored.GetFlag("private", Context, Quiet)); + } + + foreach (var definition in saved["flags"]!.AsArray()) + { + definition!.AsObject().Remove("secret"); + } + + File.WriteAllText(file, saved.ToJsonString()); + var oldTransport = new TestTransport(); + oldTransport.EnqueueGetFailure(new HttpRequestException("offline")); + await using var old = new ReflagClient(Options(oldTransport, provider)); + await old.InitializeAsync(); + Assert.Empty(old.GetFlagsForBootstrap(Context, Quiet).Flags); + Assert.True(old.GetFlag("private", Context, Quiet)); + } + finally + { + if (Directory.Exists(directory)) Directory.Delete(directory, recursive: true); + } + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task Unclassified_static_values_and_offline_overrides_remain_server_only(bool offline) + { + var values = new Dictionary { ["local"] = true }; + var transport = new TestTransport(); + transport.EnqueueGetFailure(new HttpRequestException("offline")); + await using var client = new ReflagClient(new ReflagClientOptions + { + SecretKey = "synthetic-key-with-more-than-22-characters", + HttpClient = transport.CreateHttpClient(), + FlagsSyncMode = ReflagFlagsSyncMode.Polling, + FlagsFetchRetries = 0, + Offline = offline, + FlagOverrides = offline ? values : null, + FlagsFallbackProvider = offline ? null : ReflagFallbackProviders.Static(values), + }); + await client.InitializeAsync(); + Assert.Empty(client.GetFlagsForBootstrap(Context, Quiet).Flags); + Assert.True(client.GetFlag("local", Context, Quiet)); + } + + private static ReflagClientOptions Options(TestTransport transport, IFlagsFallbackProvider? provider = null) => new() + { + SecretKey = "synthetic-key-with-more-than-22-characters", + HttpClient = transport.CreateHttpClient(), + FlagsSyncMode = ReflagFlagsSyncMode.Polling, + FlagsFetchRetries = 0, + FlagsFallbackProvider = provider, + }; + + private static string Response(params (FlagDefinition Flag, bool Secret)[] flags) + { + var body = JsonNode.Parse(TestDefinitions.FlagsResponse(1, flags.Select(pair => pair.Flag).ToArray()))!; + for (var index = 0; index < flags.Length; index++) body["flags"]![index]!["secret"] = flags[index].Secret; + return body.ToJsonString(); + } +} diff --git a/tests/Reflag.Tests/EvaluationDiagnosticsTelemetryTests.cs b/tests/Reflag.Tests/EvaluationDiagnosticsTelemetryTests.cs index 9e94c49..bc1cf12 100644 --- a/tests/Reflag.Tests/EvaluationDiagnosticsTelemetryTests.cs +++ b/tests/Reflag.Tests/EvaluationDiagnosticsTelemetryTests.cs @@ -145,7 +145,7 @@ public async Task Offline_access_before_initialization_does_not_log_initializati }); Assert.True(client.GetFlag("flag", new ReflagContext())); - Assert.Empty(client.GetFlagsForBootstrap(new ReflagContext()).Flags["flag"].Errors); + Assert.Empty(client.GetFlagsForBootstrap(new ReflagContext()).Flags); await client.FlushAsync(); Assert.DoesNotContain(logger.Entries, entry => entry.Level == LogLevel.Error); Assert.Empty(transport.GetCalls); @@ -182,6 +182,7 @@ private static string Definitions(string op, string value) => JsonSerializer.Ser private static object BooleanFlag(string key, object filter) => new { key, + secret = false, sourceVersionId = $"{key}:v1", variants = new { on = true, off = false }, rules = new object[] diff --git a/tests/Reflag.Tests/JsonValueSerializationTests.cs b/tests/Reflag.Tests/JsonValueSerializationTests.cs index 79132c9..dd69bc0 100644 --- a/tests/Reflag.Tests/JsonValueSerializationTests.cs +++ b/tests/Reflag.Tests/JsonValueSerializationTests.cs @@ -31,13 +31,20 @@ public async Task Json_value_sources_preserve_null_properties(string source) ["none"] = null, }; var transport = new TestTransport(); - transport.EnqueueGetFailure(new HttpRequestException("offline")); + if (source == "static") + { + transport.EnqueueGetFailure(new HttpRequestException("offline")); + } + else + { + transport.EnqueueGetJson(TestDefinitions.FlagsResponse(1, values.Keys.Select(key => + TestDefinitions.CreateMultivariateFlag(key, "default", new Dictionary { ["default"] = null })).ToArray())); + } using var httpClient = transport.CreateHttpClient(); await using var client = new ReflagClient(new ReflagClientOptions { SecretKey = "validSecretKeyWithMoreThan22Chars", HttpClient = httpClient, - Offline = source != "static", FlagsSyncMode = ReflagFlagsSyncMode.Polling, FlagsFetchRetries = 0, JsonFlagOverrides = source == "startup" ? values : null, @@ -78,13 +85,22 @@ public async Task Json_value_sources_preserve_null_properties(string source) Assert.Equal(JsonValueKind.Null, client.GetFlag("none", context, default, telemetry).ValueKind); using var bootstrap = JsonDocument.Parse(JsonSerializer.Serialize(client.GetFlagsForBootstrap(context, telemetry))); - var flag = bootstrap.RootElement.GetProperty("flags").GetProperty("poco"); - Assert.Equal(JsonValueKind.Null, flag.GetProperty("value").GetProperty("name").ValueKind); - Assert.False(flag.GetProperty("resolved").GetBoolean()); - Assert.False(flag.TryGetProperty("variantKey", out _)); - Assert.False(flag.TryGetProperty("sourceVersionId", out _)); - Assert.False(flag.TryGetProperty("matchedRuleId", out _)); - Assert.False(bootstrap.RootElement.TryGetProperty("flagStateVersion", out _)); + if (source == "static") + { + Assert.Empty(bootstrap.RootElement.GetProperty("flags").EnumerateObject()); + Assert.False(bootstrap.RootElement.TryGetProperty("flagStateVersion", out _)); + } + else + { + var flag = bootstrap.RootElement.GetProperty("flags").GetProperty("poco"); + Assert.Equal(JsonValueKind.Null, flag.GetProperty("value").GetProperty("name").ValueKind); + Assert.Equal(JsonValueKind.Null, bootstrap.RootElement.GetProperty("flags").GetProperty("anonymous").GetProperty("value").GetProperty("nested").GetProperty("label").ValueKind); + Assert.False(flag.GetProperty("resolved").GetBoolean()); + Assert.False(flag.TryGetProperty("variantKey", out _)); + Assert.False(flag.TryGetProperty("sourceVersionId", out _)); + Assert.False(flag.TryGetProperty("matchedRuleId", out _)); + Assert.Equal(1, bootstrap.RootElement.GetProperty("flagStateVersion").GetInt32()); + } } [Fact] diff --git a/tests/Reflag.Tests/ReflagClientTests.cs b/tests/Reflag.Tests/ReflagClientTests.cs index 9a836a3..a41fa31 100644 --- a/tests/Reflag.Tests/ReflagClientTests.cs +++ b/tests/Reflag.Tests/ReflagClientTests.cs @@ -279,8 +279,7 @@ public void GetFlag_before_initialize_logs_and_uses_overrides() var bootstrapped = client.GetFlagsForBootstrap(new ReflagContext()); Assert.True(enabled); - Assert.True(bootstrapped.Flags["forced-flag"].Value!.Value.GetBoolean()); - Assert.False(bootstrapped.Flags["forced-flag"].Resolved); + Assert.Empty(bootstrapped.Flags); Assert.Null(bootstrapped.FlagStateVersion); Assert.Contains(logger.Entries, entry => entry.Level == LogLevel.Error && entry.Message.Contains("flag access: ReflagClient is not initialized yet.")); } @@ -352,10 +351,8 @@ public async Task InitializeAsync_uses_static_fallback_when_fetch_fails() var definitions = client.GetFlagDefinitions(); Assert.True(enabled); - Assert.True(bootstrapped.Flags["fallback-flag"].Value!.Value.GetBoolean()); - // Static values do not identify authored variants. - Assert.False(bootstrapped.Flags["fallback-flag"].Resolved); - Assert.Null(bootstrapped.Flags["fallback-flag"].VariantKey); + // Static values have no public visibility metadata. + Assert.Empty(bootstrapped.Flags); Assert.Null(bootstrapped.FlagStateVersion); Assert.Equal("static:fallback-flag", Assert.Single(definitions.Flags).SourceVersionId); Assert.Contains(logger.Entries, entry => entry.Level == LogLevel.Warning && entry.Message.Contains("remote flags unavailable, using fallback flags fetched")); diff --git a/tests/Reflag.Tests/ReflagEndToEndTests.cs b/tests/Reflag.Tests/ReflagEndToEndTests.cs index b42cba9..6edc3e8 100644 --- a/tests/Reflag.Tests/ReflagEndToEndTests.cs +++ b/tests/Reflag.Tests/ReflagEndToEndTests.cs @@ -19,6 +19,7 @@ public sealed class ReflagEndToEndTests "flags": [ { "key": "new-dashboard", + "secret": false, "sourceVersionId": "fv-dashboard", "variants": { "true": true, "false": false }, "rules": [ @@ -28,6 +29,7 @@ public sealed class ReflagEndToEndTests }, { "key": "model", + "secret": false, "sourceVersionId": "fv-model", "variants": { "quality": { "name": "large", "maxTokens": 8000 }, @@ -41,6 +43,7 @@ public sealed class ReflagEndToEndTests }, { "key": "quality-banner", + "secret": false, "sourceVersionId": "fv-banner", "variants": { "true": true, "false": false }, "rules": [ diff --git a/tests/Reflag.Tests/StartupOverridesTests.cs b/tests/Reflag.Tests/StartupOverridesTests.cs index 6610102..072dfa6 100644 --- a/tests/Reflag.Tests/StartupOverridesTests.cs +++ b/tests/Reflag.Tests/StartupOverridesTests.cs @@ -54,14 +54,7 @@ public async Task Json_values_are_captured_at_construction_and_remain_unresolved Assert.Equal("node", client.GetFlag("node", new ReflagContext(), default).GetProperty("name").GetString()); Assert.Equal("element", client.GetFlag("element", new ReflagContext(), default).GetProperty("name").GetString()); Assert.Equal(new[] { "one", "two" }, client.GetFlag("tags", new ReflagContext(), Array.Empty())); - Assert.All(client.GetFlagsForBootstrap(new ReflagContext()).Flags.Values, flag => - { - Assert.False(flag.Resolved); - Assert.Null(flag.VariantKey); - Assert.Null(flag.SourceVersionId); - Assert.Empty(flag.RuleResults); - Assert.Empty(flag.Errors); - }); + Assert.Empty(client.GetFlagsForBootstrap(new ReflagContext()).Flags); } } diff --git a/tests/Reflag.Tests/TestDoubles.cs b/tests/Reflag.Tests/TestDoubles.cs index b9170c9..5662dae 100644 --- a/tests/Reflag.Tests/TestDoubles.cs +++ b/tests/Reflag.Tests/TestDoubles.cs @@ -154,6 +154,7 @@ public static FlagDefinition CreateFlag( return new FlagDefinition { Key = key, + Secret = false, SourceVersionId = $"{key}:v{version}", Variants = new Dictionary { @@ -207,6 +208,7 @@ public static FlagDefinition CreateMultivariateFlag( return new FlagDefinition { Key = key, + Secret = false, SourceVersionId = $"{key}:v1", Variants = variants.ToDictionary(pair => pair.Key, pair => JsonSerializer.SerializeToElement(pair.Value)), Rules = rules, @@ -234,6 +236,7 @@ public static string FlagsResponse(int flagStateVersion, FlagDefinition[] flags, public static object ConstantFlagBody(string key, bool value) => new { key, + secret = false, sourceVersionId = $"{key}:{(value ? "on" : "off")}", variants = new Dictionary { ["on"] = true, ["off"] = false }, rules = new object[]