Skip to content

Commit 76fce30

Browse files
author
Stein Fletcher
committed
Add JWT docs
1 parent 49aadad commit 76fce30

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,23 @@ apitest.New().
115115
Assert(Matches(`$.a`, `^[abc]{1,3}$`)).
116116
End()
117117
```
118+
119+
### JWT matchers
120+
121+
`JWTHeaderEqual` and `JWTPayloadEqual` can be used to assert on the contents of the JWT in the response (it does not verify a JWT).
122+
123+
```go
124+
func TestX(t *testing.T) {
125+
apitest.New().
126+
HandlerFunc(myHandler).
127+
Post("/login").
128+
Expect(t).
129+
Assert(jsonpath.JWTPayloadEqual(fromAuthHeader, `$.sub`, "1234567890")).
130+
Assert(jsonpath.JWTHeaderEqual(fromAuthHeader, `$.alg`, "HS256")).
131+
End()
132+
}
133+
134+
func fromAuthHeader(res *http.Response) (string, error) {
135+
return res.Header.Get("Authorization"), nil
136+
}
137+
```

0 commit comments

Comments
 (0)