Skip to content

Instantly share code, notes, and snippets.

@ishults
Last active September 26, 2017 17:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ishults/43b7e14d4deb60f5bb5cecfc872aee7b to your computer and use it in GitHub Desktop.
Tests for the main class
class LogMaskingConverterSpec extends Specification {
@Shared
LogMaskingConverter converter
void setup() {
converter = new LogMaskingConverter()
}
@Unroll
void 'format() should mask sensitive data'() {
setup:
SimpleMessage message = new SimpleMessage(input)
LogEvent logEvent = new Log4jLogEvent('LogMaskingConverterSpecLogger', new MarkerManager.Log4jMarker(LoggingMarkers.JSON.name), null, null, message, null)
StringBuilder builder = new StringBuilder()
when:
converter.format(logEvent, builder)
then:
assert builder.toString() == expectedOutput
where:
input | expectedOutput
'{"noMask": "foo"}' | '{"noMask": "foo"}'
'{"ssn": "1234567890", "id": "ABC-123", "private": "someKey"}' | '{"ssn": "****", "id": "ABC-123", "private": "****"}'
'invalidJson' | 'invalidJson'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment