Files
crank/apps/admin-api/src/service/resources/tests/diagnostics.rs
T
bsodfather 54ce770682
CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
feat(epic3): deliver the accepted Epic 3 scope through Story 3.17
Recovery delivery of the accumulated, TL-accepted Epic 3 work that had never been
committed to Git (stories 3.6-3.17, see the crank board). Story 3.18 is not accepted
yet and is deliberately excluded: its logging surface, its capability registration,
its oracle projections and its tests are not part of this tree.

Accepted scope
- 3.6 typed static Resource Drafts; 3.7 publication and exact binding of static
  Resource Versions; 3.8 MCP discovery/read and revocation of static Resources;
- 3.9 Resource import/export in API and UI plus TLS dependency maintenance;
  3.10 REST-backed Resource templates; 3.11 shared REST read runtime and the MCP
  revision/capability foundation;
- 3.12 parameterised Prompt Drafts with preview; 3.13 Prompt publication and exact
  version binding to Agents; 3.14 MCP prompts; 3.15 Prompt import/export;
- 3.16 composite Prompts with published Resources (dependency content scan plus
  dynamic read through the accepted 3.11 runtime, admin preview and MCP prompts/get);
- 3.17 bounded MCP completion suggestions from typed published schemas and the
  resources/list admission fix for bound template publications.

Accepted evidence being reused (unchanged code paths)
- 3.16 candidate: core 7, admin-api 22, registry 4, mcp-server 4, UI 6; one final
  `just verify` run 1651 passed / 0 failed / 2 ignored.
- 3.17 candidate: full run 1672 passed / 0 failed / 2 ignored, QA targeted reruns and
  a real MCP Inspector 2.12.0 client smoke.

Delivery engineering in this commit
- CI: one event per change (feature branches are gated by their pull request, push
  runs only on main), story events run the changed packages, the full workspace suite
  stays the feature/release gate; no cache/sharding without a measured runner check.
- Release: the packaged archives, checksums and SBOM are now uploaded to the Gitea
  release entry of the tag instead of dying with the runner workspace.

Not included on purpose: Story 3.18 work, build caches, runtime databases, local
credentials and scratch evidence.

Refs: crank kanban t_e39d7263; baseline 1b6db09bd1.
2026-10-25 09:08:22 +00:00

127 lines
5.4 KiB
Rust

//! F5 (TL run105): диагностика рукописного фрагментированного запроса не несёт
//! session/CSRF-значения.
//!
//! Контроль **положительный и синтетический**: маркерные значения заведомо отправляются
//! реальным сокетным запросом, поэтому их отсутствие в подписи — результат редактирования,
//! а не пустая строка. Одновременно проверяется, что подпись сохраняет метод, путь,
//! `Transfer-Encoding` и статус: иначе отказ не отличить от ошибки харнесса.
//!
//! Размещение: in-crate сервисные тесты (`tests/**`) — корневой фикстур-файл ограничен
//! health-правилом 1000 строк, а сам контроль проверяет публичные (crate-private) шлюзы
//! composition-стенда.
//!
//! Канонический прогон: `cargo test -p admin-api --lib
//! service::resources::tests::diagnostics -- --test-threads=1`.
use serial_test::serial;
use crate::app::resource_test_support::{
GuardHarness, RawHttpResponse, RawSession, redact_sensitive_headers, send_chunked_multipart,
};
const MARKER_COOKIE: &str = "crank_session=C36-F5-MARKER-cookie";
const MARKER_CSRF: &str = "C36-F5-MARKER-csrf";
const MARKER_REPLY_COOKIE: &str = "C36-F5-MARKER-reply";
/// Прямой контроль шлюза: значения заменяются маркером, структура головы сохраняется.
#[test]
fn story36_at06_header_redaction_drops_sensitive_values_and_keeps_context() {
let request_head = format!(
"POST /api/admin/workspaces/ws_default/resources HTTP/1.1\r\n\
Host: 127.0.0.1:1234\r\n\
Cookie: {MARKER_COOKIE}\r\n\
X-CSRF-Token: {MARKER_CSRF}\r\n\
Content-Type: multipart/form-data; boundary=story36\r\n\
Transfer-Encoding: chunked\r\n\
Connection: close\r\n\r\n"
);
let response_head = format!(
"HTTP/1.1 400 Bad Request\r\n\
content-type: application/json\r\n\
set-cookie: {MARKER_REPLY_COOKIE}; Path=/\r\n\r\n"
);
let response = RawHttpResponse {
status: 400,
head: redact_sensitive_headers(&response_head),
body: "{\"error\":{\"code\":\"validation_error\"}}".to_owned(),
request_head: redact_sensitive_headers(&request_head),
write_error: None,
read_error: None,
};
let signature = response.signature();
for marker in [MARKER_COOKIE, MARKER_CSRF, MARKER_REPLY_COOKIE] {
assert!(
!signature.contains(marker),
"raw session/CSRF values must never reach the diagnostics: marker `{marker}` \
present in `{signature}`"
);
}
for kept in [
"POST /api/admin/workspaces/ws_default/resources HTTP/1.1",
"Cookie: <redacted-sensitive-header>",
"X-CSRF-Token: <redacted-sensitive-header>",
"Transfer-Encoding: chunked",
"status=400",
"400 Bad Request",
] {
assert!(
signature.contains(kept),
"redaction must keep the diagnostic context `{kept}`: {signature}"
);
}
}
/// Тот же контроль на **реальном** сокетном пути: маркерная сессия действительно
/// отправляется настоящим chunked-запросом, а сохранённая диагностика обязана быть
/// отредактированной (значения живут только в момент отправки).
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn story36_at06_real_chunked_diagnostics_carry_no_session_or_csrf_values() {
let harness = GuardHarness::spawn("redaction").await;
let session = RawSession {
cookie: MARKER_COOKIE.to_owned(),
csrf: MARKER_CSRF.to_owned(),
};
let boundary = "story36f5marker";
let body = format!(
"--{boundary}\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n{{}}\r\n\
--{boundary}\r\nContent-Disposition: form-data; name=\"content\"; filename=\"d.txt\"\r\n\r\n\
marker payload without a closing boundary"
);
let chunks = vec![body.into_bytes()];
let response = send_chunked_multipart(
harness.addr,
"/api/admin/workspaces/ws_default/resources",
&session,
boundary,
&chunks,
)
.await;
let signature = response.signature();
for marker in [MARKER_COOKIE, MARKER_CSRF] {
assert!(
!signature.contains(marker),
"a real chunked request must not store raw credentials: marker `{marker}` present \
in `{signature}`"
);
}
assert!(
!signature.contains("crank_session="),
"no stored head may carry a session value: {signature}"
);
for kept in [
"POST /api/admin/workspaces/ws_default/resources HTTP/1.1",
"Cookie: <redacted-sensitive-header>",
"X-CSRF-Token: <redacted-sensitive-header>",
"Transfer-Encoding: chunked",
] {
assert!(
signature.contains(kept),
"the refused request must stay distinguishable from a harness error: `{kept}` \
missing in `{signature}`"
);
}
}