Skip to content

Commit 12a6076

Browse files
acy-normaneshepelyuk
authored andcommitted
fix: added support for JSON bodies of type array and literals (Fixes #54)
1 parent aabd920 commit 12a6076

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

jwt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ type PayloadInput struct {
159159
Headers map[string][]string `json:"headers"`
160160
JWTHeader JwtHeader `json:"tokenHeader"`
161161
JWTPayload map[string]interface{} `json:"tokenPayload"`
162-
Body map[string]interface{} `json:"body,omitempty"`
162+
Body interface{} `json:"body,omitempty"`
163163
Form url.Values `json:"form,omitempty"`
164164
}
165165

jwt_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestServeOPAWithBody(t *testing.T) {
121121
contentType string
122122
body string
123123
allowed bool
124-
expectedBody map[string]interface{}
124+
expectedBody interface{}
125125
expectedForm url.Values
126126
expectedStatus int
127127
drainBody bool
@@ -144,6 +144,28 @@ func TestServeOPAWithBody(t *testing.T) {
144144
expectedStatus: http.StatusOK,
145145
drainBody: true,
146146
},
147+
{
148+
name: "jsonArray",
149+
method: "POST",
150+
contentType: "application/json",
151+
body: `[ "killroy", "washere" ]`,
152+
allowed: true,
153+
expectedBody: []interface{}{
154+
"killroy", "washere",
155+
},
156+
expectedStatus: http.StatusOK,
157+
drainBody: true,
158+
},
159+
{
160+
name: "jsonLiteral",
161+
method: "POST",
162+
contentType: "application/json",
163+
body: `"killroy"`,
164+
allowed: true,
165+
expectedBody: "killroy",
166+
expectedStatus: http.StatusOK,
167+
drainBody: true,
168+
},
147169
{
148170
name: "nobody",
149171
method: "POST",

0 commit comments

Comments
 (0)