Skip to content

Commit c74473e

Browse files
authored
Feat[TESTS]: Add fuzz-tests for subscriptions (#1226)
Signed-off-by: Anton Pryakhin <apryakhin1@bloomberg.net>
1 parent a4cb800 commit c74473e

4 files changed

Lines changed: 46 additions & 3 deletions

File tree

.github/workflows/build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ jobs:
185185
"negotiation_bypass_authentication",
186186
"negotiation",
187187
"open_queue",
188+
"configure_stream",
188189
"configure_queue_stream",
189190
"put",
190191
"confirm",

src/python/blazingmq/dev/fuzztest/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ handle all messages gracefully, even if message is malformed.
99

1010
# Launching #
1111

12-
- Build the BlazingMQ broker (the build dir might be `cmake.bld/Linux/src/applications/bmqbrkr`)
12+
- Build the BlazingMQ broker (the build dir might be `build/blazingmq/src/applications/bmqbrkr`)
1313

1414
- Set up the repo dir for convenience
1515

@@ -22,13 +22,13 @@ export BLAZINGMQ_REPO=`pwd`
2222
```shell
2323
python3 -m venv ${BLAZINGMQ_REPO}/venv
2424
source ${BLAZINGMQ_REPO}/venv/bin/activate
25-
pip3 install -r "${BLAZINGMQ_REPO}/src/python/blazingmq/dev/requirements.txt"
25+
pip3 install -r "${BLAZINGMQ_REPO}/src/python/requirements-dev.txt"
2626
```
2727

2828
- Launch fuzz testing:
2929

3030
```shell
3131
source ${BLAZINGMQ_REPO}/venv/bin/activate
3232
cd ${BLAZINGMQ_REPO}/src/python
33-
python3 -m blazingmq.dev.fuzztest --broker-dir "${BLAZINGMQ_REPO}/cmake.bld/Linux/src/applications/bmqbrkr"
33+
python3 -m blazingmq.dev.fuzztest --broker-dir "${BLAZINGMQ_REPO}/build/blazingmq/src/applications/bmqbrkr"
3434
```

src/python/blazingmq/dev/fuzztest/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ def schema_to_boofuzz(schema: broker.SchemaDescription) -> BoofuzzSequence:
110110

111111
if isinstance(value, dict):
112112
res += schema_to_boofuzz(value)
113+
elif isinstance(value, list):
114+
res.append(boofuzz.Static(default_value="["))
115+
for item in value:
116+
res += schema_to_boofuzz(item)
117+
res.append(boofuzz.Delim(default_value=",", fuzzable=fuzz_delimiters))
118+
# last boofuzz.Delim "," should be removed if presented
119+
if len(value) > 0:
120+
res = res[:-1]
121+
res.append(boofuzz.Static(default_value="]"))
113122
elif isinstance(value, str):
114123
res.append(boofuzz.String(default_value=f'"{value}"'))
115124
elif isinstance(value, bool):
@@ -397,6 +406,11 @@ def fuzz(host: str, port: int, request: Optional[str] = None) -> None:
397406
"OpenQueue", children=(make_control_message(broker.OPEN_QUEUE_SCHEMA))
398407
)
399408

409+
configure_stream = boofuzz.Request(
410+
"ConfigureStream",
411+
children=(make_control_message(broker.CONFIGURE_STREAM_SCHEMA)),
412+
)
413+
400414
configure_queue_stream = boofuzz.Request(
401415
"ConfigureQueueStream",
402416
children=(make_control_message(broker.CONFIGURE_QUEUE_STREAM_SCHEMA)),
@@ -418,6 +432,7 @@ def fuzz(host: str, port: int, request: Optional[str] = None) -> None:
418432
(authentication, "authentication"),
419433
(negotiation, "negotiation"),
420434
(open_queue, "open_queue"),
435+
(configure_stream, "configure_stream"),
421436
(configure_queue_stream, "configure_queue_stream"),
422437
(put, "put"),
423438
(confirm, "confirm"),

src/python/blazingmq/schemas/broker.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,33 @@ class PutHeaderFlags(IntFlag):
103103
}
104104
}
105105

106+
CONFIGURE_STREAM_SCHEMA: SchemaDescription = {
107+
"rId": 0,
108+
"configureStream": {
109+
"qId": 0,
110+
"streamParameters": {
111+
"appId": "__default",
112+
"subscriptions": [
113+
{
114+
"sId": 0,
115+
"expression": {
116+
"version": "E_VERSION_1",
117+
"text": "test_expression",
118+
},
119+
"consumers": [
120+
{
121+
"maxUnconfirmedMessages": 0,
122+
"maxUnconfirmedBytes": 0,
123+
"consumerPriority": -2147483648,
124+
"consumerPriorityCount": 0,
125+
},
126+
],
127+
},
128+
],
129+
},
130+
},
131+
}
132+
106133
CONFIGURE_QUEUE_STREAM_SCHEMA: SchemaDescription = {
107134
"rId": 0,
108135
"configureQueueStream": {

0 commit comments

Comments
 (0)