Skip to content

Commit

Permalink
server/server_test: Add new testcase.
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Conrad <[email protected]>
  • Loading branch information
philipaconrad committed Jun 26, 2024
1 parent 42d6c27 commit 0af6be7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,27 @@ func mustGZIPPayload(payload []byte) []byte {
return compressedPayload.Bytes()
}

// generateJSONBenchmarkData returns a map of `k` keys and `v` key/value pairs.
// Taken from topdown/topdown_bench_test.go
func generateJSONBenchmarkData(k, v int) map[string]interface{} {
// create array of null values that can be iterated over
keys := make([]interface{}, k)
for i := range keys {
keys[i] = nil
}

// create large JSON object value (100,000 entries is about 2MB on disk)
values := map[string]interface{}{}
for i := 0; i < v; i++ {
values[fmt.Sprintf("key%d", i)] = fmt.Sprintf("value%d", i)
}

return map[string]interface{}{
"keys": keys,
"values": values,
}
}

// Ref: https://github.com/open-policy-agent/opa/issues/6804
func TestDataGetV1CompressedRequestWithAuthorizer(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -1729,6 +1750,11 @@ func TestDataGetV1CompressedRequestWithAuthorizer(t *testing.T) {
expRespHTTPStatus: 200,
forcePayloadSizeField: 134217728, // 128 MB
},
{
note: "basic authz - huge zip",
payload: mustGZIPPayload(util.MustMarshalJSON(generateJSONBenchmarkData(100, 100))),
expRespHTTPStatus: 401,
},
}

for _, test := range tests {
Expand Down

0 comments on commit 0af6be7

Please sign in to comment.