diff --git a/src/ConfigCat.Client.Tests/BasicConfigCatClientIntegrationTests.cs b/src/ConfigCat.Client.Tests/BasicConfigCatClientIntegrationTests.cs index b856926b..43e0bd44 100644 --- a/src/ConfigCat.Client.Tests/BasicConfigCatClientIntegrationTests.cs +++ b/src/ConfigCat.Client.Tests/BasicConfigCatClientIntegrationTests.cs @@ -340,7 +340,7 @@ static void Configure(ConfigCatClientOptions options) public async Task Http_Timeout_Test_Async() { var response = $"{{ \"f\": {{ \"fakeKey\": {{ \"v\": \"fakeValue\", \"p\": [] ,\"r\": [] }} }} }}"; - using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake", options => + using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake-67890123456789012/1234567890123456789012", options => { options.PollingMode = PollingModes.ManualPoll; options.Logger = ConsoleLogger; @@ -357,7 +357,7 @@ public async Task Http_Timeout_Test_Async() public void Http_Timeout_Test_Sync() { var response = $"{{ \"f\": {{ \"fakeKey\": {{ \"v\": \"fakeValue\", \"p\": [] ,\"r\": [] }} }} }}"; - using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake", options => + using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake-67890123456789012/1234567890123456789012", options => { options.PollingMode = PollingModes.ManualPoll; options.Logger = ConsoleLogger; @@ -374,7 +374,7 @@ public async Task Ensure_MaxInitWait_Overrides_Timeout() { var now = DateTimeOffset.UtcNow; var response = $"{{ \"f\": {{ \"fakeKey\": {{ \"v\": \"fakeValue\", \"p\": [] ,\"r\": [] }} }} }}"; - using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake", options => + using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake-67890123456789012/1234567890123456789012", options => { options.PollingMode = PollingModes.AutoPoll(maxInitWaitTime: TimeSpan.FromSeconds(1)); options.Logger = ConsoleLogger; @@ -390,7 +390,7 @@ public void Ensure_MaxInitWait_Overrides_Timeout_Sync() { var now = DateTimeOffset.UtcNow; var response = $"{{ \"f\": {{ \"fakeKey\": {{ \"v\": \"fakeValue\", \"p\": [] ,\"r\": [] }} }} }}"; - using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake", options => + using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake-67890123456789012/1234567890123456789012", options => { options.PollingMode = PollingModes.AutoPoll(maxInitWaitTime: TimeSpan.FromSeconds(1)); options.Logger = ConsoleLogger; @@ -407,7 +407,7 @@ public void Ensure_Client_Dispose_Kill_Hanging_Http_Call() var defer = new ManualResetEvent(false); var now = DateTimeOffset.UtcNow; var response = $"{{ \"f\": {{ \"fakeKey\": {{ \"v\": \"fakeValue\", \"p\": [] ,\"r\": [] }} }} }}"; - using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake", options => + using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake-67890123456789012/1234567890123456789012", options => { options.Logger = ConsoleLogger; options.HttpClientHandler = new FakeHttpClientHandler(System.Net.HttpStatusCode.OK, response, TimeSpan.FromSeconds(5)); @@ -426,7 +426,7 @@ public void Ensure_Client_Dispose_Kill_Hanging_Http_Call_Sync() var defer = new ManualResetEvent(false); var now = DateTimeOffset.UtcNow; var response = $"{{ \"f\": {{ \"fakeKey\": {{ \"v\": \"fakeValue\", \"p\": [] ,\"r\": [] }} }} }}"; - using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake", options => + using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake-67890123456789012/1234567890123456789012", options => { options.Logger = ConsoleLogger; options.HttpClientHandler = new FakeHttpClientHandler(System.Net.HttpStatusCode.OK, response, TimeSpan.FromSeconds(5)); @@ -447,7 +447,7 @@ public void Ensure_Client_Dispose_Kill_Hanging_Http_Call_Sync() public void Ensure_Multiple_Requests_Doesnt_Interfere_In_ValueTasks() { var response = $"{{ \"f\": {{ \"fakeKey\": {{ \"v\": \"fakeValue\", \"p\": [] ,\"r\": [] }} }} }}"; - using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake", options => + using IConfigCatClient manualPollClient = ConfigCatClient.Get("fake-67890123456789012/1234567890123456789012", options => { options.Logger = ConsoleLogger; options.PollingMode = PollingModes.ManualPoll; diff --git a/src/ConfigCat.Client.Tests/ConfigCatClientTests.cs b/src/ConfigCat.Client.Tests/ConfigCatClientTests.cs index 928992b1..1b16629e 100644 --- a/src/ConfigCat.Client.Tests/ConfigCatClientTests.cs +++ b/src/ConfigCat.Client.Tests/ConfigCatClientTests.cs @@ -83,7 +83,7 @@ public void CreateAnInstance_WhenLazyLoadConfigurationTimeToLiveSecondsIsZero_Sh [DoNotParallelize] public void CreateAnInstance_WhenLoggerIsNull_ShouldCreateAnInstance() { - using var client = ConfigCatClient.Get("hsdrTr4sxbHdSgdhHRZds346hdgsS2vfsgf/GsdrTr4sxbHdSgdhHRZds346hdOPsSgvfsgf", options => + using var client = ConfigCatClient.Get("hsdrTr4sxbHdSgdhHRZds3/GsdrTr4sxbHdSgdhHRZds3", options => { options.Logger = null; }); @@ -95,7 +95,7 @@ public void CreateAnInstance_WhenLoggerIsNull_ShouldCreateAnInstance() [DoNotParallelize] public void CreateAnInstance_WithSdkKey_ShouldCreateAnInstance() { - using var _ = ConfigCatClient.Get("hsdrTr4sxbHdSgdhHRZds346hdgsS2vfsgf/GsdrTr4sxbHdSgdhHRZds346hdOPsSgvfsgf"); + using var _ = ConfigCatClient.Get("hsdrTr4sxbHdSgdhHRZds3/GsdrTr4sxbHdSgdhHRZds3"); } [TestMethod] @@ -149,6 +149,10 @@ public void GetValue_EvaluateServiceThrowException_ShouldReturnDefaultValue() const string defaultValue = "Victory for the Firstborn!"; + this.configServiceMock + .Setup(m => m.GetConfig()) + .Throws(); + this.evaluatorMock .Setup(m => m.Evaluate(ref It.Ref.IsAny)) .Throws(); @@ -178,6 +182,10 @@ public async Task GetValueAsync_EvaluateServiceThrowException_ShouldReturnDefaul const string defaultValue = "Victory for the Firstborn!"; + this.configServiceMock + .Setup(m => m.GetConfigAsync(It.IsAny())) + .Throws(); + this.evaluatorMock .Setup(m => m.Evaluate(ref It.Ref.IsAny)) .Throws(); @@ -622,6 +630,10 @@ public async Task GetAllValueDetails_ConfigServiceThrowException_ShouldReturnEmp { // Arrange + this.configServiceMock + .Setup(m => m.GetConfig()) + .Throws(); + this.configServiceMock .Setup(m => m.GetConfigAsync(It.IsAny())) .Throws(); @@ -779,7 +791,7 @@ public void GetAllKeys_DeserializerThrowException_ShouldReturnsWithEmptyArray() { // Arrange - this.configServiceMock.Setup(m => m.GetConfigAsync(It.IsAny())).ReturnsAsync(ProjectConfig.Empty); + this.configServiceMock.Setup(m => m.GetConfig()).Returns(ProjectConfig.Empty); var o = new Config(); IConfigCatClient instance = new ConfigCatClient( @@ -1065,7 +1077,7 @@ public async Task ForceRefreshAsync_ShouldBeCancelable() private static IConfigCatClient CreateClientFromLocalFile(string fileName, User? defaultUser = null) { - return ConfigCatClient.Get("localhost", options => + return ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile( Path.Combine("data", fileName), @@ -1160,11 +1172,11 @@ void Configure(ConfigCatClientOptions options) // Act - using var client1 = ConfigCatClient.Get("test", Configure); + using var client1 = ConfigCatClient.Get("test-67890123456789012/1234567890123456789012", Configure); var warnings1 = warnings.ToArray(); warnings.Clear(); - using var client2 = ConfigCatClient.Get("test", passConfigureToSecondGet ? Configure : null); + using var client2 = ConfigCatClient.Get("test-67890123456789012/1234567890123456789012", passConfigureToSecondGet ? Configure : null); var warnings2 = warnings.ToArray(); // Assert @@ -1189,7 +1201,7 @@ public void Dispose_CachedInstanceRemoved() { // Arrange - var client1 = ConfigCatClient.Get("test", options => options.PollingMode = PollingModes.ManualPoll); + var client1 = ConfigCatClient.Get("test-67890123456789012/1234567890123456789012", options => options.PollingMode = PollingModes.ManualPoll); // Act @@ -1211,7 +1223,7 @@ public void Dispose_CanRemoveCurrentCachedInstanceOnly() { // Arrange - var client1 = ConfigCatClient.Get("test", options => options.PollingMode = PollingModes.ManualPoll); + var client1 = ConfigCatClient.Get("test-67890123456789012/1234567890123456789012", options => options.PollingMode = PollingModes.ManualPoll); // Act @@ -1221,7 +1233,7 @@ public void Dispose_CanRemoveCurrentCachedInstanceOnly() var instanceCount2 = ConfigCatClient.Instances.GetAliveCount(); - var client2 = ConfigCatClient.Get("test", options => options.PollingMode = PollingModes.ManualPoll); + var client2 = ConfigCatClient.Get("test-67890123456789012/1234567890123456789012", options => options.PollingMode = PollingModes.ManualPoll); var instanceCount3 = ConfigCatClient.Instances.GetAliveCount(); @@ -1248,8 +1260,8 @@ public void DisposeAll_CachedInstancesRemoved() { // Arrange - var client1 = ConfigCatClient.Get("test1", options => options.PollingMode = PollingModes.AutoPoll()); - var client2 = ConfigCatClient.Get("test2", options => options.PollingMode = PollingModes.ManualPoll); + var client1 = ConfigCatClient.Get("test1-7890123456789012/1234567890123456789012", options => options.PollingMode = PollingModes.AutoPoll()); + var client2 = ConfigCatClient.Get("test2-7890123456789012/1234567890123456789012", options => options.PollingMode = PollingModes.ManualPoll); // Act @@ -1283,8 +1295,8 @@ static void CreateClients(out int instanceCount) // because that could interfere with this test: when raising the event, the service acquires a strong reference to the client, // which would temporarily prevent the client from being GCd. This could break the test in the case of unlucky timing. // Setting maxInitWaitTime to zero prevents this because then the event is raised immediately at creation. - var client1 = ConfigCatClient.Get("test1", options => options.PollingMode = PollingModes.AutoPoll(maxInitWaitTime: TimeSpan.Zero)); - var client2 = ConfigCatClient.Get("test2", options => options.PollingMode = PollingModes.ManualPoll); + var client1 = ConfigCatClient.Get("test1-7890123456789012/1234567890123456789012", options => options.PollingMode = PollingModes.AutoPoll(maxInitWaitTime: TimeSpan.Zero)); + var client2 = ConfigCatClient.Get("test2-7890123456789012/1234567890123456789012", options => options.PollingMode = PollingModes.ManualPoll); instanceCount = ConfigCatClient.Instances.GetAliveCount(); diff --git a/src/ConfigCat.Client.Tests/OverrideTests.cs b/src/ConfigCat.Client.Tests/OverrideTests.cs index dd82e09c..165d2575 100644 --- a/src/ConfigCat.Client.Tests/OverrideTests.cs +++ b/src/ConfigCat.Client.Tests/OverrideTests.cs @@ -24,7 +24,7 @@ public class OverrideTests [TestMethod] public void LocalFile() { - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(ComplexJsonPath, false, OverrideBehaviour.LocalOnly); }); @@ -39,7 +39,7 @@ public void LocalFile() [TestMethod] public async Task LocalFileAsync() { - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(ComplexJsonPath, false, OverrideBehaviour.LocalOnly); }); @@ -53,7 +53,7 @@ public async Task LocalFileAsync() public static void LocalFile_Parallel() { - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(ComplexJsonPath, false, OverrideBehaviour.LocalOnly); }); @@ -77,7 +77,7 @@ public void LocalFileAsync_Parallel() "stringSetting", }; - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(ComplexJsonPath, false, OverrideBehaviour.LocalOnly); }); @@ -100,7 +100,7 @@ public void LocalFileAsync_Parallel_Sync() "stringSetting", }; - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(ComplexJsonPath, false, OverrideBehaviour.LocalOnly); }); @@ -114,7 +114,7 @@ public void LocalFileAsync_Parallel_Sync() [TestMethod] public void LocalFile_Default_WhenErrorOccures() { - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile("something-not-existing", false, OverrideBehaviour.LocalOnly); }); @@ -126,7 +126,7 @@ public void LocalFile_Default_WhenErrorOccures() [TestMethod] public void LocalFile_Read() { - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(ComplexJsonPath, true, OverrideBehaviour.LocalOnly); }); @@ -141,7 +141,7 @@ public void LocalFile_Read() [TestMethod] public async Task LocalFileAsync_Read() { - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(ComplexJsonPath, true, OverrideBehaviour.LocalOnly); }); @@ -156,7 +156,7 @@ public async Task LocalFileAsync_Read() [TestMethod] public void LocalFile_Default_WhenErrorOccures_Reload() { - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile("something-not-existing", true, OverrideBehaviour.LocalOnly); }); @@ -168,7 +168,7 @@ public void LocalFile_Default_WhenErrorOccures_Reload() [TestMethod] public void LocalFile_Simple() { - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(SimpleJsonPath, false, OverrideBehaviour.LocalOnly); }); @@ -183,7 +183,7 @@ public void LocalFile_Simple() [TestMethod] public async Task LocalFileAsync_Simple() { - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(SimpleJsonPath, false, OverrideBehaviour.LocalOnly); }); @@ -207,7 +207,7 @@ public void LocalFile_Dictionary() {"stringSetting", "test"}, }; - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalDictionary(dict, OverrideBehaviour.LocalOnly); }); @@ -231,7 +231,7 @@ public async Task LocalFileAsync_Dictionary() {"stringSetting", "test"}, }; - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalDictionary(dict, OverrideBehaviour.LocalOnly); }); @@ -252,7 +252,7 @@ public void LocalOnly() {"nonexisting", true}, }; - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalDictionary(dict, OverrideBehaviour.LocalOnly); options.PollingMode = PollingModes.ManualPoll; @@ -276,7 +276,7 @@ public void LocalOnly_Watch() {"fakeKey", "test1"}, }; - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalDictionary(dict, true, OverrideBehaviour.LocalOnly); options.PollingMode = PollingModes.ManualPoll; @@ -297,7 +297,7 @@ public async Task LocalOnly_Async_Watch() {"fakeKey", "test1"}, }; - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalDictionary(dict, true, OverrideBehaviour.LocalOnly); options.PollingMode = PollingModes.ManualPoll; @@ -319,7 +319,7 @@ public async Task LocalOnly_Async() {"nonexisting", true}, }; - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalDictionary(dict, OverrideBehaviour.LocalOnly); options.PollingMode = PollingModes.ManualPoll; @@ -346,7 +346,7 @@ public void LocalOverRemote() var fakeHandler = new FakeHttpClientHandler(System.Net.HttpStatusCode.OK); - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalDictionary(dict, OverrideBehaviour.LocalOverRemote); options.HttpClientHandler = new FakeHttpClientHandler(System.Net.HttpStatusCode.OK, GetJsonContent("false")); @@ -370,7 +370,7 @@ public async Task LocalOverRemote_Async() var fakeHandler = new FakeHttpClientHandler(System.Net.HttpStatusCode.OK); - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalDictionary(dict, OverrideBehaviour.LocalOverRemote); options.HttpClientHandler = new FakeHttpClientHandler(System.Net.HttpStatusCode.OK, GetJsonContent("false")); @@ -394,7 +394,7 @@ public void RemoteOverLocal() var fakeHandler = new FakeHttpClientHandler(System.Net.HttpStatusCode.OK); - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalDictionary(dict, OverrideBehaviour.RemoteOverLocal); options.HttpClientHandler = new FakeHttpClientHandler(System.Net.HttpStatusCode.OK, GetJsonContent("false")); @@ -418,7 +418,7 @@ public async Task RemoteOverLocal_Async() var fakeHandler = new FakeHttpClientHandler(System.Net.HttpStatusCode.OK); - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalDictionary(dict, OverrideBehaviour.RemoteOverLocal); options.HttpClientHandler = new FakeHttpClientHandler(System.Net.HttpStatusCode.OK, GetJsonContent("false")); @@ -436,7 +436,7 @@ public async Task LocalFile_Watcher_Reload() { await CreateFileAndWriteContent(SampleFileToCreate, "initial"); - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(SampleFileToCreate, true, OverrideBehaviour.LocalOnly); }); @@ -457,7 +457,7 @@ public async Task LocalFile_Watcher_Reload_Sync() { await CreateFileAndWriteContent(SampleFileToCreate, "initial"); - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.FlagOverrides = FlagOverrides.LocalFile(SampleFileToCreate, true, OverrideBehaviour.LocalOnly); }); @@ -507,7 +507,7 @@ public void OverrideValueTypeMismatchShouldBeHandledCorrectly_Dictionary(object [key] = overrideValue is not Type valueType ? overrideValue : Activator.CreateInstance(valueType)! }; - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.PollingMode = PollingModes.ManualPoll; options.FlagOverrides = FlagOverrides.LocalDictionary(dictionary, OverrideBehaviour.LocalOnly); @@ -569,7 +569,7 @@ public void OverrideValueTypeMismatchShouldBeHandledCorrectly_SimplifiedConfig(s try { - using var client = ConfigCatClient.Get("localhost", options => + using var client = ConfigCatClient.Get("localhost-123456789012/1234567890123456789012", options => { options.PollingMode = PollingModes.ManualPoll; options.FlagOverrides = FlagOverrides.LocalFile(filePath, autoReload: false, OverrideBehaviour.LocalOnly); diff --git a/src/ConfigCatClient/ConfigCatClient.cs b/src/ConfigCatClient/ConfigCatClient.cs index f0a0e1c5..594ff437 100644 --- a/src/ConfigCatClient/ConfigCatClient.cs +++ b/src/ConfigCatClient/ConfigCatClient.cs @@ -34,6 +34,32 @@ public sealed class ConfigCatClient : IConfigCatClient // which is good enough in these cases. private volatile User? defaultUser; + private static bool IsValidSdkKey(string sdkKey, bool customBaseUrl) + { + const string proxyPrefix = "configcat-proxy/"; + + if (customBaseUrl && sdkKey.Length > proxyPrefix.Length && sdkKey.StartsWith(proxyPrefix, StringComparison.Ordinal)) + { + return true; + } + + var components = sdkKey.Split('/'); + const int keyLength = 22; + + return components.Length switch + { + 2 => components[0].Length == keyLength && components[1].Length == keyLength, + 3 => components[0] == "configcat-sdk-1" && components[1].Length == keyLength && components[2].Length == keyLength, + _ => false + }; + } + + internal static string GetCacheKey(string sdkKey) + { + var key = $"{sdkKey}_{ConfigCatClientOptions.ConfigFileName}_{ProjectConfig.SerializationFormatVersion}"; + return key.Sha1(); + } + /// public LogLevel LogLevel { @@ -113,7 +139,7 @@ internal ConfigCatClient(IConfigService configService, IConfigCatLogger logger, /// SDK Key to access the ConfigCat config. /// The action used to configure the client. /// is . - /// is an empty string. + /// is an empty string or in an invalid format. public static IConfigCatClient Get(string sdkKey, Action? configurationAction = null) { if (sdkKey is null) @@ -129,6 +155,11 @@ public static IConfigCatClient Get(string sdkKey, Action var options = new ConfigCatClientOptions(); configurationAction?.Invoke(options); + if (!IsValidSdkKey(sdkKey, options.IsCustomBaseUrl)) + { + throw new ArgumentException($"SDK Key '{sdkKey}' is invalid.", nameof(sdkKey)); + } + var instance = Instances.GetOrCreate(sdkKey, options, out var instanceAlreadyCreated); if (instanceAlreadyCreated && configurationAction is not null) @@ -662,12 +693,6 @@ private static IConfigService DetermineConfigService(PollingMode pollingMode, Ht }; } - internal static string GetCacheKey(string sdkKey) - { - var key = $"{sdkKey}_{ConfigCatClientOptions.ConfigFileName}_{ProjectConfig.SerializationFormatVersion}"; - return key.Sha1(); - } - /// public void SetDefaultUser(User user) {