Class ImportRedaction

java.lang.Object
org.mockserver.imports.ImportRedaction

public class ImportRedaction extends Object
Applies 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).

  • Field Details

    • DEFAULT_SENSITIVE_BODY_FIELDS

      public static final Set<String> 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 to options. 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 if null
      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 to FixtureRedactor.redact(Expectation[]), which only carries over response actions and rebuilds each expectation with default Times/TimeToLive — fine for HAR/Postman (single static responses) but lossy for the migration importers, which also emit httpForward (proxy), httpError (fault), sequential/random multi-responses and Times constraints (repeat). This method redacts the request and each response individually (via the granular FixtureRedactor.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 if null
      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 by RecordedTrafficImporter) according to options, using the same sensitive-header and body-field masking as redact(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 when mockserver.redactSecretsInLog is 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 if null
      Returns:
      the redacted (or original, when disabled) pairs