test(cli,store): through the server a refusal writes nothing, a bank file is masked, a chart file refused; the store's own texts meet the check
The store's attestation notes and model names, attachment and document texts and the unlink, withdraw and void reasons are checked before anything is journaled, like the engine's. Two end-to-end tests changed their words (not their data): spec_projects expects "tax id" where it expected "TIN", documents expects "tax id" where it expected "taxpayer", for the refusal the new check now gives first. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
d2384dfe7c
commit
657daf43da
7 files changed
+298
-4
No files matched your search
@@ -372,6 +372,20 @@ pub struct Claim {
|
||||
}
|
||||
|
||||
impl Claim {
|
||||
/// The words a claim keeps (the note, the model's name) hold no tax id
|
||||
/// (BS-partner-2): checked before anything is journaled.
|
||||
fn check(&self) -> Result<(), StoreError> {
|
||||
for (field, text) in [
|
||||
("the note", self.note.as_deref()),
|
||||
("the model", self.method.model.as_deref()),
|
||||
] {
|
||||
if let Some(t) = text {
|
||||
ledger_core::LedgerError::free_text(field, t)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn into_attestation(self, what: Attested) -> Attestation {
|
||||
Attestation {
|
||||
seq: 0,
|
||||
@@ -731,6 +745,7 @@ impl Store {
|
||||
date: NaiveDate,
|
||||
claim: Claim,
|
||||
) -> Result<Attestation, StoreError> {
|
||||
claim.check()?;
|
||||
self.ensure_feature(crate::format::AUDITS)?;
|
||||
let entry = self
|
||||
.ledger
|
||||
@@ -775,6 +790,7 @@ impl Store {
|
||||
|
||||
/// Record that an entry was reviewed whole (`entry.reviewed`).
|
||||
pub fn review_entry(&mut self, entry_id: u64, claim: Claim) -> Result<Attestation, StoreError> {
|
||||
claim.check()?;
|
||||
self.ensure_feature(crate::format::AUDITS)?;
|
||||
let entry = self
|
||||
.ledger
|
||||
@@ -817,6 +833,7 @@ impl Store {
|
||||
period_id: u64,
|
||||
claim: Claim,
|
||||
) -> Result<(Attestation, AuditRun), StoreError> {
|
||||
claim.check()?;
|
||||
self.ensure_feature(crate::format::AUDITS)?;
|
||||
let run = self.run_for_period(period_id)?;
|
||||
let a = self.journal_attestation(
|
||||
|
||||
@@ -301,6 +301,77 @@ fn stale_head_period_attestation_refused() {
|
||||
s.verify().unwrap();
|
||||
}
|
||||
|
||||
/// BS-partner-2 (WB-partner-15): the store's own texts (a file's name and
|
||||
/// description, the reasons for unlinking, withdrawing and voiding, an
|
||||
/// attestation's note, an entry's description) meet the one free-text check
|
||||
/// before anything is journaled, whoever calls.
|
||||
#[test]
|
||||
fn the_store_refuses_text_that_looks_like_a_tax_id_and_journals_nothing() {
|
||||
use ledger_core::LedgerError;
|
||||
let dir = test_dir("tin-text");
|
||||
let (mut s, fx) = books(&dir, None);
|
||||
let tin = "000-00-0000";
|
||||
let refused = |r: Result<(), StoreError>, what: &str| match r {
|
||||
Err(StoreError::Ledger(LedgerError::FreeTextHoldsTin(why))) => {
|
||||
assert!(!why.contains("0000"), "{what}: never the number: {why}");
|
||||
}
|
||||
other => panic!("{what}: expected a refusal for the tax id, got {other:?}"),
|
||||
};
|
||||
let (att, _, _) = s
|
||||
.attach_receipt(Some(fx.entry), "r.txt", "text/plain", b"paper 40.00", None)
|
||||
.unwrap();
|
||||
let head = s.head();
|
||||
refused(
|
||||
s.attach_receipt(
|
||||
None,
|
||||
"s.txt",
|
||||
"text/plain",
|
||||
b"other",
|
||||
Some(&format!("paid {tin}")),
|
||||
)
|
||||
.map(drop),
|
||||
"a description",
|
||||
);
|
||||
refused(
|
||||
s.attach_receipt(None, &format!("w9 {tin}.txt"), "text/plain", b"other", None)
|
||||
.map(drop),
|
||||
"a file name",
|
||||
);
|
||||
refused(
|
||||
s.file_document(
|
||||
"tax",
|
||||
"t.txt",
|
||||
"text/plain",
|
||||
b"doc",
|
||||
Some(&format!("ein {tin}")),
|
||||
)
|
||||
.map(drop),
|
||||
"a document's description",
|
||||
);
|
||||
refused(
|
||||
s.unlink_receipt(att, &format!("dup {tin}")).map(drop),
|
||||
"an unlink reason",
|
||||
);
|
||||
refused(
|
||||
s.withdraw_attachment(att, &format!("dup {tin}")),
|
||||
"a withdraw reason",
|
||||
);
|
||||
refused(
|
||||
s.create_entry(d(2, 1), &format!("x {tin}")).map(drop),
|
||||
"an entry description",
|
||||
);
|
||||
refused(
|
||||
s.reverse_entry(fx.entry, d(2, 1), &format!("x {tin}"))
|
||||
.map(drop),
|
||||
"a reversal",
|
||||
);
|
||||
let mut c = claim("high");
|
||||
c.note = Some(format!("see {tin}"));
|
||||
refused(s.review_entry(fx.entry, c).map(drop), "an attestation note");
|
||||
assert_eq!(s.head(), head, "a refusal journals nothing");
|
||||
s.verify().unwrap();
|
||||
}
|
||||
|
||||
/// The integrity table: each code seeded alone.
|
||||
#[test]
|
||||
fn integrity_detects_each_seeded_defect() {
|
||||
|
||||
Reference in new issue
Block a user