Skip to content

Commit

Permalink
Fix formatting for secrets which contain new lines #363
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Mar 20, 2023
1 parent 08b0e82 commit 07cb4cc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class Reporter(
val obfuscated: List<NodeState> = nodes.sortedBy { it.node.path.flatten() }.map { state ->

val value = if (state.secret && state.node is PrimitiveNode)
obfuscator.obfuscate(state.node)
obfuscator.obfuscate(state.node).replace("\n", "")
else
state.node.valueOrNull()
state.node.valueOrNull()?.replace("\n", "")

state.copy(
node = StringNode(
Expand Down
40 changes: 40 additions & 0 deletions hoplite-core/src/test/kotlin/com/sksamuel/hoplite/ReporterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,46 @@ Property sources (highest to lowest priority):

}

test("report should remove new lines") {

data class Test(
val name: String,
val host: String,
val port: Int,
val password: Secret,
)

captureStandardOut {
ConfigLoaderBuilder.default()
.addPropertySource(
PropertySource.string(
"""
name = my database
host = l\nremotehost
port = 3306
password = ssm://mysecretkey
""".trimIndent(), "props"
)
)
.withReport()
.build()
.loadConfigOrThrow<Test>()
}.shouldContain(
"""
Used keys: 4
+----------+---------------------+----------+
| Key | Source | Value |
+----------+---------------------+----------+
| host | props string source | lr***** |
| name | props string source | my ***** |
| password | props string source | ssm***** |
| port | props string source | 3306 |
+----------+---------------------+----------+
"""
)

}

test("should print report on failed config") {

data class Config(val name: String, val host: String, val port: Int)
Expand Down

0 comments on commit 07cb4cc

Please sign in to comment.