Skip to content

Commit

Permalink
fix: added support for JSON bodies of type array and literals (Fixes #54
Browse files Browse the repository at this point in the history
)
  • Loading branch information
acy-norman committed May 23, 2024
1 parent aabd920 commit 8d28c6a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ type PayloadInput struct {
Headers map[string][]string `json:"headers"`
JWTHeader JwtHeader `json:"tokenHeader"`
JWTPayload map[string]interface{} `json:"tokenPayload"`
Body map[string]interface{} `json:"body,omitempty"`
Body interface{} `json:"body,omitempty"`
Form url.Values `json:"form,omitempty"`
}

Expand Down
24 changes: 23 additions & 1 deletion jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestServeOPAWithBody(t *testing.T) {
contentType string
body string
allowed bool
expectedBody map[string]interface{}
expectedBody interface{}
expectedForm url.Values
expectedStatus int
drainBody bool
Expand All @@ -144,6 +144,28 @@ func TestServeOPAWithBody(t *testing.T) {
expectedStatus: http.StatusOK,
drainBody: true,
},
{
name: "jsonArray",
method: "POST",
contentType: "application/json",
body: `[ "killroy", "washere" ]`,
allowed: true,
expectedBody: []interface{}{
"killroy", "washere",
},
expectedStatus: http.StatusOK,
drainBody: true,
},
{
name: "jsonLiteral",
method: "POST",
contentType: "application/json",
body: `"killroy"`,
allowed: true,
expectedBody: "killroy",
expectedStatus: http.StatusOK,
drainBody: true,
},
{
name: "nobody",
method: "POST",
Expand Down

0 comments on commit 8d28c6a

Please sign in to comment.