[fuzz] split http filter logic into a fuzzing class#13016
[fuzz] split http filter logic into a fuzzing class#13016htuch merged 2 commits intoenvoyproxy:masterfrom
Conversation
Signed-off-by: Asra Ali <asraa@google.com>
|
\cc @nareddyt This is my attempt at cleaning up the design for fuzzing http filters... We have a base HttpFilterFuzzer library that can truly be applied to any filter without extra mocks or any set-up needed. It just holds onto the filter decoding/encoding logic. If you import this it would mean changing UberFilterFuzzer to HttpFilterFuzzer. It should increase the speed of the fuzzer drastically. WDYT? I could also implement these outside of a class, but I wouldn't be able to hold onto the headermaps for access logging. Open to suggestions. |
|
This is great, thanks @asraa! I was brainstorming a way of simplifying this a few months ago, but I was trying to use composition instead of inheritance and had some issues with holding onto the header maps. Your solution works really well and it seems clean to me. I'll be sure to switch over ESPv2 (maybe in the next month) and try collect some metrics on the performance improvement. I'm curious how much improvement we'll see from removing mocks, though we might still have to mock the |
htuch
left a comment
There was a problem hiding this comment.
LGTM, thanks! The comment applies to existing code.
| return status; | ||
| } | ||
|
|
||
| template <> |
There was a problem hiding this comment.
The logic of handling filter return status and end_stream values in runData is the common for encoders/decoder, so we meant to share that across both encoder/decoder despite different methods.
There were some alternatives considered here #11209, one of which was adding a lambda in for the correct header/data/trailer funcs (encodeHeaders, decodeHeaders), and having the runData use those lambda HeaderFunc, DataFunc, TrailerFunc depending on if it's encoder or decoder.
If I were to de-template this, it's not too much additional work. The lambdas (Header/Data/Trailer)Funcs are the template send(Header/Data/Trailer) specializations. I guess it also depends on what API is exposed to the fuzzer:
runData(FilterType, data) vs runEncode(encoder, data) and runDecode(decoder, data)
where runEncode(encoder, data) calls runData with the appropriate lambas. I was happy with both.
There was a problem hiding this comment.
FYI if we don't template these functions, then you have to duplicate all the code in runData, right?
envoy/test/extensions/filters/http/common/fuzz/http_filter_fuzzer.h
Lines 84 to 114 in d60073c
There was a problem hiding this comment.
I don't think so. runData's signature could be
runData(FilterType* filter, const test::fuzz::HttpData& data, HeaderFunc header_func, DataFunc data_func, TrailerFunc trailer_func)
and runEncode(encoder, data) would call runData with the right funcs (the specializations of sendHeaders/sendData/sendTrailers)
Edit: maybe because of encoder/decoder typing there'd need to be type downcasting... I'll just give it a shot
Signed-off-by: Asra Ali <asraa@google.com>
…code * upstream/master: lint: add more linters for using absl:: over std:: (envoyproxy#13043) udpa: filesystem list collection support for inline entries. (envoyproxy#13028) filter: http: jwt: implement matching for HTTP CONNECT (envoyproxy#13064) [fuzz] split http filter logic into a fuzzing class (envoyproxy#13016) xds: allow empty delta update (envoyproxy#12699) CacheFilter: parses the allowed_vary_headers from the cache config. (envoyproxy#12928) router: extend HTTP CONNECT route matching criteria (envoyproxy#13056) docs: clarify use of Extended CONNECT for h/2 (envoyproxy#13051) build: shellcheck tools/ (envoyproxy#13007) [fuzz] Refactored Health Checker Impl Tests (envoyproxy#13017) Signed-off-by: Lihao Luo <lihao@squareup.com>
Signed-off-by: Asra Ali asraa@google.com
Commit Message: This splits out the "filter manager" logic that the HTTP filter fuzzer uses into a lightweight HttpFilterFuzzer class. The logic implemented control the flow for calling decode(Headers/Data/Trailers) and encode(Headers/Data/Trailers). Users of this class now create a filter, set callbacks, and then call
HttpFilterFuzzer::runData(filter, fuzzed_data). See example (https://github.com/GoogleCloudPlatform/esp-v2/blob/e86330b106484eb3734dc207a3ab9419f9dcb903/src/envoy/http/path_matcher/filter_fuzz_test.cc#L59). It could be done before, but UberFilterFuzzer held much more state than necessary to apply to a dedicated fuzzer.The UberFilterFuzzer extends this and holds the logic to generically create and set up filters. It uses this HttpFilterFuzzer library for the headers, data, trailer logic calls. Now all state needed for all filters is held in UberFilterFuzzer.
Risk Level: Low
Testing: filter_fuzz_test still works, this is a no-op
Follow-up PRs: