Class ImportRedaction
FixtureRedactor masking to expectations produced by the import
pipeline (HarImporter, PostmanCollectionImporter) before they
are persisted, so real credentials in captured traffic never land in the
expectation store.
Redaction is on by default. Imported requests and responses
have sensitive headers (Authorization, X-Api-Key, Cookie,
Set-Cookie, Proxy-Authorization, etc. — see
FixtureRedactor.defaultSensitiveHeaders()) and well-known sensitive JSON
body fields replaced with FixtureRedactor.REDACTED_PLACEHOLDER. The
placeholder keeps the expectation structurally intact so it still matches.
Callers can disable redaction or extend the sensitive-key list via
ImportRedaction.Options. The expectation id assigned by the importer is preserved
across redaction (the underlying FixtureRedactor rebuilds expectations
without copying the id).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRedaction options for an import. -
Field Summary
FieldsModifier and TypeFieldDescriptionDefault JSON body field names redacted on import (case-insensitive, matched at any depth). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<Expectation>redact(List<Expectation> expectations, ImportRedaction.Options options) Redact the supplied expectations according tooptions.static List<Expectation>redactPreservingActions(List<Expectation> expectations, ImportRedaction.Options options) Redact expectations produced by a migration importer (WireMockImporter,MountebankImporter,MockoonImporter) while preserving the action type and matching constraints.static List<HttpRequestAndHttpResponse>redactRecordedTraffic(List<HttpRequestAndHttpResponse> pairs, ImportRedaction.Options options) Redact recorded request/response pairs (loaded from a persisted NDJSON archive byRecordedTrafficImporter) according tooptions, using the same sensitive-header and body-field masking asredact(List, Options).
-
Field Details
-
DEFAULT_SENSITIVE_BODY_FIELDS
Default JSON body field names redacted on import (case-insensitive, matched at any depth). Covers the common secret-bearing field names seen in captured API traffic.
-
-
Constructor Details
-
ImportRedaction
public ImportRedaction()
-
-
Method Details
-
redact
public static List<Expectation> redact(List<Expectation> expectations, ImportRedaction.Options options) Redact the supplied expectations according tooptions. When redaction is disabled the input list is returned unchanged; otherwise a new list of redacted expectations (preserving each expectation's id) is returned.- Parameters:
expectations- expectations produced by an importer (may be empty)options- redaction options; defaults to enabled ifnull- Returns:
- the redacted (or original, when disabled) expectations
-
redactPreservingActions
public static List<Expectation> redactPreservingActions(List<Expectation> expectations, ImportRedaction.Options options) Redact expectations produced by a migration importer (WireMockImporter,MountebankImporter,MockoonImporter) while preserving the action type and matching constraints.redact(List, Options)delegates toFixtureRedactor.redact(Expectation[]), which only carries over response actions and rebuilds each expectation with defaultTimes/TimeToLive— fine for HAR/Postman (single static responses) but lossy for the migration importers, which also emithttpForward(proxy),httpError(fault), sequential/random multi-responses andTimesconstraints (repeat). This method redacts the request and each response individually (via the granularFixtureRedactor.redactRequestDefinition(org.mockserver.model.RequestDefinition)/FixtureRedactor.redactResponseObject(org.mockserver.model.HttpResponse)clones) and re-attaches them to a rebuilt expectation that keeps the original action type,Times,TimeToLive, priority, id, scenario state and response mode.- Parameters:
expectations- expectations produced by a migration importer (may be empty)options- redaction options; defaults to enabled ifnull- Returns:
- the redacted (or original, when disabled) expectations
-
redactRecordedTraffic
public static List<HttpRequestAndHttpResponse> redactRecordedTraffic(List<HttpRequestAndHttpResponse> pairs, ImportRedaction.Options options) Redact recorded request/response pairs (loaded from a persisted NDJSON archive byRecordedTrafficImporter) according tooptions, using the same sensitive-header and body-field masking asredact(List, Options). When redaction is disabled the input list is returned unchanged; otherwise a new list of redacted pairs is returned. This is a defence-in-depth re-mask on the import side — the persist side already redacts on write whenmockserver.redactSecretsInLogis on, and re-masking an already-masked value is a no-op.- Parameters:
pairs- recorded request/response pairs (may be null or empty)options- redaction options; defaults to enabled ifnull- Returns:
- the redacted (or original, when disabled) pairs
-