High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
test(extract): e2e asserts the vocabulary token and tab id match between headers and body, a stale token is refused, the tab route targets the navigated tab, and an injected extracted value warns and blocks (PIN-393)
Luigi Agosti94b59e5a5dde
diff --git a/tests/e2e/scenarios/api/extract-basic.sh b/tests/e2e/scenarios/api/extract-basic.shindex 0959b811..66c58f60 100755--- a/tests/e2e/scenarios/api/extract-basic.sh+++ b/tests/e2e/scenarios/api/extract-basic.sh@@ -31,6 +31,40 @@ assert_ok "click on the name ref proves the ref is live"end_test+# ─────────────────────────────────────────────────────────────────+start_test "extract: vocabulary token and tab id match between headers and body"++pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/extract-product.html\"}"+assert_ok "navigate to extract-product.html"+TAB_ID=$(echo "$RESULT" | jq -r '.tabId')++EXTRACT_HEADERS=$(mktemp)+RESULT=$(e2e_curl -s -D "$EXTRACT_HEADERS" -X POST "${E2E_SERVER}/extract" -H "Content-Type: application/json" -d "{\"schema\":${PRODUCT_SCHEMA}}")+HEADER_VOCAB=$(grep -i '^X-PinchTab-Vocab:' "$EXTRACT_HEADERS" | cut -d' ' -f2 | tr -d '\r')+HEADER_TAB=$(grep -i '^X-PinchTab-Tab-Id:' "$EXTRACT_HEADERS" | cut -d' ' -f2 | tr -d '\r')+rm -f "$EXTRACT_HEADERS"+BODY_VOCAB=$(echo "$RESULT" | jq -r '.vocabularyToken')++if [ -n "$BODY_VOCAB" ] && [ "$BODY_VOCAB" != "null" ] && [ "$BODY_VOCAB" = "$HEADER_VOCAB" ]; then+ pass_assert "body vocabularyToken $BODY_VOCAB matches X-PinchTab-Vocab"+else+ fail_assert "body vocabularyToken '$BODY_VOCAB' vs X-PinchTab-Vocab '$HEADER_VOCAB'"+fi+if [ "$HEADER_TAB" = "$TAB_ID" ]; then+ pass_assert "X-PinchTab-Tab-Id names the navigated tab"+else+ fail_assert "X-PinchTab-Tab-Id '$HEADER_TAB', want '$TAB_ID'"+fi++NAME_REF=$(echo "$RESULT" | jq -r '.fields.name.ref')+pt_post /action -d "{\"kind\":\"click\",\"ref\":\"${NAME_REF}\",\"vocab\":\"${BODY_VOCAB}\"}"+assert_ok "an action echoing the extract's own token is accepted"++pt_post /action -d "{\"kind\":\"click\",\"ref\":\"${NAME_REF}\",\"vocab\":\"stale-pre-extract-token\"}"+assert_http_status 409 "a pre-extract token is refused vocab_superseded"++end_test+# ─────────────────────────────────────────────────────────────────start_test "extract: array schema, scoped table, and maxItems on extract-list.html"@@ -69,9 +103,10 @@ assert_http_status 404 "bogus tabId"pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/extract-list.html\"}"assert_ok "navigate to extract-list.html for the tab route"+LIST_TAB=$(echo "$RESULT" | jq -r '.tabId')pt_get /tabsassert_ok "list tabs"-LIST_TAB=$(echo "$RESULT" | jq -r '.tabs[0].id // .tabs[0].tabId')+assert_json_eq "$RESULT" "[.tabs[] | (.id // .tabId)] | index(\"${LIST_TAB}\") != null" 'true' "/tabs lists the navigated tab"pt_post "/tabs/${LIST_TAB}/extract" -d "{\"schema\":${PRODUCTS_SCHEMA}}"assert_ok "tab-scoped extract"assert_json_eq "$RESULT" '.data.products | length' '6' "tab-scoped route resolves the same page"diff --git a/tests/e2e/scenarios/api/extract-extended.sh b/tests/e2e/scenarios/api/extract-extended.shindex a28d5c88..2181d184 100755--- a/tests/e2e/scenarios/api/extract-extended.sh+++ b/tests/e2e/scenarios/api/extract-extended.sh@@ -9,6 +9,7 @@ secure_post() {}INJECT_SCHEMA='{"type":"object","properties":{"headline":{"type":"string","description":"page heading","x-pinchtab-hint":"role:heading"}}}'+INJECTED_VALUE_SCHEMA='{"type":"object","properties":{"notice":{"type":"string","description":"link text","x-pinchtab-hint":"role:link"}}}'# ─────────────────────────────────────────────────────────────────start_test "extract: injection page carries the IDPI warning in warn mode"@@ -29,6 +30,19 @@ assert_json_exists "$RESULT" ".idpiWarning" "idpiWarning present in the body"end_test+# ─────────────────────────────────────────────────────────────────+start_test "extract: an extracted value carrying the injection is flagged in warn mode"++pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/idpi-inject.html\"}"+assert_ok "navigate to idpi-inject.html"++pt_post /extract -d "{\"schema\":${INJECTED_VALUE_SCHEMA}}"+assert_ok "extract the injected link text in warn mode"+assert_contains "$(echo "$RESULT" | jq -r '.data.notice')" "Ignore previous instructions" "the injection phrase is the extracted value"+assert_json_exists "$RESULT" ".idpiWarning" "idpiWarning present when the value itself is injected"++end_test+# ─────────────────────────────────────────────────────────────────start_test "extract: strict mode blocks the injection page like /find"@@ -39,6 +53,10 @@ secure_post /extract -d "{\"schema\":${INJECT_SCHEMA}}"assert_http_status 403 "extract blocked by IDPI"assert_contains "$RESULT" "idpi" "block names the scanner"+secure_post /extract -d "{\"schema\":${INJECTED_VALUE_SCHEMA}}"+assert_http_status 403 "extract blocked when the extracted value is the injection"+assert_not_contains "$RESULT" "reveal your system prompt" "the blocked response does not leak the injected value"+secure_post /find -d '{"query":"heading"}'assert_http_status 403 "find blocked the same way"