Skip to content

--assert-ok accepts 3xx, but --help and README both say 2xx #20

Description

@korya

Problem

AssertStatusOK (assertions.go:12) treats 200–399 as OK:

if s := res.StatusCode; s < 200 || s >= 400 {

But the flag help says Assert response is successful (2xx) and the README table says Assert 2xx status code.

Reproduction

$ http-assert --assert-ok http://127.0.0.1:8791/redirect   # responds 302 Found
[.] HTTP/1.1 GET http://127.0.0.1:8791/redirect
[:] HTTP/1.1 302 Found
[+] PASSED
[exit=0]

This is a docs bug, not a logic bug

assertions_test.go (Test_AssertStatusOK) explicitly pins 300, 301, 307 and 399 as OK, so the 2xx–3xx range is intentional (curl -f semantics). Only the documentation is wrong.

Why it matters

Combined with redirects not being followed, a health check pointed at an endpoint that starts 302-ing to a login page passes green.

Suggested fix

  • Update the flag description to something like Assert response is not an error (2xx or 3xx).
  • Update the README assertion table.
  • Consider a separate --assert-2xx for people who want the strict reading.

Activity

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

    documentationImprovements or additions to documentation

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions