- commit
- 6a079fec85ff06b03533c39bf1d0ef0dcc0f7e94
- parent
- 549b90487a583fadf5b744bb29685a39b82ee06f
- author
- Dami <dami.etoile@gmail.com>
| M | crates/ | 106 | +++++++++++++++++++++++------- |
@@ -2636,6 +2636,20 @@ fn load_invitation_file(
26362636 expected_host: EndpointId,26372637 expected_peer: EndpointId,26382638 required_grants: InvitationGrants,2639+) -> Result<String> {2640+ let now = SystemTime::now()2641+ .duration_since(UNIX_EPOCH)2642+ .context("system clock is before the Unix epoch")?2643+ .as_secs();2644+ load_invitation_file_at(path, expected_host, expected_peer, required_grants, now)2645+}2646+2647+fn load_invitation_file_at(2648+ path: &Path,2649+ expected_host: EndpointId,2650+ expected_peer: EndpointId,2651+ required_grants: InvitationGrants,2652+ now: u64,26392653 ) -> Result<String> {26402654 let mut options = OpenOptions::new();26412655 options.read(true);@@ -2713,10 +2727,6 @@ fn load_invitation_file(
27132727 || invitation.claims.grants.contains(InvitationGrants::GAMEPAD),27142728 "invitation must grant pointer/keyboard or gamepad for the probe input acknowledgment"27152729 );2716- let now = SystemTime::now()2717- .duration_since(UNIX_EPOCH)2718- .context("system clock is before the Unix epoch")?2719- .as_secs();27202730 ensure!(27212731 now >= invitation27222732 .claims@@ -3398,34 +3408,54 @@ mod tests {
33983408 33993409 write_private_invitation(&path, &token, b"\n");34003410 assert_eq!(3401- load_invitation_file(3411+ load_invitation_file_at(34023412 &path,34033413 host.public(),34043414 peer.public(),34053415 InvitationGrants::VIEW.union(InvitationGrants::GAMEPAD),3416+ now,34063417 )34073418 .unwrap(),34083419 token34093420 );34103421 write_private_invitation(&path, &token, b"\r\n");34113422 assert!(3412- load_invitation_file(&path, host.public(), peer.public(), InvitationGrants::VIEW,)3413- .is_ok()3423+ load_invitation_file_at(3424+ &path,3425+ host.public(),3426+ peer.public(),3427+ InvitationGrants::VIEW,3428+ now,3429+ )3430+ .is_ok()34143431 );34153432 assert!(3416- load_invitation_file(&path, other.public(), peer.public(), InvitationGrants::VIEW,)3417- .is_err()3433+ load_invitation_file_at(3434+ &path,3435+ other.public(),3436+ peer.public(),3437+ InvitationGrants::VIEW,3438+ now,3439+ )3440+ .is_err()34183441 );34193442 assert!(3420- load_invitation_file(&path, host.public(), other.public(), InvitationGrants::VIEW,)3421- .is_err()3443+ load_invitation_file_at(3444+ &path,3445+ host.public(),3446+ other.public(),3447+ InvitationGrants::VIEW,3448+ now,3449+ )3450+ .is_err()34223451 );34233452 assert!(3424- load_invitation_file(3453+ load_invitation_file_at(34253454 &path,34263455 host.public(),34273456 peer.public(),34283457 InvitationGrants::POINTER_KEYBOARD,3458+ now,34293459 )34303460 .is_err()34313461 );@@ -3439,10 +3469,16 @@ mod tests {
34393469 );34403470 write_private_invitation(&path, &view_only, b"\n");34413471 assert!(3442- load_invitation_file(&path, host.public(), peer.public(), InvitationGrants::VIEW,)3443- .unwrap_err()3444- .to_string()3445- .contains("input acknowledgment")3472+ load_invitation_file_at(3473+ &path,3474+ host.public(),3475+ peer.public(),3476+ InvitationGrants::VIEW,3477+ now,3478+ )3479+ .unwrap_err()3480+ .to_string()3481+ .contains("input acknowledgment")34463482 );34473483 34483484 let expired = test_invitation(@@ -3454,15 +3490,27 @@ mod tests {
34543490 );34553491 write_private_invitation(&path, &expired, b"\n");34563492 assert!(3457- load_invitation_file(&path, host.public(), peer.public(), InvitationGrants::VIEW,)3458- .unwrap_err()3459- .to_string()3460- .contains("expired")3493+ load_invitation_file_at(3494+ &path,3495+ host.public(),3496+ peer.public(),3497+ InvitationGrants::VIEW,3498+ now,3499+ )3500+ .unwrap_err()3501+ .to_string()3502+ .contains("expired")34613503 );34623504 write_private_invitation(&path, &token, b"\n\n");34633505 assert!(3464- load_invitation_file(&path, host.public(), peer.public(), InvitationGrants::VIEW,)3465- .is_err()3506+ load_invitation_file_at(3507+ &path,3508+ host.public(),3509+ peer.public(),3510+ InvitationGrants::VIEW,3511+ now,3512+ )3513+ .is_err()34663514 );34673515 let future = test_invitation(34683516 &host,@@ -3473,10 +3521,16 @@ mod tests {
34733521 );34743522 write_private_invitation(&path, &future, b"\n");34753523 assert!(3476- load_invitation_file(&path, host.public(), peer.public(), InvitationGrants::VIEW,)3477- .unwrap_err()3478- .to_string()3479- .contains("future")3524+ load_invitation_file_at(3525+ &path,3526+ host.public(),3527+ peer.public(),3528+ InvitationGrants::VIEW,3529+ now,3530+ )3531+ .unwrap_err()3532+ .to_string()3533+ .contains("future")34803534 );34813535 }34823536