Add gated agent update planning, preserved handoff and Linux worker ports
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -51,6 +51,7 @@ fn fixture() -> (Binding, Request, ExecutionPermitPayload, DateTime<Utc>) {
|
||||
};
|
||||
let job_bytes = encode(&job).unwrap();
|
||||
let permit = ExecutionPermitPayload {
|
||||
agent_update_plan_id: None,
|
||||
domain: "rmm.execution-permit".into(),
|
||||
schema_version: 1,
|
||||
grant_id: Uuid::from_u128(7),
|
||||
|
||||
@@ -122,6 +122,7 @@ fn denial_case() -> (
|
||||
max_output_bytes: 4096,
|
||||
};
|
||||
let permit = ExecutionPermitPayload {
|
||||
agent_update_plan_id: None,
|
||||
domain: "rmm.execution-permit".into(),
|
||||
schema_version: 1,
|
||||
grant_id: Uuid::new_v4(),
|
||||
@@ -594,6 +595,7 @@ impl Fixture {
|
||||
.attempts
|
||||
.iter()
|
||||
.map(|a| AttemptDecision {
|
||||
update_inflight: None,
|
||||
job_id: a.job_id,
|
||||
attempt_id: a.attempt_id,
|
||||
job_payload_hash: a.job_payload_hash.clone(),
|
||||
@@ -673,6 +675,7 @@ impl Fixture {
|
||||
max_output_bytes: 4096,
|
||||
};
|
||||
let permit = ExecutionPermitPayload {
|
||||
agent_update_plan_id: None,
|
||||
domain: "rmm.execution-permit".into(),
|
||||
schema_version: 1,
|
||||
grant_id: Uuid::new_v4(),
|
||||
@@ -957,6 +960,9 @@ fn request(
|
||||
text(8, &a.original_boot_id.to_string(), &mut row);
|
||||
text(11, &a.outcome_sha256, &mut row);
|
||||
blob(12, &a.outcome_bytes, &mut row);
|
||||
if !a.update_handoff_bytes.is_empty() {
|
||||
blob(14, &a.update_handoff_bytes, &mut row);
|
||||
}
|
||||
blob(6, &row, &mut out);
|
||||
}
|
||||
num(8, 1, &mut out);
|
||||
@@ -1399,3 +1405,572 @@ fn root_and_system_are_distinct_explicit_helper_domains() {
|
||||
let changed = sync.with_helper_identity(HelperIdentity::Root);
|
||||
assert!(!changed.can_start(&system.db, &system.guard, 1, &system.clock, &system.boot));
|
||||
}
|
||||
|
||||
// Test-only update admission port. This verifies fixture identity/bytes, NOT
|
||||
// real update trust files, service ownership, OS locks or a WebUI approval.
|
||||
struct TestUpdateGuard {
|
||||
ledger: ExecutorGuard,
|
||||
handoff_hash: String,
|
||||
delegation: rmm_domain::agent_update::UpdateDelegation,
|
||||
owner_alive: bool,
|
||||
owner_authority: bool,
|
||||
health_public_key: [u8; 32],
|
||||
}
|
||||
impl ExecutorLedgerGuard for TestUpdateGuard {
|
||||
fn is_update_owner_authority(&self) -> bool {
|
||||
self.owner_authority
|
||||
}
|
||||
fn check(&self, db: &Connection) -> anyhow::Result<()> {
|
||||
self.ledger.check(db)
|
||||
}
|
||||
fn check_update_owner(
|
||||
&self,
|
||||
handoff: &rmm_updater_handoff::Handoff,
|
||||
delegation: &rmm_domain::agent_update::UpdateDelegation,
|
||||
_: rmm_updater_handoff::Phase,
|
||||
_: &[rmm_updater_handoff::Event],
|
||||
) -> anyhow::Result<()> {
|
||||
anyhow::ensure!(
|
||||
self.owner_alive
|
||||
&& hash(&handoff.bytes()?) == self.handoff_hash
|
||||
&& delegation == &self.delegation,
|
||||
"TEST_OWNER_LOST"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl rmm_agent_core::update_handoff::UpdateAdmissionGuard for TestUpdateGuard {
|
||||
fn health_public_key(&self) -> anyhow::Result<[u8; 32]> {
|
||||
Ok(self.health_public_key)
|
||||
}
|
||||
fn verify_prepared_update(
|
||||
&self,
|
||||
_: &Request,
|
||||
handoff: &rmm_updater_handoff::Handoff,
|
||||
delegation: &rmm_domain::agent_update::UpdateDelegation,
|
||||
_: DateTime<Utc>,
|
||||
) -> anyhow::Result<()> {
|
||||
anyhow::ensure!(
|
||||
hash(&handoff.bytes()?) == self.handoff_hash && delegation == &self.delegation,
|
||||
"TEST_HANDOFF_CHANGED"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
fn update_case() -> (
|
||||
Fixture,
|
||||
HelperSync,
|
||||
Request,
|
||||
rmm_updater_handoff::Handoff,
|
||||
TestUpdateGuard,
|
||||
) {
|
||||
use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
|
||||
use rmm_domain::agent_update as u;
|
||||
use rmm_updater_handoff as h;
|
||||
let mut f = Fixture::new();
|
||||
let mut sync = f.sync();
|
||||
rmm_agent_core::update_handoff::initialize(&f.db, &f.guard).unwrap();
|
||||
let snapshot = f.snapshot(&mut sync, 7);
|
||||
let raw = f.request(&snapshot);
|
||||
let ready = f.decision(&snapshot, &raw, 7, true);
|
||||
assert!(f.apply(&mut sync, &ready, &raw).unwrap().ready);
|
||||
let digest = |n: u8| format!("{n:02x}").repeat(32);
|
||||
let mut manifest: u::ReleaseManifest = serde_json::from_slice(include_bytes!(
|
||||
"../../updater/tests/fixtures/release_v1.json"
|
||||
))
|
||||
.unwrap();
|
||||
manifest.published_at = f.clock.now.timestamp() as u64 - 1;
|
||||
manifest.expires_at = f.clock.now.timestamp() as u64 + 3600;
|
||||
let payload = encode(&manifest).unwrap();
|
||||
let release_key = SigningKey::from_bytes(&[43; 32]);
|
||||
let mut signed = b"rmm.agent-release.v1\0".to_vec();
|
||||
signed.extend_from_slice(&payload);
|
||||
let envelope = u::ReleaseEnvelope {
|
||||
schema_version: 1,
|
||||
key_id: hash(release_key.verifying_key().as_bytes()),
|
||||
payload_bytes: URL_SAFE_NO_PAD.encode(&payload),
|
||||
signature: URL_SAFE_NO_PAD.encode(release_key.sign(&signed).to_bytes()),
|
||||
};
|
||||
let update = u::ResolvedAgentUpdate {
|
||||
schema_version: 1,
|
||||
profile: u::UpdateProfile::FixedCodePairV1,
|
||||
release_envelope_sha256: envelope.sha256().unwrap(),
|
||||
manifest_sha256: hash(&payload),
|
||||
release_envelope: envelope,
|
||||
predecessor: u::Predecessor {
|
||||
release_id: Uuid::from_u128(99),
|
||||
release_sequence: 3,
|
||||
manifest_sha256: digest(1),
|
||||
installed_record_sha256: digest(2),
|
||||
agent_sha256: digest(3),
|
||||
helper_sha256: digest(4),
|
||||
},
|
||||
updater: u::UpdaterBinding {
|
||||
binary_sha256: digest(5),
|
||||
policy_sha256: digest(6),
|
||||
keyring_generation: 1,
|
||||
keyring_sha256: digest(7),
|
||||
health_public_key_hex: hex::encode(
|
||||
SigningKey::from_bytes(&[44; 32]).verifying_key().to_bytes(),
|
||||
),
|
||||
health_key_pin_sha256: digest(10),
|
||||
},
|
||||
peer_pin_transition: u::PeerPinTransition::UnchangedGeneralPinV1 {
|
||||
general_pin_sha256: digest(8),
|
||||
},
|
||||
recovery: u::Recovery::RestoreExactPredecessorOnce,
|
||||
health_profile: u::HealthProfile::MtlsInventorySyncV1,
|
||||
health_timeout_seconds: 180,
|
||||
no_reboot: true,
|
||||
};
|
||||
assert!(update.validate());
|
||||
let job = JobPayload {
|
||||
schema_version: 1,
|
||||
tenant_id: f.binding.tenant_id,
|
||||
asset_id: f.binding.asset_id,
|
||||
agent_id: f.binding.agent_id,
|
||||
enrollment_generation: 1,
|
||||
assignment_version: 3,
|
||||
job_id: Uuid::new_v4(),
|
||||
attempt_id: Uuid::new_v4(),
|
||||
action: Action::UpdateAgent {
|
||||
update: Box::new(update.clone()),
|
||||
},
|
||||
execution_identity: "root".into(),
|
||||
not_before: f.clock.now - Duration::seconds(1),
|
||||
start_before: f.clock.now + Duration::minutes(5),
|
||||
max_runtime_seconds: 600,
|
||||
max_output_bytes: 4096,
|
||||
};
|
||||
let permit = ExecutionPermitPayload {
|
||||
agent_update_plan_id: Some(Uuid::from_u128(1001)),
|
||||
domain: "rmm.execution-permit".into(),
|
||||
schema_version: 1,
|
||||
grant_id: Uuid::new_v4(),
|
||||
authorization_id: Uuid::new_v4(),
|
||||
tenant_id: job.tenant_id,
|
||||
asset_id: job.asset_id,
|
||||
agent_id: job.agent_id,
|
||||
enrollment_generation: 1,
|
||||
assignment_version: 3,
|
||||
job_id: job.job_id,
|
||||
attempt_id: job.attempt_id,
|
||||
plan_hash: digest(9),
|
||||
job_payload_hash: hash(&encode(&job).unwrap()),
|
||||
action: "update_agent".into(),
|
||||
execution_identity: "root".into(),
|
||||
not_before: f.clock.now - Duration::seconds(1),
|
||||
start_before: f.clock.now + Duration::seconds(59),
|
||||
max_runtime_seconds: 600,
|
||||
key_id: hash(f.key.verifying_key().as_bytes()),
|
||||
};
|
||||
let permit_bytes = encode(&permit).unwrap();
|
||||
let request = Request {
|
||||
job_bytes: encode(&job).unwrap(),
|
||||
permit_bytes: permit_bytes.clone(),
|
||||
signature: f.key.sign(&permit_bytes).to_bytes().to_vec(),
|
||||
plan_hash: permit.plan_hash.clone(),
|
||||
authorization_id: permit.authorization_id,
|
||||
};
|
||||
let handoff = h::Handoff {
|
||||
schema_version: 1,
|
||||
attempt: h::AttemptBinding {
|
||||
tenant_id: job.tenant_id,
|
||||
asset_id: job.asset_id,
|
||||
agent_id: job.agent_id,
|
||||
enrollment_generation: 1,
|
||||
assignment_version: 3,
|
||||
plan_id: Uuid::from_u128(1001),
|
||||
plan_sha256: permit.plan_hash,
|
||||
job_id: job.job_id,
|
||||
attempt_id: job.attempt_id,
|
||||
job_payload_sha256: permit.job_payload_hash,
|
||||
grant_id: permit.grant_id,
|
||||
authorization_id: permit.authorization_id,
|
||||
original_request_sha256: hash(&encode(&request).unwrap()),
|
||||
original_start_witness_sha256: hash(
|
||||
&rmm_agent_core::ledger::start_witness_bytes(
|
||||
&serde_json::from_slice(&request.permit_bytes).unwrap(),
|
||||
&request,
|
||||
f.boot.0,
|
||||
f.clock.now,
|
||||
)
|
||||
.unwrap(),
|
||||
),
|
||||
},
|
||||
agent_journal_id: f.agent_journal,
|
||||
helper_journal_id: snapshot.journal_id,
|
||||
helper_checkpoint: snapshot.checkpoint,
|
||||
previous_decision_id: ready.decision_id,
|
||||
boot_id: f.boot.0,
|
||||
connection_generation: 7,
|
||||
owner_nonce: Uuid::new_v4(),
|
||||
updater_sha256: update.updater.binary_sha256,
|
||||
updater_policy_sha256: update.updater.policy_sha256,
|
||||
predecessor_record_sha256: update.predecessor.installed_record_sha256,
|
||||
retained_state_sha256: digest(10),
|
||||
ledger_identity_sha256: digest(11),
|
||||
staged_files_sha256: digest(12),
|
||||
predecessor: h::CodePair {
|
||||
manifest_sha256: update.predecessor.manifest_sha256,
|
||||
agent_sha256: update.predecessor.agent_sha256.clone(),
|
||||
helper_sha256: update.predecessor.helper_sha256.clone(),
|
||||
pin_sha256: digest(8),
|
||||
},
|
||||
target: h::CodePair {
|
||||
manifest_sha256: update.manifest_sha256,
|
||||
agent_sha256: manifest.artifacts[0].sha256.clone(),
|
||||
helper_sha256: manifest.artifacts[1].sha256.clone(),
|
||||
pin_sha256: digest(8),
|
||||
},
|
||||
pin_transition: h::PinTransition::UnchangedLinuxGeneralV1,
|
||||
pin_transition_sha256: hash(&encode(&update.peer_pin_transition).unwrap()),
|
||||
files: vec![
|
||||
h::FileTransition {
|
||||
role: h::FileRole::AgentBinary,
|
||||
old_sha256: update.predecessor.agent_sha256,
|
||||
new_sha256: manifest.artifacts[0].sha256.clone(),
|
||||
},
|
||||
h::FileTransition {
|
||||
role: h::FileRole::HelperBinary,
|
||||
old_sha256: update.predecessor.helper_sha256,
|
||||
new_sha256: manifest.artifacts[1].sha256.clone(),
|
||||
},
|
||||
],
|
||||
stop_set: vec![h::Service::LinuxAgent, h::Service::LinuxGeneralHelper],
|
||||
consumed_at: f.clock.now.timestamp() as u64,
|
||||
finish_before: f.clock.now.timestamp() as u64 + 600,
|
||||
};
|
||||
let guard = TestUpdateGuard {
|
||||
ledger: ExecutorGuard {
|
||||
directory: f.dir.clone(),
|
||||
},
|
||||
handoff_hash: hash(&handoff.bytes().unwrap()),
|
||||
owner_alive: true,
|
||||
owner_authority: true,
|
||||
health_public_key: SigningKey::from_bytes(&[44; 32]).verifying_key().to_bytes(),
|
||||
delegation: u::UpdateDelegation {
|
||||
schema_version: 1,
|
||||
handoff_sha256: hash(&handoff.bytes().unwrap()),
|
||||
owner_nonce: handoff.owner_nonce,
|
||||
boot_id: handoff.boot_id,
|
||||
prepared_at: f.clock.now,
|
||||
updater: u::ParticipantIdentity {
|
||||
role: u::ParticipantRole::LinuxUpdater,
|
||||
pid: 600,
|
||||
birth: 1000,
|
||||
image_sha256: handoff.updater_sha256.clone(),
|
||||
security_principal: "uid:0".into(),
|
||||
service_instance_sha256: digest(14),
|
||||
},
|
||||
original_helper: u::ParticipantIdentity {
|
||||
role: u::ParticipantRole::LinuxGeneralHelper,
|
||||
pid: 700,
|
||||
birth: 2000,
|
||||
image_sha256: handoff.predecessor.helper_sha256.clone(),
|
||||
security_principal: "uid:0".into(),
|
||||
service_instance_sha256: digest(15),
|
||||
},
|
||||
},
|
||||
};
|
||||
(f, sync, request, handoff, guard)
|
||||
}
|
||||
#[test]
|
||||
fn update_handoff_consumption_start_and_stop_intent_are_one_transaction() {
|
||||
for trigger in [
|
||||
"",
|
||||
"CREATE TRIGGER deny_handoff BEFORE INSERT ON agent_update_handoffs BEGIN SELECT RAISE(ABORT,'test'); END;",
|
||||
"CREATE TRIGGER deny_event BEFORE INSERT ON agent_update_handoff_events BEGIN SELECT RAISE(ABORT,'test'); END;",
|
||||
] {
|
||||
let (mut f, mut sync, request, handoff, guard) = update_case();
|
||||
f.db.execute_batch(trigger).unwrap();
|
||||
let result = sync.begin_update_handoff(
|
||||
&mut f.db,
|
||||
&guard,
|
||||
7,
|
||||
&rmm_agent_core::update_handoff::PreparedHandoff {
|
||||
request: &request,
|
||||
handoff: &handoff,
|
||||
delegation: &guard.delegation,
|
||||
recorded_at: f.clock.now,
|
||||
},
|
||||
&f.clock,
|
||||
&f.boot,
|
||||
);
|
||||
assert_eq!(result.is_ok(), trigger.is_empty(), "{result:?}");
|
||||
for table in [
|
||||
"consumed",
|
||||
"execution_evidence",
|
||||
"agent_update_handoffs",
|
||||
"agent_update_delegations",
|
||||
"agent_update_handoff_events",
|
||||
] {
|
||||
let count: u32 =
|
||||
f.db.query_row(&format!("SELECT count(*) FROM {table}"), [], |r| r.get(0))
|
||||
.unwrap();
|
||||
assert_eq!(count, if trigger.is_empty() { 1 } else { 0 }, "{table}");
|
||||
}
|
||||
if trigger.is_empty() {
|
||||
let journal =
|
||||
rmm_agent_core::update_handoff::read(&f.db, &guard, handoff.attempt.grant_id)
|
||||
.unwrap();
|
||||
assert_eq!(journal.phase(), rmm_updater_handoff::Phase::StopIntent);
|
||||
assert!(!sync.can_start(&f.db, &guard, 7, &f.clock, &f.boot));
|
||||
assert!(
|
||||
sync.begin_update_handoff(
|
||||
&mut f.db,
|
||||
&guard,
|
||||
7,
|
||||
&rmm_agent_core::update_handoff::PreparedHandoff {
|
||||
request: &request,
|
||||
handoff: &handoff,
|
||||
delegation: &guard.delegation,
|
||||
recorded_at: f.clock.now
|
||||
},
|
||||
&f.clock,
|
||||
&f.boot
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_inflight_negative_control_keeps_every_start_closed_and_owner_loss_is_terminal() {
|
||||
let (mut f, mut sync, request, handoff, mut guard) = update_case();
|
||||
let prepared = rmm_agent_core::update_handoff::PreparedHandoff {
|
||||
request: &request,
|
||||
handoff: &handoff,
|
||||
delegation: &guard.delegation,
|
||||
recorded_at: f.clock.now,
|
||||
};
|
||||
sync.begin_update_handoff(&mut f.db, &guard, 7, &prepared, &f.clock, &f.boot)
|
||||
.unwrap();
|
||||
let original: Vec<u8> =
|
||||
f.db.query_row(
|
||||
"SELECT start FROM execution_evidence WHERE grant_id=?1",
|
||||
[handoff.attempt.grant_id.to_string()],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
f.clock.now += Duration::seconds(1);
|
||||
let mut fresh = f.sync();
|
||||
let snapshot = fresh
|
||||
.snapshot(&mut f.db, &guard, 8, &f.clock, &f.boot)
|
||||
.unwrap();
|
||||
assert_eq!(snapshot.attempts[0].state, "running");
|
||||
assert!(!snapshot.attempts[0].update_handoff_bytes.is_empty());
|
||||
let raw = f.request(&snapshot);
|
||||
let mut decision = f.decision(&snapshot, &raw, 8, false);
|
||||
let proof = rmm_domain::agent_update::UpdateInflightProof::from_bytes(
|
||||
&snapshot.attempts[0].update_handoff_bytes,
|
||||
)
|
||||
.unwrap();
|
||||
let attempt = &mut decision.attempts[0];
|
||||
attempt.outcome_state = "running".into();
|
||||
attempt.update_inflight =
|
||||
Some(rmm_domain::agent_update::inflight_decision(&proof, guard.health_public_key).unwrap());
|
||||
attempt.reason = "AGENT_UPDATE_INFLIGHT".into();
|
||||
let signed = f.sign(&decision);
|
||||
let applied = fresh
|
||||
.apply(&mut f.db, &guard, &signed, &raw, &f.clock, &f.boot)
|
||||
.unwrap();
|
||||
assert!(!applied.ready && applied.unlocked_grants.is_empty());
|
||||
assert!(!fresh.can_start(&f.db, &guard, 8, &f.clock, &f.boot));
|
||||
assert_eq!(
|
||||
f.db.query_row::<u32, _, _>(
|
||||
"SELECT count(*) FROM execution_evidence WHERE outcome IS NOT NULL",
|
||||
[],
|
||||
|r| r.get(0)
|
||||
)
|
||||
.unwrap(),
|
||||
0
|
||||
);
|
||||
// A nondesignated General reader cannot attest this Full-owned update,
|
||||
// and must never turn that lack of authority into terminal Unknown.
|
||||
guard.owner_authority = false;
|
||||
guard.owner_alive = false;
|
||||
assert!(
|
||||
fresh
|
||||
.snapshot(&mut f.db, &guard, 8, &f.clock, &f.boot)
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(
|
||||
rmm_agent_core::update_handoff::read(&f.db, &guard, handoff.attempt.grant_id)
|
||||
.unwrap()
|
||||
.phase(),
|
||||
rmm_updater_handoff::Phase::StopIntent
|
||||
);
|
||||
guard.owner_authority = true;
|
||||
f.clock.now += Duration::seconds(1);
|
||||
let lost = fresh
|
||||
.snapshot(&mut f.db, &guard, 8, &f.clock, &f.boot)
|
||||
.unwrap();
|
||||
assert_eq!(lost.attempts[0].state, "unknown");
|
||||
assert!(lost.attempts[0].update_handoff_bytes.is_empty());
|
||||
assert_eq!(
|
||||
rmm_agent_core::update_handoff::read(&f.db, &guard, handoff.attempt.grant_id)
|
||||
.unwrap()
|
||||
.phase(),
|
||||
rmm_updater_handoff::Phase::Unknown
|
||||
);
|
||||
guard.owner_alive = true;
|
||||
let retained = fresh
|
||||
.snapshot(&mut f.db, &guard, 8, &f.clock, &f.boot)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
retained.attempts[0].outcome_bytes,
|
||||
lost.attempts[0].outcome_bytes
|
||||
);
|
||||
assert_eq!(retained.attempts[0].state, "unknown");
|
||||
assert_eq!(
|
||||
f.db.query_row::<Vec<u8>, _, _>(
|
||||
"SELECT start FROM execution_evidence WHERE grant_id=?1",
|
||||
[handoff.attempt.grant_id.to_string()],
|
||||
|r| r.get(0)
|
||||
)
|
||||
.unwrap(),
|
||||
original
|
||||
);
|
||||
assert_eq!(
|
||||
f.db.query_row::<u32, _, _>(
|
||||
"SELECT count(*) FROM consumed WHERE result IS NULL",
|
||||
[],
|
||||
|r| r.get(0)
|
||||
)
|
||||
.unwrap(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
impl rmm_agent_core::update_handoff::UpdateParticipantGuard for TestUpdateGuard {
|
||||
fn participant(&self) -> rmm_agent_core::update_handoff::Participant {
|
||||
rmm_agent_core::update_handoff::Participant::OriginalHelper
|
||||
}
|
||||
fn verify_update_event(
|
||||
&self,
|
||||
_: &rmm_updater_handoff::Handoff,
|
||||
_: &rmm_domain::agent_update::UpdateDelegation,
|
||||
_: &rmm_updater_handoff::Event,
|
||||
) -> anyhow::Result<()> {
|
||||
anyhow::bail!("TEST_NATIVE_INTENTS_ONLY_NO_OS_EFFECTS")
|
||||
}
|
||||
fn verify_native_effect(
|
||||
&self,
|
||||
h: &rmm_updater_handoff::Handoff,
|
||||
d: &rmm_domain::agent_update::UpdateDelegation,
|
||||
_: &rmm_agent_core::update_handoff::NativeEffect,
|
||||
_: rmm_agent_core::update_handoff::NativeEffectStage,
|
||||
) -> anyhow::Result<()> {
|
||||
anyhow::ensure!(
|
||||
self.owner_alive
|
||||
&& self.owner_authority
|
||||
&& hash(&h.bytes()?) == self.handoff_hash
|
||||
&& d == &self.delegation,
|
||||
"TEST_NATIVE_DENIED"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn native_stop_intent_is_original_head_bound_create_once_and_transactional() {
|
||||
use rmm_agent_core::update_handoff as u;
|
||||
for fail_insert in [false, true] {
|
||||
let (mut f, mut sync, request, handoff, mut guard) = update_case();
|
||||
sync.begin_update_handoff(
|
||||
&mut f.db,
|
||||
&guard,
|
||||
7,
|
||||
&u::PreparedHandoff {
|
||||
request: &request,
|
||||
handoff: &handoff,
|
||||
delegation: &guard.delegation,
|
||||
recorded_at: f.clock.now,
|
||||
},
|
||||
&f.clock,
|
||||
&f.boot,
|
||||
)
|
||||
.unwrap();
|
||||
let head = u::read(&f.db, &guard, handoff.attempt.grant_id)
|
||||
.unwrap()
|
||||
.head_sha256()
|
||||
.to_owned();
|
||||
let effect = u::NativeEffect::StopService {
|
||||
service: u::NativeService::Agent,
|
||||
};
|
||||
assert!(
|
||||
u::claim_native_effect(
|
||||
&mut f.db,
|
||||
&guard,
|
||||
handoff.attempt.grant_id,
|
||||
&"0".repeat(64),
|
||||
&effect,
|
||||
f.clock.now
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
guard.owner_alive = false;
|
||||
assert!(
|
||||
u::claim_native_effect(
|
||||
&mut f.db,
|
||||
&guard,
|
||||
handoff.attempt.grant_id,
|
||||
&head,
|
||||
&effect,
|
||||
f.clock.now
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
guard.owner_alive = true;
|
||||
if fail_insert {
|
||||
f.db.execute_batch("CREATE TRIGGER deny_native BEFORE INSERT ON agent_update_native_claims BEGIN SELECT RAISE(ABORT,'test'); END;").unwrap();
|
||||
}
|
||||
let result = u::claim_native_effect(
|
||||
&mut f.db,
|
||||
&guard,
|
||||
handoff.attempt.grant_id,
|
||||
&head,
|
||||
&effect,
|
||||
f.clock.now,
|
||||
);
|
||||
assert_eq!(result.is_ok(), !fail_insert);
|
||||
if let Ok(claim) = result {
|
||||
assert_eq!(claim.grant_id(), handoff.attempt.grant_id);
|
||||
assert_eq!(claim.owner_nonce(), handoff.owner_nonce);
|
||||
assert_eq!(claim.head_sha256(), head);
|
||||
assert_eq!(claim.effect(), &effect);
|
||||
assert!(
|
||||
u::claim_native_effect(
|
||||
&mut f.db,
|
||||
&guard,
|
||||
handoff.attempt.grant_id,
|
||||
&head,
|
||||
&effect,
|
||||
f.clock.now
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
f.db.query_row::<u32, _, _>(
|
||||
"SELECT count(*) FROM agent_update_native_claims",
|
||||
[],
|
||||
|r| r.get(0)
|
||||
)
|
||||
.unwrap(),
|
||||
u32::from(!fail_insert)
|
||||
);
|
||||
assert_eq!(
|
||||
f.db.query_row::<u32, _, _>("SELECT count(*) FROM consumed", [], |r| r.get(0))
|
||||
.unwrap(),
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
u::read(&f.db, &guard, handoff.attempt.grant_id)
|
||||
.unwrap()
|
||||
.head_sha256(),
|
||||
head
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ impl Fixture {
|
||||
"succeeded" | "failed" | "cancelled" | "expired"
|
||||
);
|
||||
AttemptDecision {
|
||||
update_inflight: None,
|
||||
job_id: job.job_id,
|
||||
attempt_id: job.attempt_id,
|
||||
job_payload_hash: local.job_payload_hash.clone(),
|
||||
@@ -249,6 +250,7 @@ impl Fixture {
|
||||
let mut grant = None;
|
||||
if consume {
|
||||
let p = ExecutionPermitPayload {
|
||||
agent_update_plan_id: None,
|
||||
domain: "rmm.execution-permit".into(),
|
||||
schema_version: 1,
|
||||
grant_id: Uuid::new_v4(),
|
||||
@@ -370,6 +372,7 @@ fn authenticated_helper_outcome_is_imported_as_new_durable_evidence_not_reexecut
|
||||
checkpoint: 3,
|
||||
previous_decision_id: None,
|
||||
attempts: vec![SyncAttempt {
|
||||
update_handoff_bytes: Vec::new(),
|
||||
job_id: offer.job_id.clone(),
|
||||
attempt_id: offer.attempt_id.clone(),
|
||||
job_payload_hash: offer.job_payload_hash.clone(),
|
||||
@@ -1175,6 +1178,7 @@ fn system_helper_import_requires_explicit_system_identity_and_never_root_alias()
|
||||
checkpoint: 3,
|
||||
previous_decision_id: None,
|
||||
attempts: vec![SyncAttempt {
|
||||
update_handoff_bytes: Vec::new(),
|
||||
job_id: offer.job_id.clone(),
|
||||
attempt_id: offer.attempt_id.clone(),
|
||||
job_payload_hash: offer.job_payload_hash.clone(),
|
||||
|
||||
Reference in New Issue
Block a user