Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public ConfigurationHoconAdapterTest()
Environment.SetEnvironmentVariable("akka__test_value_4__1", "one");
Environment.SetEnvironmentVariable("akka__actor__serialization_bindings2__\"System.Object\"", "hyperion");

// Issue #631
// Double underscore cases
Environment.SetEnvironmentVariable("__MISE_SESSION", "some-random-string");
// Quadruple underscore cases
Environment.SetEnvironmentVariable("MISE____SESSION", "some-random-string");
Environment.SetEnvironmentVariable("____MISE_SESSION", "some-random-string");

using var stream = new MemoryStream(Encoding.UTF8.GetBytes(ConfigSource));
_root = new ConfigurationBuilder()
.AddJsonStream(stream)
Expand Down Expand Up @@ -96,6 +103,10 @@ public Task DisposeAsync()
Environment.SetEnvironmentVariable("akka__test_value_4__1", null);
Environment.SetEnvironmentVariable("akka__actor__serialization_bindings2__\"System.Object\"", null);

Environment.SetEnvironmentVariable("__MISE_SESSION", null);
Environment.SetEnvironmentVariable("MISE____SESSION", null);
Environment.SetEnvironmentVariable("____MISE_SESSION", null);

return Task.CompletedTask;
}

Expand Down Expand Up @@ -139,6 +150,11 @@ public void EnvironmentVariableTest()
bindings.ContainsKey("System.Object").Should().BeFalse();
bindings.ContainsKey("system.object").Should().BeTrue();
bindings["system.object"].GetString().Should().Be("hyperion");

// empty string keyed objects should be accessible by using "__"
config.GetString("__.mise-session").Should().Be("some-random-string");
config.GetString("mise.__.session").Should().Be("some-random-string");
config.GetString("__.__.mise-session").Should().Be("some-random-string");
}

[Fact(DisplayName = "Non-normalized adaptor should read environment variable sourced configuration correctly")]
Expand Down Expand Up @@ -179,6 +195,11 @@ public void EnvironmentVariableCaseSensitiveTest()
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
bindings.ContainsKey("System.Object").Should().BeTrue();
bindings["System.Object"].GetString().Should().Be("hyperion");

// empty string keyed objects should be accessible by using "__"
config.GetString("__.MISE-SESSION").Should().Be("some-random-string");
config.GetString("MISE.__.SESSION").Should().Be("some-random-string");
config.GetString("__.__.MISE-SESSION").Should().Be("some-random-string");
}

[Fact(DisplayName = "Non-normalized Adaptor should read quote enclosed key inside JSON settings correctly")]
Expand Down
6 changes: 6 additions & 0 deletions src/Akka.Hosting/Configuration/ConfigurationHoconAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ private static HoconValue ExpandKey(this IConfigurationSection config, HoconObje
var sanitized = (normalizeKeys ? config.Key.ToLowerInvariant() : config.Key).Replace("_", "-");
var keys = sanitized.SplitDottedPathHonouringQuotes().ToList();

// HOCON does not support objects with empty key name.
// The most probable source for this is a double underscore prefixed environment variable, which
// confuses MS.EXT.Configuration.EnvironmentVariables. Just create a temporary name for it.
if(keys.Count == 0)
return parent.GetOrCreateKey("__");

// No need to expand the chain
if (keys.Count == 1)
{
Expand Down