Skip to content

Commit

Permalink
fix(hocon_tconf): do not obfuscate 'undefined' as "******"
Browse files Browse the repository at this point in the history
Otherwise it's impossible to tell if the original value existed
or not when an obfuscated struct is sent back for comparism.
  • Loading branch information
zmstone committed Dec 22, 2023
1 parent 04c7576 commit 670eb6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hocon_tconf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,10 @@ ensure_obfuscate_sensitive(Opts, Schema, Val) ->
Val
end.

%% Should not replace 'undefined' with "******" because we want to
%% be able to tell if value existed or not.
obfuscate(_Schema, undefined) ->
undefined;
obfuscate(Schema, Value) ->
case field_schema(Schema, sensitive) of
true -> <<"******">>;
Expand Down
7 changes: 7 additions & 0 deletions test/hocon_tconf_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fields(bar) ->
[
{union_with_default, fun union_with_default/1},
{field1, fun field1/1},
{optional_secret, fun optional_secret/1},
{host, fun host/1}
];
fields(parent) ->
Expand Down Expand Up @@ -69,6 +70,12 @@ field1(desc) -> "field1 desc";
field1(sensitive) -> true;
field1(_) -> undefined.

optional_secret(type) -> string();
optional_secret(desc) -> "optional secret";
optional_secret(sensitive) -> true;
optional_secret(required) -> false;
optional_secret(_) -> undefined.

host(type) -> string();
host(required) -> false;
host(desc) -> "host desc";
Expand Down

0 comments on commit 670eb6b

Please sign in to comment.