From 76fce30fefeae508298fc029358324f08ae37a79 Mon Sep 17 00:00:00 2001 From: Stein Fletcher Date: Sat, 4 Apr 2020 11:21:44 +0100 Subject: [PATCH] Add JWT docs --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 14cdeaf..8d654f0 100644 --- a/README.md +++ b/README.md @@ -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 +} +``` \ No newline at end of file