Files
crank/apps/admin-api/tests/integration/resources/publication/policy.rs
T
Hermes DevOps 75fe5a123c [skip ci] wip: preserve Hermes crank development checkpoint
Owner-authorized recovery of accumulated source changes.
Includes accepted work and in-progress changes; NOT a release or acceptance.
Parent baseline 1b6db09bd1. Runtime data, build caches and local credentials excluded.
2026-10-25 10:00:22 +00:00

242 lines
9.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! AC02 positive/negative controls для publication policy (Story 3.7).
//!
//! TL decision 4: explicit `include: crank://...` — это директива, а не обычное
//! упоминание. Она разрешается только workspace-local по уже опубликованной metadata;
//! понижение sensitivity запрещено. Обычные ссылки, проза и сами слова категорий
//! публикуются. Все контроля используют синтетические значения, без реальных секретов.
use super::super::helpers::{
create_draft, created_resource_id, draft_metadata, error_signature, get_card, spawn_authorized,
};
use super::{create_and_publish, create_fixture, publish, published_metadata};
use reqwest::StatusCode;
use serde_json::json;
use serial_test::serial;
/// Локальная опубликованная цель + обычная ссылка в том же Draft: обе ситуации
/// разрешены и дают immutable Published Version.
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn story37_at02_ordinary_link_and_local_published_include_are_publishable() {
let (_registry, server, client) = spawn_authorized("story37_policy_positive").await;
// Цель — exact Published Version в этом же workspace со sensitivity internal.
let target = create_and_publish(
&client,
&server,
&draft_metadata(
"crank://story37/policy-target",
"policy_target",
"text",
"text/plain",
"internal",
),
b"target reference body\n",
"story37-policy-target.txt",
"text/plain",
)
.await;
assert_eq!(target.published_version["version"], json!(1));
// Обычная ссылка + упоминания категорий: не директива и не секрет.
let ordinary = "См. https://example.com/spec; private keys и tokens описаны в prose.\n";
let ordinary_fixture = create_fixture(
&client,
&server,
&draft_metadata(
"crank://story37/policy-ordinary",
"policy_ordinary",
"text",
"text/plain",
"internal",
),
ordinary.as_bytes(),
"story37-policy-ordinary.txt",
"text/plain",
)
.await;
let (status, text, body) = publish(
&client,
&server,
&ordinary_fixture.resource_id,
&ordinary_fixture.updated_at,
)
.await;
assert_eq!(
status,
StatusCode::OK,
"an ordinary link must stay publishable; observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(published_metadata(&body)["version"], json!(1));
// Explicit include на exact published version того же workspace с совместимой
// sensitivity публикуется; текст остаётся статическим (без expansion).
let include = "include: crank://story37/policy-target\n";
let include_fixture = create_fixture(
&client,
&server,
&draft_metadata(
"crank://story37/policy-include",
"policy_include",
"text",
"text/plain",
"internal",
),
include.as_bytes(),
"story37-policy-include.txt",
"text/plain",
)
.await;
let (status, text, body) = publish(
&client,
&server,
&include_fixture.resource_id,
&include_fixture.updated_at,
)
.await;
assert_eq!(
status,
StatusCode::OK,
"an explicit include of a published local Resource must publish; observed {} body={text}",
error_signature(status, &body)
);
let published = published_metadata(&body);
assert_eq!(published["version"], json!(1));
assert_eq!(published["kind"], json!("text"));
assert!(
!published.to_string().contains("target reference body"),
"publication must not expand the included content: {published}"
);
}
/// Include на published Resource с более высокой sensitivity — access-bypassing
/// reference: тот же generic 422, без раскрытия цели и без side effects.
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn story37_at02_include_must_not_lower_published_sensitivity() {
let (_registry, server, client) = spawn_authorized("story37_policy_lowering").await;
// Публикуем секретную цель (sensitivity=secret сама по себе публикуема).
let secret_target = create_and_publish(
&client,
&server,
&draft_metadata(
"crank://story37/policy-secret-target",
"policy_secret_target",
"text",
"text/plain",
"secret",
),
b"synthetic secret target body\n",
"story37-policy-secret-target.txt",
"text/plain",
)
.await;
assert_eq!(secret_target.published_version["version"], json!(1));
// Внутренний Draft включает секретную цель -> понижение sensitivity, отказ.
let fixture = create_fixture(
&client,
&server,
&draft_metadata(
"crank://story37/policy-lowering",
"policy_lowering",
"text",
"text/plain",
"internal",
),
b"include: crank://story37/policy-secret-target\n",
"story37-policy-lowering.txt",
"text/plain",
)
.await;
let (status, text, body) =
publish(&client, &server, &fixture.resource_id, &fixture.updated_at).await;
assert_eq!(
status,
StatusCode::UNPROCESSABLE_ENTITY,
"a sensitivity-lowering include must be refused with 422; observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(body["error"]["code"], json!("resource_secret_findings"));
assert_eq!(body["error"]["context"]["field"], json!("content"));
assert!(
!text.contains("policy-secret-target") && !text.contains("policy_secret_target"),
"the refusal must not disclose the referenced target: {text}"
);
// Отказ не опубликовал включающий Draft и не изменил цель.
let card = get_card(&client, &server, &fixture.resource_id).await;
assert_eq!(card["resource"]["status"], json!("draft"));
let (status, _, _) = super::read_version(&client, &server, &fixture.resource_id, 1).await;
assert_eq!(
status,
StatusCode::NOT_FOUND,
"a refused publication must not expose a Published Version"
);
}
/// `include:` на неопубликованную (но существующую) сущность того же workspace —
/// тот же generic отказ; существование/метаданные цели не раскрываются.
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn story37_at02_include_requires_published_target_without_disclosure() {
let (_registry, server, client) = spawn_authorized("story37_policy_unpublished").await;
let unpublished_meta = draft_metadata(
"crank://story37/policy-draft-target",
"policy_draft_target",
"text",
"text/plain",
"internal",
);
let unpublished = create_draft(
&client,
&server,
&unpublished_meta,
b"draft-only target body\n",
"story37-policy-draft-target.txt",
"text/plain",
)
.await;
let unpublished_id = created_resource_id(&unpublished);
assert!(!unpublished_id.is_empty());
let fixture = create_fixture(
&client,
&server,
&draft_metadata(
"crank://story37/policy-unpublished",
"policy_unpublished",
"text",
"text/plain",
"internal",
),
b"include: crank://story37/policy-draft-target\n",
"story37-policy-unpublished.txt",
"text/plain",
)
.await;
let (status, text, body) =
publish(&client, &server, &fixture.resource_id, &fixture.updated_at).await;
assert_eq!(
status,
StatusCode::UNPROCESSABLE_ENTITY,
"an include of an unpublished target must be refused; observed {} body={text}",
error_signature(status, &body)
);
assert_eq!(body["error"]["code"], json!("resource_secret_findings"));
assert!(
!text.contains("policy-draft-target") && !text.contains("draft-only target body"),
"the refusal must not disclose the unpublished target: {text}"
);
// Цель остаётся Draft и не получила Published Version.
let target_card = get_card(&client, &server, &unpublished_id).await;
assert_eq!(target_card["resource"]["status"], json!("draft"));
let (target_version_status, _, _) =
super::read_version(&client, &server, &unpublished_id, 1).await;
assert_eq!(target_version_status, StatusCode::NOT_FOUND);
}