apex-twin 0.9.0: a webhook when the severity floor is crossed
APEX_WEBHOOK + APEX_WEBHOOK_MIN_SEVERITY (default critical) turn a finding into a JSON POST through curl, after the finding is safely on disk: - finding_add fires 'finding_added' when severity >= floor; - finding_update fires 'finding_confirmed' only on the transition into confirmed, not on every later edit (the previous status is read first); - notify_test sends one event and says whether curl accepted it; - every attempt writes an audit line with decision allow/deny and the curl exit. The webhook is operator infrastructure, not a target: it is not put through the scope gate, and it is invoked with argv, never a shell, so the JSON cannot be re-read as a command. A failing webhook never fails the finding. curl is a child process, so the binary stays libc-only. 45 tools, 222 checks. The notification test runs a local HTTP collector and asserts: critical posts, low stays quiet, confirm posts exactly once, notify_test posts, audit has the notify line, and without APEX_WEBHOOK the test answers configured=false. With the severity floor disabled, the low finding posted and the quiet check went red.
This commit is contained in:
1 parent
7db2d1173a
commit
88e7bd040f
9 files changed
+281
-13
No files matched your search
@@ -18,7 +18,7 @@ separate, explicitly armed switch.
|
||||
|
||||
```sh
|
||||
make # apex-twin, ~225 kB static-ish binary, zero warnings under -Werror
|
||||
make test # 213 end-to-end checks, no mocks
|
||||
make test # 222 end-to-end checks, no mocks
|
||||
make install # /usr/local/bin/apex-twin
|
||||
```
|
||||
|
||||
@@ -163,7 +163,20 @@ Three web checks exist because the header audit alone leaves money on the table:
|
||||
talks to port 43, so `allow_port` has to include 43; without it the gate refuses,
|
||||
which is the correct answer rather than a silent bypass.
|
||||
|
||||
## Tools (44)
|
||||
## Notifications
|
||||
|
||||
Set `APEX_WEBHOOK` to a URL and `APEX_WEBHOOK_MIN_SEVERITY` (default
|
||||
`critical`); a finding at or above the floor is POSTed as JSON after it is on
|
||||
disk, and so is the transition of a finding into `confirmed`. `notify_test` sends
|
||||
one event so the path can be proven before anyone relies on it.
|
||||
|
||||
The webhook is operator infrastructure, not a target: it is **not** put through
|
||||
the scope gate, and it is called with argv (no shell) so the JSON cannot be
|
||||
re-read as a command. A failing webhook never fails the finding — the file and
|
||||
the audit line are the product, the POST is a convenience. Without
|
||||
`APEX_WEBHOOK` nothing is sent and nothing is lost.
|
||||
|
||||
## Tools (45)
|
||||
|
||||
**Scope and bookkeeping** — `scope_show`, `scope_check` (ask the gate without
|
||||
touching anything), `scope_reload`, `capabilities`, `audit_log`, `evidence_save`
|
||||
@@ -198,6 +211,9 @@ as a lead), `xss_probe` (marked payload, returns the reflection context), `curl`
|
||||
to `$APEX_HOME/reports`), `evidence_list`, `evidence_read` (text, or base64 when
|
||||
the bytes are not text)
|
||||
|
||||
**Notifications** — `notify_test` (fire the configured webhook once and report
|
||||
whether curl accepted it)
|
||||
|
||||
Method is not decoration. `method_playbook` returns the ordered steps for a
|
||||
technique, the check that turns a lead into a finding, and the mistake that wastes
|
||||
an engagement — 12 techniques across recon, enum, web, creds, AD, wifi and report,
|
||||
@@ -245,6 +261,8 @@ APEX_SERIAL=/dev/ttyACM0 APEX_BAUD=115200
|
||||
| `APEX_DRY_RUN` | unset | `1` prints commands, runs none |
|
||||
| `APEX_DEFAULT_TIMEOUT_MS` | `60000` | per-tool default |
|
||||
| `APEX_MAX_TIMEOUT_MS` | `900000` | hard cap |
|
||||
| `APEX_WEBHOOK` | unset | URL POSTed on a finding at or above the floor |
|
||||
| `APEX_WEBHOOK_MIN_SEVERITY` | `critical` | floor for the webhook |
|
||||
|
||||
## Files it writes
|
||||
|
||||
@@ -271,7 +289,7 @@ finding and the next report no longer mentions it.
|
||||
make test
|
||||
```
|
||||
|
||||
213 checks, real binary, real DNS, real files written; no mocks. The suite was
|
||||
222 checks, real binary, real DNS, real files written; no mocks. The suite was
|
||||
seen red on purpose: with the "no scope" branch disabled by `if (0 && ...)`,
|
||||
three checks fail, because they assert the *reason* and not merely that an error
|
||||
came back — a gate that falls through to the next deny branch looks identical
|
||||
@@ -290,6 +308,8 @@ the proxy's gate call bypassed, the out-of-scope request was forwarded and three
|
||||
checks went red (403 became 502, and the audit had no deny). Forcing the CORS
|
||||
'reflected' flag to false and the cookie flags to true turned four checks red:
|
||||
the risk grade fell to low and the missing Secure/HttpOnly issues disappeared.
|
||||
Disabling the notification severity floor made a low finding post, and "a low
|
||||
finding stays quiet" went red.
|
||||
|
||||
A port is never assumed: an earlier version of the HTTP test used 18797, which on
|
||||
this host is an SSH forward to another machine, and a foreign server answered
|
||||
@@ -297,12 +317,13 @@ this host is an SSH forward to another machine, and a foreign server answered
|
||||
|
||||
## Status
|
||||
|
||||
0.8.0. Built and run: 44 tools, 213 checks. The loop closes: a probe captures
|
||||
0.9.0. Built and run: 45 tools, 222 checks. The loop closes: a probe captures
|
||||
the exchange as a pair, a finding points at it, `finding_update` gives it a
|
||||
state, an asset records the host it came from, `cors_check`/`cookie_audit`/
|
||||
`http_options` turn a web answer into a graded lead, `report_markdown` turns
|
||||
findings and inventory into one Markdown or CSV file, and
|
||||
`evidence_read`/`traffic_read` get the proof back. `--proxy` puts the same gate
|
||||
in front of curl and a browser. Not yet wired into a fleet router.
|
||||
in front of curl and a browser, and `APEX_WEBHOOK` wakes someone when the
|
||||
severity floor is crossed. Not yet wired into a fleet router.
|
||||
|
||||
Licence: AGPL-3.0, same as ARTEX.
|
||||
+3
-2
@@ -21,6 +21,7 @@ module, deliberately left out, or still open.
|
||||
| Evidence (`evidence/store.go`) | `evidence/<ts>-<label>.bin` + `evidence_save`/`_list`/`_read` | 0600 blobs, base64 on read when not text |
|
||||
| Asset inventory (`server/assets*.go`) | `src/store.c` assets + `asset_*` | One file per target, merged by target, gated on add |
|
||||
| Traffic archive (`traffic/`) | `src/store.c` traffic + `http_capture`/`traffic_*` | Request/response pair on disk; a capture is a proof |
|
||||
| Notifications (`notify/`) | `src/notify.c`, `notify_test` | Webhook via curl, severity floor, fire-and-forget, audited; not gated (operator infrastructure) |
|
||||
| Intercepting proxy (`intercept/`, `traffic/proxy.go`) | `src/proxy.c`, `--proxy` | Loopback forward proxy, gate before connect, HTTP captured, CONNECT tunnelled blind; no TLS interception, no rewrite rules |
|
||||
| Report export (`report/findings.go`) | `tools_report.c` `report_markdown` | Markdown and CSV, severity-sorted, severity and lifecycle tables, optional asset table |
|
||||
| Budgets / timeouts (`agent/budget.go`) | `APEX_DEFAULT_TIMEOUT_MS`, `APEX_MAX_TIMEOUT_MS` | Per-tool timeout, process-group kill |
|
||||
@@ -41,9 +42,9 @@ module, deliberately left out, or still open.
|
||||
|
||||
## Open
|
||||
|
||||
1. **Notifications** (`notify/`): webhook on a critical finding.
|
||||
2. **Request rewriting** (`traffic/rewrite`, `intercept`): the proxy forwards
|
||||
1. **Request rewriting** (`traffic/rewrite`, `intercept`): the proxy forwards
|
||||
and captures, but does not yet modify a request in flight on a rule.
|
||||
2. **TLS interception**: deliberately absent; CONNECT is a blind tunnel.
|
||||
|
||||
The rule for every item: it may observe or prove, it may not add a shell, and it
|
||||
must call `gated()`/`apex_scope_check()` before it opens a socket or spawns a
|
||||
|
||||
+5
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "mcp.h"
|
||||
|
||||
#define APEX_VERSION "0.8.0"
|
||||
#define APEX_VERSION "0.9.0"
|
||||
#define APEX_MAX_OUT (1u << 20)
|
||||
#define APEX_PATH_MAX 512
|
||||
#define APEX_PATH_FULL 1024
|
||||
@@ -67,6 +67,8 @@ typedef struct {
|
||||
char report_dir[APEX_PATH_MAX];
|
||||
char asset_dir[APEX_PATH_MAX];
|
||||
char traffic_dir[APEX_PATH_MAX];
|
||||
char webhook[1024];
|
||||
char webhook_min[16];
|
||||
char serial[128];
|
||||
int baud;
|
||||
int default_timeout_ms;
|
||||
@@ -143,6 +145,8 @@ int apex_finding_update(const char *id, const char *status, const char *severity
|
||||
const char *tags, const char *note);
|
||||
int apex_finding_status_valid(const char *status);
|
||||
int apex_finding_scan(apex_finding *out, int max);
|
||||
/* Load one finding by id. 0 = found, -1 = not found. */
|
||||
int apex_finding_get(const char *id, apex_finding *out);
|
||||
int apex_finding_list(mcp_buf *b, const char *target_filter, int limit);
|
||||
int apex_finding_read(const char *id, mcp_buf *b);
|
||||
|
||||
|
||||
@@ -172,6 +172,15 @@ void apex_config_init(void)
|
||||
env_int("APEX_BAUD", &g_cfg.baud);
|
||||
if (dry != NULL && (*dry == '1' || *dry == 'y' || *dry == 't'))
|
||||
g_cfg.dry_run = 1;
|
||||
{
|
||||
const char *hook = getenv("APEX_WEBHOOK");
|
||||
const char *min = getenv("APEX_WEBHOOK_MIN_SEVERITY");
|
||||
|
||||
if (hook != NULL)
|
||||
copy_str(g_cfg.webhook, sizeof(g_cfg.webhook), hook);
|
||||
copy_str(g_cfg.webhook_min, sizeof(g_cfg.webhook_min),
|
||||
min != NULL && *min != '\0' ? min : "critical");
|
||||
}
|
||||
|
||||
apex_mkdir_p(g_cfg.home, 0700);
|
||||
apex_mkdir_p(g_cfg.finding_dir, 0700);
|
||||
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* notify.c - the smallest useful notification path.
|
||||
*
|
||||
* curl is used as a child process, not linked: the binary stays libc-only and a
|
||||
* missing curl is a recorded failure, not a build dependency. --data-binary and
|
||||
* argv (not a shell) mean the JSON cannot be re-interpreted as a command.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "apex.h"
|
||||
#include "notify.h"
|
||||
|
||||
static int sev_rank(const char *s)
|
||||
{
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
if (strcasecmp(s, "critical") == 0)
|
||||
return 4;
|
||||
if (strcasecmp(s, "high") == 0)
|
||||
return 3;
|
||||
if (strcasecmp(s, "medium") == 0)
|
||||
return 2;
|
||||
if (strcasecmp(s, "low") == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int apex_notify_enabled(void)
|
||||
{
|
||||
return g_cfg.webhook[0] != '\0';
|
||||
}
|
||||
|
||||
int apex_notify_event(const char *event, const char *id, const char *target,
|
||||
const char *title, const char *severity,
|
||||
const char *status)
|
||||
{
|
||||
mcp_buf body;
|
||||
char *argv[16];
|
||||
apex_proc p;
|
||||
char reason[512];
|
||||
char *cmd;
|
||||
int i = 0;
|
||||
int rc;
|
||||
int ok;
|
||||
|
||||
if (!apex_notify_enabled())
|
||||
return 0;
|
||||
/* compare against the configured floor; unknown severities count as info */
|
||||
if (sev_rank(severity) < sev_rank(g_cfg.webhook_min))
|
||||
return 0;
|
||||
|
||||
mcp_buf_init(&body);
|
||||
mcp_buf_puts(&body, "{\"event\":");
|
||||
apex_json_str(&body, event != NULL ? event : "event");
|
||||
mcp_buf_puts(&body, ",\"id\":");
|
||||
apex_json_str(&body, id);
|
||||
mcp_buf_puts(&body, ",\"target\":");
|
||||
apex_json_str(&body, target);
|
||||
mcp_buf_puts(&body, ",\"title\":");
|
||||
apex_json_str(&body, title);
|
||||
mcp_buf_puts(&body, ",\"severity\":");
|
||||
apex_json_str(&body, severity);
|
||||
mcp_buf_puts(&body, ",\"status\":");
|
||||
apex_json_str(&body, status);
|
||||
mcp_buf_puts(&body, ",\"ts\":");
|
||||
{
|
||||
char *ts = apex_now_iso();
|
||||
|
||||
apex_json_str(&body, ts != NULL ? ts : "?");
|
||||
free(ts);
|
||||
}
|
||||
mcp_buf_puts(&body, "}");
|
||||
|
||||
argv[i++] = "curl";
|
||||
argv[i++] = "-sS";
|
||||
argv[i++] = "-X";
|
||||
argv[i++] = "POST";
|
||||
argv[i++] = "-H";
|
||||
argv[i++] = "Content-Type: application/json";
|
||||
argv[i++] = "--max-time";
|
||||
argv[i++] = "10";
|
||||
argv[i++] = "--data-binary";
|
||||
argv[i++] = body.p;
|
||||
argv[i++] = g_cfg.webhook;
|
||||
argv[i] = NULL;
|
||||
|
||||
cmd = apex_join_argv(argv);
|
||||
rc = apex_run(argv, 15000, 65536, &p);
|
||||
ok = rc == 0 && p.exit_code == 0;
|
||||
snprintf(reason, sizeof(reason), "webhook %s (curl exit %d)",
|
||||
ok ? "sent" : "failed", rc == 0 ? p.exit_code : -1);
|
||||
apex_audit("notify", g_cfg.webhook, 0, ok, reason, cmd);
|
||||
free(cmd);
|
||||
apex_proc_free(&p);
|
||||
mcp_buf_free(&body);
|
||||
return ok ? 1 : -1;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* notify.h - one webhook, fired after the finding is on disk.
|
||||
*
|
||||
* The webhook is operator infrastructure, not a target: it is configured by
|
||||
* APEX_WEBHOOK and is deliberately not put through the scope gate. A webhook
|
||||
* that fails must never fail the finding - the file and the audit line are the
|
||||
* product, the POST is a convenience.
|
||||
*/
|
||||
#ifndef APEX_NOTIFY_H
|
||||
#define APEX_NOTIFY_H
|
||||
|
||||
#include "apex.h"
|
||||
|
||||
/* 0 = nothing to send (no webhook, or below the threshold),
|
||||
* 1 = sent and curl exited 0, -1 = configured but the call failed. */
|
||||
int apex_notify_event(const char *event, const char *id, const char *target,
|
||||
const char *title, const char *severity,
|
||||
const char *status);
|
||||
int apex_notify_enabled(void);
|
||||
|
||||
#endif /* APEX_NOTIFY_H */
|
||||
+2
-2
@@ -693,7 +693,7 @@ static const char *canon_severity(const char *severity)
|
||||
|
||||
/* Read one finding through the same validated path as finding_read, then pull
|
||||
* the fields out of it. */
|
||||
static int load_finding(const char *id, apex_finding *out)
|
||||
int apex_finding_get(const char *id, apex_finding *out)
|
||||
{
|
||||
mcp_buf b;
|
||||
int rc;
|
||||
@@ -748,7 +748,7 @@ int apex_finding_update(const char *id, const char *status, const char *severity
|
||||
cv = severity != NULL && *severity != '\0' ? canon_severity(severity) : NULL;
|
||||
if (severity != NULL && *severity != '\0' && cv == NULL)
|
||||
return -2;
|
||||
if (load_finding(id, &f) != 0)
|
||||
if (apex_finding_get(id, &f) != 0)
|
||||
return -1;
|
||||
|
||||
if (cs != NULL)
|
||||
|
||||
@@ -22,11 +22,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "apex.h"
|
||||
#include "notify.h"
|
||||
#include "tools.h"
|
||||
|
||||
/* --------------------------------------------------------------- helpers */
|
||||
@@ -760,6 +762,10 @@ static void t_finding_add(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_buf_puts(&b, "}");
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
(void)apex_notify_event("finding_added", id, target, title,
|
||||
severity != NULL && *severity != '\0' ? severity
|
||||
: "info",
|
||||
"open");
|
||||
free(id);
|
||||
}
|
||||
|
||||
@@ -809,6 +815,8 @@ static void t_finding_update(mcp_conn *c, const mcp_json *args, void *user)
|
||||
const char *note = mcp_arg_string(args, "note");
|
||||
mcp_buf b;
|
||||
int rc;
|
||||
apex_finding before;
|
||||
int had_before;
|
||||
|
||||
(void)user;
|
||||
if (id == NULL || *id == '\0') {
|
||||
@@ -822,6 +830,7 @@ static void t_finding_update(mcp_conn *c, const mcp_json *args, void *user)
|
||||
mcp_reply_error(c, "nothing to update: pass at least one field");
|
||||
return;
|
||||
}
|
||||
had_before = apex_finding_get(id, &before) == 0;
|
||||
rc = apex_finding_update(id, status, severity, confidence, remediation, tags,
|
||||
note);
|
||||
if (rc == -1) {
|
||||
@@ -833,6 +842,17 @@ static void t_finding_update(mcp_conn *c, const mcp_json *args, void *user)
|
||||
"severity info|low|medium|high|critical");
|
||||
return;
|
||||
}
|
||||
{
|
||||
apex_finding after;
|
||||
|
||||
/* notify on the transition into confirmed, not on every later edit */
|
||||
if (apex_finding_get(id, &after) == 0 &&
|
||||
strcasecmp(after.status, "confirmed") == 0 &&
|
||||
(!had_before || strcasecmp(before.status, "confirmed") != 0))
|
||||
(void)apex_notify_event("finding_confirmed", after.id,
|
||||
after.target, after.title,
|
||||
after.severity, after.status);
|
||||
}
|
||||
mcp_buf_init(&b);
|
||||
if (apex_finding_read(id, &b) != 0) {
|
||||
mcp_buf_free(&b);
|
||||
@@ -861,6 +881,29 @@ static void t_whois(mcp_conn *c, const mcp_json *args, void *user)
|
||||
(void)gated_cmd(c, "whois", target, 43, argv, timeout, NULL);
|
||||
}
|
||||
|
||||
static void t_notify_test(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
mcp_buf b;
|
||||
int rc = 0;
|
||||
|
||||
(void)args;
|
||||
(void)user;
|
||||
mcp_buf_init(&b);
|
||||
if (!apex_notify_enabled()) {
|
||||
mcp_buf_puts(&b, "{\"configured\":false,\"sent\":false,\"reason\":"
|
||||
"\"APEX_WEBHOOK is not set\"}");
|
||||
} else {
|
||||
rc = apex_notify_event("test", "notify-test", "127.0.0.1",
|
||||
"APEX TWIN test event", "critical", "test");
|
||||
mcp_buf_printf(&b, "{\"configured\":true,\"sent\":%s,"
|
||||
"\"reason\":\"%s\"}", rc == 1 ? "true" : "false",
|
||||
rc == 1 ? "webhook accepted the event"
|
||||
: "curl failed; see audit.log");
|
||||
}
|
||||
mcp_reply_json(c, b.p);
|
||||
mcp_buf_free(&b);
|
||||
}
|
||||
|
||||
static void t_capabilities(mcp_conn *c, const mcp_json *args, void *user)
|
||||
{
|
||||
static const char *progs[] = { "nmap", "dig", "host", "openssl", "curl",
|
||||
@@ -1061,6 +1104,13 @@ const mcp_tool TOOLS_RECON[] = {
|
||||
"whether the run is a dry run. Use it once at the start of an engagement.",
|
||||
"{\"type\":\"object\",\"properties\":{}}",
|
||||
t_capabilities },
|
||||
{ "notify_test",
|
||||
"Send one test event to the configured webhook and report whether curl "
|
||||
"accepted it. Use it after setting APEX_WEBHOOK, before relying on a "
|
||||
"critical finding to wake someone up. Without APEX_WEBHOOK it answers "
|
||||
"configured=false and sends nothing.",
|
||||
"{\"type\":\"object\",\"properties\":{}}",
|
||||
t_notify_test },
|
||||
};
|
||||
|
||||
const size_t TOOLS_RECON_N = sizeof(TOOLS_RECON) / sizeof(TOOLS_RECON[0]);
|
||||
+65
-3
@@ -101,14 +101,15 @@ res, _ = run([
|
||||
], home=empty)
|
||||
check("tools/list answers", any(r.get("id") == 1 for r in res))
|
||||
tools = [r for r in res if r.get("id") == 1][0]["result"]["tools"]
|
||||
check("44 tools registered", len(tools) == 44, len(tools))
|
||||
check("45 tools registered", len(tools) == 45, len(tools))
|
||||
names = {t["name"] for t in tools}
|
||||
for need in ("portscan", "nmap", "http_request", "marauder_scan",
|
||||
"method_playbook", "finding_add", "finding_update", "scope_check",
|
||||
"report_markdown", "evidence_list", "evidence_read",
|
||||
"guard_check", "asset_add", "asset_list", "asset_read",
|
||||
"asset_update", "http_capture", "traffic_list", "traffic_read",
|
||||
"whois", "cors_check", "cookie_audit", "http_options"):
|
||||
"whois", "cors_check", "cookie_audit", "http_options",
|
||||
"notify_test"):
|
||||
check("tool present: " + need, need in names)
|
||||
for r in res:
|
||||
if r.get("id") in (2, 3, 4):
|
||||
@@ -701,6 +702,67 @@ check("whois refuses an out-of-scope target", err(res[1]), text(res[1]))
|
||||
check("whois refusal names the scope", "outside allow_ip" in text(res[1]),
|
||||
text(res[1]))
|
||||
|
||||
print("\n== notifications ==")
|
||||
posts = []
|
||||
|
||||
|
||||
class _HookHandler(http.server.BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
n = int(self.headers.get("Content-Length", "0"))
|
||||
body = self.rfile.read(n)
|
||||
posts.append(json.loads(body.decode()))
|
||||
self.send_response(204)
|
||||
self.send_header("Content-Length", "0")
|
||||
self.end_headers()
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
hook = http.server.HTTPServer(("127.0.0.1", 0), _HookHandler)
|
||||
hport = hook.server_address[1]
|
||||
threading.Thread(target=hook.serve_forever, daemon=True).start()
|
||||
hook_env = {"APEX_WEBHOOK": "http://127.0.0.1:%d/hook" % hport,
|
||||
"APEX_WEBHOOK_MIN_SEVERITY": "high"}
|
||||
try:
|
||||
res, _ = run([
|
||||
call(1, "finding_add", target="example.com", title="Notify me",
|
||||
severity="critical"),
|
||||
call(2, "finding_add", target="example.com", title="Quiet one",
|
||||
severity="low"),
|
||||
call(3, "notify_test"),
|
||||
call(4, "audit_log", limit=200),
|
||||
], extra_env=hook_env)
|
||||
by_id = {r.get("id"): r for r in res}
|
||||
nid = json.loads(text(by_id[1]))["id"]
|
||||
res2, _ = run([
|
||||
call(1, "finding_update", id=nid, status="confirmed"),
|
||||
], extra_env=hook_env)
|
||||
check("confirming a finding succeeds", not err(res2[0]), text(res2[0]))
|
||||
finally:
|
||||
hook.shutdown()
|
||||
hook.server_close()
|
||||
|
||||
events = [p["event"] for p in posts]
|
||||
check("a critical finding fires the webhook", "finding_added" in events, posts)
|
||||
check("the payload carries the title and severity",
|
||||
any(p["title"] == "Notify me" and p["severity"] == "critical"
|
||||
for p in posts), posts)
|
||||
check("a low finding stays quiet",
|
||||
not any(p["title"] == "Quiet one" for p in posts), posts)
|
||||
check("confirming fires exactly once",
|
||||
events.count("finding_confirmed") == 1, events)
|
||||
check("notify_test sends a test event", "test" in events, events)
|
||||
check("notification is audited",
|
||||
any(e["tool"] == "notify" and e["decision"] == "allow"
|
||||
for e in json.loads(text(by_id[4]))),
|
||||
[e for e in json.loads(text(by_id[4])) if e["tool"] == "notify"][:2])
|
||||
|
||||
res, _ = run([call(1, "notify_test")])
|
||||
quiet = json.loads(text(res[0]))
|
||||
check("without a webhook the test says so", quiet["configured"] is False,
|
||||
quiet)
|
||||
|
||||
# --------------------------------------------------------------- transport
|
||||
print("\n== http transport ==")
|
||||
|
||||
@@ -745,7 +807,7 @@ try:
|
||||
check("http initialize", init["result"]["serverInfo"]["name"] == "apex-twin",
|
||||
init)
|
||||
listing = post({"jsonrpc": "2.0", "id": 2, "method": "tools/list"})
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 44)
|
||||
check("http tools/list", len(listing["result"]["tools"]) == 45)
|
||||
shown = post(call(3, "scope_show"))
|
||||
check("http scope_show", '"loaded":true' in shown["result"]["content"][0]["text"])
|
||||
# the id must be the request's id, not one found inside the arguments
|
||||
|
||||
Reference in new issue
Block a user