mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 16:24:38 +00:00
craft-esign keep the send context off status requests
submit_request consumed the captured send context for every request kind. A status refresh for the current document submitted while another document's send was still outstanding then carried the old context. pump dropped its reply as stale. The context now goes only to the create submission that answers the taken send request. Every other request uses the current context.
This commit is contained in:
1 parent
df8f35d297
commit
52d874ae96
2 files changed
+42
-1
No files matched your search
@@ -70,3 +70,35 @@ fn reset_capabilities_reprobes_the_same_backend_after_an_out_of_band_sign_in() {
|
||||
|
||||
assert!(dialog.linked, "reset_capabilities did not pick up the backend's new linked state");
|
||||
}
|
||||
|
||||
/// The captured send context belongs only to the create submission that
|
||||
/// answers a taken [`SendRequest`]. A status refresh submitted for the
|
||||
/// current document while another document's send is still outstanding must
|
||||
/// carry the current context, or `pump` drops its reply as belonging to the
|
||||
/// abandoned send.
|
||||
#[test]
|
||||
fn status_for_the_current_document_is_not_consumed_by_an_outstanding_send_from_another() {
|
||||
let (mut dialog, hold) = ready();
|
||||
|
||||
// Document A's send is taken by the app but never submitted: its captured
|
||||
// context stays pending.
|
||||
dialog.open("doc-A".into(), "A.pdf".into(), None, who("alice"));
|
||||
send(&mut dialog, b"A bytes");
|
||||
|
||||
// The dialog moves on to document B, which already has an envelope the
|
||||
// host wants a status for.
|
||||
dialog.open("doc-B".into(), "B.pdf".into(), None, who("alice"));
|
||||
dialog.envelope = Some(envelope_for("doc-B", "alice"));
|
||||
let env_id = dialog.envelope.as_ref().map(|e| e.id.clone()).unwrap_or_default();
|
||||
|
||||
dialog.submit_request(Request::Status { envelope: env_id });
|
||||
let (_, status) = hold.take(|r| matches!(r, Request::Status { .. }));
|
||||
status.answer(Answer::Status(Envelope { status: EnvelopeStatus::Completed, ..envelope_for("doc-B", "alice") }));
|
||||
dialog.pump(1.0);
|
||||
|
||||
assert_eq!(
|
||||
dialog.envelope.as_ref().map(|e| e.status),
|
||||
Some(EnvelopeStatus::Completed),
|
||||
"B's status reply was dropped because the status request consumed A's outstanding send context"
|
||||
);
|
||||
}
|
||||
@@ -378,7 +378,16 @@ impl EsignDialog {
|
||||
/// install under whichever context happens to be current when this is
|
||||
/// finally called.
|
||||
pub fn submit_request(&mut self, request: Request) {
|
||||
let context = self.pending_send_context.take().unwrap_or_else(|| self.current_context());
|
||||
// The captured send context belongs to the create submission answering
|
||||
// a taken [`SendRequest`], and to nothing else. A status refresh (or
|
||||
// any other request) submitted while that send is still outstanding is
|
||||
// the current document's business: tagging it with the old send's
|
||||
// context would make `pump` drop its reply as stale.
|
||||
let context = if matches!(request, Request::Create { .. }) {
|
||||
self.pending_send_context.take().unwrap_or_else(|| self.current_context())
|
||||
} else {
|
||||
self.current_context()
|
||||
};
|
||||
// A public `Request::Status` submission is request-specific routing
|
||||
// state too: without this, `pump`'s `status_seq` guard never sees
|
||||
// this sequence and drops the reply that comes back for it.
|
||||
|
||||
Reference in new issue
Block a user