Skip to content

Refuse a cassette interaction whose request URI is not a request URI #3

Closed

Description

@Balanov

What is missing today

cassette.Load in internal/cassette/io.go:91 refuses an interaction when the request method is empty, when the request URI is empty, or when the response status is outside 100..999. It never checks that the recorded URI is a URI at all.

Every consumer then has to cope with the malformed value on its own, and each one falls back to the raw string:

  • cassette.Key (internal/cassette/match.go:24) keeps path = request.URI and query = "" when url.ParseRequestURI fails, so the interaction is filed under a key that no HTTP client can produce.
  • cassette.observedPath (internal/cassette/openapi.go:175) returns the raw URI as the OpenAPI path key.
  • lab.targetURL (internal/lab/http.go:63) fails at request time, so equal verify reports the interaction as a transport failure instead of refusing the cassette.

The consequence is that a hand-edited or third-party cassette with a malformed URI, for example /v1/a%zz or /v1/a b, loads without any message. equal replay binds the interaction to a key that can never be requested, so the sandbox holds an interaction that is dead. equal export writes the raw string as a path key into the OpenAPI document, and the CI only validates the OpenAPI schema of the shipped examples/openapi.json, so nothing catches it.

docs/ARCHITECTURE.md states the rule for the replay path: "At startup, EQUAL validates the complete cassette and precomputes request keys into queues." The CHANGELOG.md entry for 0.2.0 states the promise for the export path: "Add equal export: generate a valid OpenAPI 3.1 JSON document from recorded traffic."

What done means

  • equal replay --cassette FILE refuses a cassette whose interaction URI is not a request URI. The message names the interaction id and the URI, and the process exits 1 before the listener starts.
  • equal verify, equal export and equal inspect refuse the same cassette with the same message and exit 1.
  • An interaction whose URI is a valid origin-form path, for example /v1/users/42?include=profile, and an interaction whose URI is a valid absolute URL are both still accepted.
  • examples/cassette.jsonl still loads, and the document that equal export --cassette examples/cassette.jsonl writes keeps the same paths, parameters, requestBody and responses as examples/openapi.json.
  • go test -count=1 ./... passes, with one test for an interaction whose URI is not a request URI.
  • go vet ./... passes.
  • The exit codes stay as they are: 0 success, 1 a runtime error, 2 a usage error, 3 an incompatible candidate.

Boundary

  • Zero runtime dependencies. The standard library is enough.
  • No change to the equal/v1 cassette format, to the recorded fields or to the redaction behaviour.
  • No network call, no telemetry, no account, no service.
  • The replay, verify, export and inspect commands keep their current arguments and their current output.
  • Do not add vendor links or endorsements to the documentation, and do not trade a documentation change for this fix.

Activity

  1. Balanov commented on Nov 15, 2026

    @Balanov
    OwnerAuthor

    Thank you for the report, and for the fix. @ShahadatTest opened pull request #4 and it is merged: a cassette whose request URI does not parse, or that carries raw whitespace, is refused at load time with the interaction id and the URI in the message. It ships in equal 0.2.1.

    A malformed cassette that loads quietly and then replays under an unreachable key is a trap. Thank you for the report and for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions