From d18835fd6c7c2b0908d8e4020ded56ccde74b6f0 Mon Sep 17 00:00:00 2001 From: Colin Redmond Date: Wed, 20 Mar 2024 23:21:38 -0700 Subject: [PATCH] chore: add extra testing around secret masking --- .../github/gestalt/config/GestaltTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gestalt-core/src/test/java/org/github/gestalt/config/GestaltTest.java b/gestalt-core/src/test/java/org/github/gestalt/config/GestaltTest.java index 97ef82c9c..aa473a9ce 100644 --- a/gestalt-core/src/test/java/org/github/gestalt/config/GestaltTest.java +++ b/gestalt-core/src/test/java/org/github/gestalt/config/GestaltTest.java @@ -1748,6 +1748,31 @@ public void testSecretMasking() throws GestaltException { "port=LeafNode{value='&&&&&'}, uri=LeafNode{value='my.sql.com'}}}", rootNode); } + @Test + public void testSecretMaskingDefault() throws GestaltException { + Map configs = new HashMap<>(); + configs.put("db.password", "test"); + configs.put("db.port", "abcdef"); + configs.put("db.uri", "my.sql.com"); + configs.put("db.salt", "pepper"); + configs.put("db.secret.user", "12345"); + + Gestalt gestalt = new GestaltBuilder() + .addSource(MapConfigSourceBuilder.builder().setCustomConfig(configs).build()) + .setTreatMissingValuesAsErrors(true) + .setTreatMissingDiscretionaryValuesAsErrors(true) + .setProxyDecoderMode(ProxyDecoderMode.CACHE) + .useCacheDecorator(false) + .build(); + + gestalt.loadConfigs(); + + String rootNode = gestalt.debugPrint(Tags.of()); + + Assertions.assertEquals("MapNode{db=MapNode{password=LeafNode{value='*****'}, salt=LeafNode{value='*****'}, " + + "port=LeafNode{value='abcdef'}, secret=MapNode{user=LeafNode{value='*****'}}, uri=LeafNode{value='my.sql.com'}}}", rootNode); + } + @Test public void testDebugPrint() throws GestaltException { Map configs = new HashMap<>();