Skip to content

Commit

Permalink
Add JWT docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Stein Fletcher committed Apr 4, 2020
1 parent 49aadad commit 76fce30
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,23 @@ apitest.New().
Assert(Matches(`$.a`, `^[abc]{1,3}$`)).
End()
```

### JWT matchers

`JWTHeaderEqual` and `JWTPayloadEqual` can be used to assert on the contents of the JWT in the response (it does not verify a JWT).

```go
func TestX(t *testing.T) {
apitest.New().
HandlerFunc(myHandler).
Post("/login").
Expect(t).
Assert(jsonpath.JWTPayloadEqual(fromAuthHeader, `$.sub`, "1234567890")).
Assert(jsonpath.JWTHeaderEqual(fromAuthHeader, `$.alg`, "HS256")).
End()
}

func fromAuthHeader(res *http.Response) (string, error) {
return res.Header.Get("Authorization"), nil
}
```

0 comments on commit 76fce30

Please sign in to comment.