mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-12 19:55:14 +02:00
refactor(dynamic): add broker loopback stubs for Kafka, SQS, Pub/Sub, RabbitMQ, and NATS, enhance stub initialization and event recording logic across supported languages, and expand test coverage
This commit is contained in:
parent
170d2028d0
commit
c57cd233fc
8 changed files with 346 additions and 2 deletions
|
|
@ -1367,7 +1367,7 @@ fn generate_go_mod(shape: GoShape) -> String {
|
|||
if !deps.is_empty() {
|
||||
out.push_str("\nrequire (\n");
|
||||
for (module, version) in deps {
|
||||
out.push_str("\t");
|
||||
out.push('\t');
|
||||
out.push_str(module);
|
||||
out.push(' ');
|
||||
out.push_str(version);
|
||||
|
|
@ -2120,6 +2120,7 @@ fn emit_message_handler_harness(spec: &HarnessSpec, queue: &str) -> HarnessSourc
|
|||
nyxDispatch(msg)
|
||||
}})
|
||||
fmt.Println("{publish_marker} " + "{queue}")
|
||||
nyxRecordBrokerPublish("NYX_NATS_LOG", "{queue}", payload)
|
||||
broker.Publish("{queue}", payload)"##,
|
||||
queue = queue,
|
||||
publish_marker = crate::dynamic::stubs::NATS_PUBLISH_MARKER,
|
||||
|
|
@ -2134,6 +2135,7 @@ fn emit_message_handler_harness(spec: &HarnessSpec, queue: &str) -> HarnessSourc
|
|||
nyxDispatch(msg)
|
||||
}})
|
||||
fmt.Println("{publish_marker} " + "{queue}")
|
||||
nyxRecordBrokerPublish("NYX_PUBSUB_LOG", "{queue}", payload)
|
||||
broker.Publish("{queue}", payload)"##,
|
||||
queue = queue,
|
||||
publish_marker = crate::dynamic::stubs::PUBSUB_PUBLISH_MARKER,
|
||||
|
|
@ -2214,6 +2216,19 @@ func nyxPayload() string {{
|
|||
return ""
|
||||
}}
|
||||
|
||||
func nyxRecordBrokerPublish(envName string, destination string, payload string) {{
|
||||
path := os.Getenv(envName)
|
||||
if path == "" {{
|
||||
return
|
||||
}}
|
||||
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||
if err != nil {{
|
||||
return
|
||||
}}
|
||||
defer f.Close()
|
||||
_, _ = fmt.Fprintf(f, "%s\t%s\n", strings.ReplaceAll(destination, "\t", " "), payload)
|
||||
}}
|
||||
|
||||
func main() {{
|
||||
__nyx_install_crash_guard("{handler}")
|
||||
payload := nyxPayload()
|
||||
|
|
|
|||
|
|
@ -3502,6 +3502,7 @@ fn emit_message_handler_harness(
|
|||
}}
|
||||
}});
|
||||
System.out.println({publish_marker:?} + " " + {queue:?});
|
||||
nyxRecordBrokerPublish("NYX_SQS_LOG", {queue:?}, payload);
|
||||
brokerRef.publish({queue:?}, payload);"#,
|
||||
handler = handler,
|
||||
queue = queue,
|
||||
|
|
@ -3533,6 +3534,7 @@ fn emit_message_handler_harness(
|
|||
}}
|
||||
}});
|
||||
System.out.println({publish_marker:?} + " " + {queue:?});
|
||||
nyxRecordBrokerPublish("NYX_RABBIT_LOG", {queue:?}, payload);
|
||||
chan.basicPublish("", {queue:?}, payload);"#,
|
||||
handler = handler,
|
||||
queue = queue,
|
||||
|
|
@ -3555,6 +3557,7 @@ fn emit_message_handler_harness(
|
|||
}}
|
||||
}});
|
||||
System.out.println({publish_marker:?} + " " + {queue:?});
|
||||
nyxRecordBrokerPublish("NYX_KAFKA_LOG", {queue:?}, payload);
|
||||
brokerRef.publish({queue:?}, payload);"#,
|
||||
handler = handler,
|
||||
queue = queue,
|
||||
|
|
@ -3599,6 +3602,21 @@ public class NyxHarness {{
|
|||
}}
|
||||
return "";
|
||||
}}
|
||||
|
||||
static void nyxRecordBrokerPublish(String envName, String destination, String payload) {{
|
||||
String path = System.getenv(envName);
|
||||
if (path == null || path.isEmpty()) return;
|
||||
String line = destination.replace('\t', ' ') + "\t" + payload + "\n";
|
||||
try {{
|
||||
java.nio.file.Files.write(
|
||||
java.nio.file.Paths.get(path),
|
||||
line.getBytes(java.nio.charset.StandardCharsets.UTF_8),
|
||||
java.nio.file.StandardOpenOption.CREATE,
|
||||
java.nio.file.StandardOpenOption.APPEND
|
||||
);
|
||||
}} catch (Exception ignored) {{
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
"#,
|
||||
entry_class = entry_class,
|
||||
|
|
|
|||
|
|
@ -920,6 +920,17 @@ if (typeof _handler !== 'function') {{
|
|||
}}
|
||||
|
||||
const _broker = new NyxSqsLoopback();
|
||||
function _nyxRecordBrokerPublish(envName, destination, body) {{
|
||||
const path = process.env[envName] || '';
|
||||
if (!path) return;
|
||||
try {{
|
||||
require('fs').appendFileSync(
|
||||
path,
|
||||
String(destination).replace(/\t/g, ' ') + '\t' + String(body) + '\n',
|
||||
'utf8'
|
||||
);
|
||||
}} catch (_) {{}}
|
||||
}}
|
||||
_broker.subscribe({queue:?}, async (envelope) => {{
|
||||
try {{
|
||||
// Sink-reachability sentinel — runner's `vuln_fired && sink_hit`
|
||||
|
|
@ -933,6 +944,7 @@ _broker.subscribe({queue:?}, async (envelope) => {{
|
|||
|
||||
(async () => {{
|
||||
process.stdout.write({publish_marker:?} + ' ' + {queue:?} + '\n');
|
||||
_nyxRecordBrokerPublish('NYX_SQS_LOG', {queue:?}, payload);
|
||||
_broker.publish({queue:?}, payload);
|
||||
}})();
|
||||
"#,
|
||||
|
|
|
|||
|
|
@ -958,6 +958,7 @@ def _nyx_sqs_dispatch(envelope):
|
|||
_h(envelope)
|
||||
_loop.subscribe({queue:?}, _nyx_sqs_dispatch)
|
||||
print({publish_marker:?} + " " + {queue:?}, flush=True)
|
||||
_nyx_record_broker_publish("NYX_SQS_LOG", {queue:?}, payload)
|
||||
_loop.publish({queue:?}, payload)"#,
|
||||
handler = handler,
|
||||
queue = queue,
|
||||
|
|
@ -973,6 +974,7 @@ def _nyx_pubsub_dispatch(message):
|
|||
_h(message)
|
||||
_loop.subscribe({queue:?}, _nyx_pubsub_dispatch)
|
||||
print({publish_marker:?} + " " + {queue:?}, flush=True)
|
||||
_nyx_record_broker_publish("NYX_PUBSUB_LOG", {queue:?}, payload)
|
||||
_loop.publish({queue:?}, payload)"#,
|
||||
handler = handler,
|
||||
queue = queue,
|
||||
|
|
@ -988,6 +990,7 @@ def _nyx_rabbit_dispatch(ch, method, props, body):
|
|||
_h(ch, method, props, body)
|
||||
_chan.basic_consume(queue={queue:?}, on_message_callback=_nyx_rabbit_dispatch)
|
||||
print({publish_marker:?} + " " + {queue:?}, flush=True)
|
||||
_nyx_record_broker_publish("NYX_RABBIT_LOG", {queue:?}, payload)
|
||||
_chan.basic_publish(exchange="", routing_key={queue:?}, body=payload)"#,
|
||||
handler = handler,
|
||||
queue = queue,
|
||||
|
|
@ -1003,6 +1006,7 @@ def _nyx_kafka_dispatch(message):
|
|||
_h(message)
|
||||
_loop.subscribe({queue:?}, _nyx_kafka_dispatch)
|
||||
print({publish_marker:?} + " " + {queue:?}, flush=True)
|
||||
_nyx_record_broker_publish("NYX_KAFKA_LOG", {queue:?}, payload)
|
||||
_loop.publish({queue:?}, payload)"#,
|
||||
handler = handler,
|
||||
queue = queue,
|
||||
|
|
@ -1017,6 +1021,16 @@ _loop.publish({queue:?}, payload)"#,
|
|||
{pubsub_src}
|
||||
{rabbit_src}
|
||||
|
||||
def _nyx_record_broker_publish(env_name, destination, body):
|
||||
path = os.environ.get(env_name, "")
|
||||
if not path:
|
||||
return
|
||||
try:
|
||||
with open(path, "a", encoding="utf-8") as f:
|
||||
f.write(str(destination).replace("\t", " ") + "\t" + str(body) + "\n")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
{register_and_publish}
|
||||
except SystemExit as _e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue