1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! Signed-license contract test — missing public key.
//!
//! Runs in its own integration-test binary so that the `OnceLock`
//! holding the public verification key is guaranteed unset. Tests in
//! `signed_license_lifecycle.rs` (a separate binary) own the
//! "key-is-set" half of the contract.
//!
//! Operator hard rules honoured:
//! - No production private keys in the repo.
//! - No test private keys committed to disk — fixtures are generated
//! in-memory inside each test.
//! - The public-key state is NOT modified by this test (the file is
//! reserved for the `set_license_public_key`-not-called case).
use pdfluent::{set_license_payload, Error};
#[test]
fn set_license_payload_without_public_key_returns_invalid_license() {
// The xfa-license::token::sign_license + generate_keypair APIs are
// gated behind the `signing` feature, which pdfluent activates via
// dev-dependencies. We do not even need to call them here: even
// with a syntactically-valid JSON shape, the umbrella rejects the
// call because no public key has been injected.
//
// The payload below would be invalid anyway (no signature), but
// the umbrella stops BEFORE attempting verification — this proves
// the "no public key configured" guard fires first.
let stub = r#"{"payload":{},"signature":""}"#;
let err = set_license_payload(stub).expect_err("must fail when no public key set");
match err {
Error::InvalidLicense { reason } => {
assert!(
reason.contains("no public key configured"),
"expected 'no public key configured' guard message, got {reason:?}"
);
assert_eq!(
Error::InvalidLicense {
reason: String::new()
}
.code(),
"E-LICENSE-INVALID"
);
}
other => panic!("expected Error::InvalidLicense, got {other:?}"),
}
}