-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesktop_e2e.rs
More file actions
2831 lines (2701 loc) · 102 KB
/
Copy pathdesktop_e2e.rs
File metadata and controls
2831 lines (2701 loc) · 102 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Desktop-shell acceptance: two app backends driven through exactly the
//! layer the Tauri commands wrap ([`Session`]) — pairing via the bundle
//! *hex* a user pastes or scans, honest delivery states arriving as the
//! `node-event` payloads the webview would receive, verification,
//! settings persistence, and the backup → mnemonic → restore flow.
//!
//! No webview is involved: `commands.rs` is one-line wrappers over these
//! same methods, so this pins the whole behavior a UI click reaches.
use std::path::Path;
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
use base64::Engine;
use komms_desktop::commands;
use komms_desktop::session::{
hex_decode, NetworkSettings, Session, UiCustomIconCrop, UiCustomIconTarget,
UiDeviceLinkSelection, UiEvent, UiFolderSelection, UiFolderTarget, UiHint, UiImageCrop,
UiImageEditRecipe, UiImageRegion, UiLabelTarget, UiMentionSpan, UiPinTarget,
UiTextFormatHighlight, UiThemePreference,
};
use kult_ffi::{
edit_image, ImageCrop, ImageEditRecipe, ImageEditRegion, ImageEditRegionKind, KdfChoice,
};
fn image_recipe() -> (UiImageEditRecipe, ImageEditRecipe) {
(
UiImageEditRecipe {
crop: Some(UiImageCrop {
x: 1,
y: 0,
width: 23,
height: 16,
}),
rotation_quarter_turns: 1,
regions: vec![
UiImageRegion {
kind: "pixelate".to_owned(),
x: 0,
y: 0,
width: 8,
height: 8,
strength: 4,
},
UiImageRegion {
kind: "blur".to_owned(),
x: 8,
y: 0,
width: 8,
height: 12,
strength: 2,
},
],
},
ImageEditRecipe {
crop: Some(ImageCrop {
x: 1,
y: 0,
width: 23,
height: 16,
}),
rotation_quarter_turns: 1,
regions: vec![
ImageEditRegion {
kind: ImageEditRegionKind::Pixelate,
x: 0,
y: 0,
width: 8,
height: 8,
strength: 4,
},
ImageEditRegion {
kind: ImageEditRegionKind::Blur,
x: 8,
y: 0,
width: 8,
height: 12,
strength: 2,
},
],
},
)
}
fn canonical_audio(samples: usize) -> Vec<u8> {
let data_len = (samples * 2) as u32;
let mut bytes = Vec::with_capacity(44 + data_len as usize);
bytes.extend_from_slice(b"RIFF");
bytes.extend_from_slice(&(36 + data_len).to_le_bytes());
bytes.extend_from_slice(b"WAVEfmt ");
bytes.extend_from_slice(&16u32.to_le_bytes());
bytes.extend_from_slice(&1u16.to_le_bytes());
bytes.extend_from_slice(&1u16.to_le_bytes());
bytes.extend_from_slice(&16_000u32.to_le_bytes());
bytes.extend_from_slice(&32_000u32.to_le_bytes());
bytes.extend_from_slice(&2u16.to_le_bytes());
bytes.extend_from_slice(&16u16.to_le_bytes());
bytes.extend_from_slice(b"data");
bytes.extend_from_slice(&data_len.to_le_bytes());
for index in 0..samples {
bytes.extend_from_slice(&((index as i16 % 2_000) - 1_000).to_le_bytes());
}
bytes
}
fn native_audio_with_metadata(canonical: &[u8]) -> Vec<u8> {
let mut bytes = Vec::with_capacity(canonical.len() + 12);
bytes.extend_from_slice(b"RIFF");
bytes.extend_from_slice(&((canonical.len() + 4) as u32).to_le_bytes());
bytes.extend_from_slice(&canonical[8..36]);
bytes.extend_from_slice(b"LIST\x04\0\0\0leak");
bytes.extend_from_slice(&canonical[36..]);
bytes
}
/// Collects `node-event` payloads exactly as the webview would.
#[derive(Clone, Default)]
struct Events(Arc<Mutex<Vec<UiEvent>>>);
impl Events {
fn sink(&self) -> komms_desktop::session::EventSink {
let events = self.0.clone();
Box::new(move |event| events.lock().unwrap().push(event))
}
fn wait(&self, what: &str, pred: impl Fn(&UiEvent) -> bool) -> UiEvent {
let deadline = Instant::now() + Duration::from_secs(30);
loop {
if let Some(hit) = self.0.lock().unwrap().iter().find(|e| pred(e)) {
return hit.clone();
}
assert!(Instant::now() < deadline, "timed out waiting for {what}");
std::thread::sleep(Duration::from_millis(50));
}
}
fn count(&self, pred: impl Fn(&UiEvent) -> bool) -> usize {
self.0
.lock()
.unwrap()
.iter()
.filter(|event| pred(event))
.count()
}
}
/// Hermetic settings: loopback QUIC only, no mDNS — hints are explicit.
fn test_settings() -> NetworkSettings {
NetworkSettings {
listen: vec!["/ip4/127.0.0.1/udp/0/quic-v1".to_owned()],
mdns: false,
..NetworkSettings::default()
}
}
fn open(dir: &Path, name: &str, events: &Events) -> Session {
// Mirror the unlock command: persist settings, then boot.
let data_dir = dir.join(name);
let settings = test_settings();
settings.save(&data_dir).expect("settings save");
Session::open(
&data_dir,
"test-passphrase".to_owned(),
&settings,
KdfChoice::Mobile,
events.sink(),
)
.expect("session opens")
}
fn complete_group_security(session: &Session, group: &str) {
let deadline = Instant::now() + Duration::from_secs(30);
let mut upgrade_requested = false;
loop {
let security = session.group_security(group.to_owned()).unwrap();
match security.level {
"recipient_authenticated" => {
assert!(security.pending_devices.is_empty());
return;
}
"upgrade_required" if !upgrade_requested => {
session.upgrade_group_security(group.to_owned()).unwrap();
upgrade_requested = true;
}
"upgrade_required" | "upgrading" => {}
level => panic!("unexpected group security level: {level}"),
}
assert!(
Instant::now() < deadline,
"group origin exchange did not complete: {security:?}"
);
std::thread::sleep(Duration::from_millis(50));
}
}
fn accept_group_invitation(session: &Session, events: &Events, group: &str, what: &str) {
events.wait(
what,
|event| matches!(event, UiEvent::GroupInvitationReceived { group: id, .. } if id == group),
);
let invitation = session
.group_invitations()
.unwrap()
.into_iter()
.find(|invitation| invitation.group == group)
.expect("group invitation is listed");
assert_eq!(
session.accept_group_invitation(invitation.id).unwrap(),
group
);
events.wait(
"group invitation acceptance",
|event| matches!(event, UiEvent::GroupInvitationAccepted { group: id, .. } if id == group),
);
}
#[test]
fn desktop_message_request_inbox_keeps_unknown_senders_separate() {
let directory = tempfile::tempdir().unwrap();
let bob_events = Events::default();
let bob = open(directory.path(), "request-bob", &bob_events);
let accept = open(directory.path(), "request-accept", &Events::default());
let delete = open(directory.path(), "request-delete", &Events::default());
let block = open(directory.path(), "request-block", &Events::default());
let bob_addr = listen_addr(&bob);
for (sender, preview) in [
(&accept, "please accept"),
(&delete, "please delete"),
(&block, "please block"),
] {
let _ = listen_addr(sender);
let _ = sender.my_bundle().unwrap();
let bundle = bob.my_bundle().unwrap();
let peer = sender
.add_contact(
"Bob".to_owned(),
&bundle.hex,
&multiaddr_hint(bob_addr.clone()),
)
.unwrap();
sender.send(peer, preview.to_owned()).unwrap();
}
bob_events.wait("message request", |event| {
matches!(event, UiEvent::MessageRequestReceived { .. })
});
let deadline = Instant::now() + Duration::from_secs(30);
let requests = loop {
let requests = bob.message_requests().unwrap();
if requests.len() == 3 {
break requests;
}
assert!(Instant::now() < deadline, "three requests were not listed");
std::thread::sleep(Duration::from_millis(50));
};
assert!(bob.contacts().unwrap().is_empty());
let request_id = |preview: &str| {
requests
.iter()
.find(|request| request.preview == preview)
.unwrap()
.id
.clone()
};
let peer = bob
.accept_message_request(request_id("please accept"), "Accepted sender".to_owned())
.unwrap();
bob.delete_message_request(request_id("please delete"))
.unwrap();
bob.block_message_request(request_id("please block"))
.unwrap();
assert!(bob.message_requests().unwrap().is_empty());
assert_eq!(bob.contacts().unwrap()[0].name, "Accepted sender");
assert_eq!(bob.messages(peer).unwrap()[0].body, "please accept");
bob_events.wait("request accepted", |event| {
matches!(event, UiEvent::MessageRequestAccepted { .. })
});
bob_events.wait("request deleted", |event| {
matches!(event, UiEvent::MessageRequestDeleted { .. })
});
bob_events.wait("request blocked", |event| {
matches!(event, UiEvent::MessageRequestBlocked { .. })
});
accept.stop();
delete.stop();
block.stop();
bob.stop();
}
#[test]
fn desktop_linked_device_ceremony_and_sync_use_only_session_surface() {
let directory = tempfile::tempdir().unwrap();
let source_events = Events::default();
let target_events = Events::default();
let source = open(directory.path(), "device-source", &source_events);
let target = open(directory.path(), "device-target", &target_events);
source
.send_note_to_self("source-only history".to_owned())
.unwrap();
let source_device = source.device_id().unwrap();
let target_device = target.device_id().unwrap();
let offer = source.begin_device_link().unwrap();
assert!(offer.qr_svg.contains("<svg"));
let accepted = target
.accept_device_link(offer.hex, "Laptop".to_owned())
.unwrap();
assert_eq!(accepted.confirmation_code.len(), 6);
assert_eq!(
source
.device_link_confirmation_code(accepted.response_hex.clone())
.unwrap(),
accepted.confirmation_code
);
let package = source
.approve_device_link(
accepted.response_hex,
UiDeviceLinkSelection {
contacts: false,
organization: false,
history: false,
},
true,
)
.unwrap();
target.complete_device_link(package, true).unwrap();
assert_eq!(source.status().unwrap().peer, target.status().unwrap().peer);
assert_ne!(source_device, target_device);
assert!(target.note_to_self_messages().unwrap().is_empty());
assert_eq!(source.linked_devices().unwrap().len(), 2);
target_events.wait("device link completion", |event| {
matches!(event, UiEvent::DeviceLinkCompleted { device, .. } if device == &target_device)
});
let tablet = open(directory.path(), "device-tablet", &Events::default());
let offer = source.begin_device_link().unwrap();
let accepted = tablet
.accept_device_link(offer.hex, "Tablet".to_owned())
.unwrap();
let quorum = source
.approve_device_link(
accepted.response_hex,
UiDeviceLinkSelection {
contacts: false,
organization: false,
history: false,
},
true,
)
.unwrap_err();
assert!(quorum.contains("additional active-device approval"));
let request = source.device_link_approval_request().unwrap();
let approval = target.approve_device_link_request(request).unwrap();
let package = source
.accept_device_link_approval(approval)
.unwrap()
.expect("quorum finalizes link");
tablet.complete_device_link(package, true).unwrap();
let authority_sync = source.export_device_sync(target_device.clone()).unwrap();
target.import_device_sync(authority_sync).unwrap();
let quorum = source
.rename_linked_device(target_device.clone(), "Travel laptop".to_owned())
.unwrap_err();
assert!(quorum.contains("additional active-device approval"));
let request = source.device_authority_approval_request().unwrap();
let approval = target.approve_device_authority_request(request).unwrap();
assert!(source.accept_device_authority_approval(approval).unwrap());
let sync = source.export_device_sync(target_device.clone()).unwrap();
target.import_device_sync(sync).unwrap();
assert!(target
.linked_devices()
.unwrap()
.iter()
.any(|device| device.id == target_device && device.name == "Travel laptop"));
assert!(source.device_authority_conflicts().unwrap().is_empty());
assert!(source.contact_authority_conflicts().unwrap().is_empty());
source.stop();
target.stop();
tablet.stop();
}
fn wait_authority_generation(
session: &Session,
group: &str,
generation: u64,
) -> komms_desktop::session::UiGroupAuthority {
let deadline = Instant::now() + Duration::from_secs(30);
loop {
let authority = session.group_authority(group.to_owned()).unwrap();
if authority.signed && authority.generation >= generation {
return authority;
}
assert!(
Instant::now() < deadline,
"desktop authority generation did not converge"
);
std::thread::sleep(Duration::from_millis(50));
}
}
fn wait_closed_poll(
session: &Session,
group: &str,
poll_id: &str,
) -> komms_desktop::session::UiGroupPoll {
let deadline = Instant::now() + Duration::from_secs(30);
loop {
if let Some(poll) = session
.group_polls(group.to_owned())
.unwrap()
.into_iter()
.find(|poll| poll.id == poll_id && poll.closed)
{
return poll;
}
assert!(
Instant::now() < deadline,
"desktop poll closure did not converge"
);
std::thread::sleep(Duration::from_millis(50));
}
}
#[test]
fn desktop_ephemeral_controls_match_shared_honesty_and_block_render_bypasses() {
let fixture: serde_json::Value = serde_json::from_str(include_str!(
"../../../../fixtures/c4-ephemeral-parity.json"
))
.unwrap();
let html = include_str!("../../ui/index.html");
let frontend = include_str!("../../ui/main.js");
for lifetime in fixture["text_lifetimes"].as_array().unwrap() {
assert!(html.contains(&format!("value=\"{}\"", lifetime.as_u64().unwrap())));
}
assert!(html.contains("recipients and other devices may retain copies"));
assert!(frontend.contains("send_disappearing"));
assert!(frontend.contains("send_group_disappearing"));
assert!(frontend.contains("consume_view_once_attachment"));
assert!(frontend.contains("if (!attachment.view_once) actions.append"));
assert!(frontend.contains("preview && !attachment.view_once"));
assert!(frontend.contains("!attachment.view_once && isAudio"));
}
#[test]
fn desktop_first_run_authority_uses_native_save_and_retryable_errors() {
let html = include_str!("../../ui/index.html");
let frontend = include_str!("../../ui/main.js");
let authority_template = html
.split("<template id=\"tpl-recovery-authority\">")
.nth(1)
.unwrap()
.split("</template>")
.next()
.unwrap();
assert!(!authority_template.contains("data-f=\"path\""));
assert!(authority_template.contains("Save offline authority…"));
assert!(authority_template.contains("data-l10n=\"recovery_authority_save\""));
assert!(authority_template.contains("data-l10n=\"recovery_authority_required_body\""));
assert!(frontend.contains("const path = await savePath({"));
assert!(frontend.contains("defaultPath: l10n(\"recovery_authority_filename\")"));
assert!(frontend.contains("recovery_authority_destination_exists"));
assert!(frontend.contains("recovery_authority_export_failed"));
}
#[test]
fn startup_wait_is_explained_and_kept_modal_across_apps() {
let html = include_str!("../../ui/index.html");
let frontend = include_str!("../../ui/main.js");
assert!(html.contains("id=\"startup-dialog\""));
assert!(html.contains("starting the node can take up to 30 seconds"));
assert!(html.contains("<progress aria-label=\"Decrypting the store and starting the node\""));
assert!(frontend.contains("startupDialog.showModal()"));
assert!(frontend.contains("event.preventDefault()"));
assert!(frontend.contains("startupDialog.close()"));
let android =
include_str!("../../../android/app/src/main/kotlin/komms/android/GateActivity.kt");
let android_strings = include_str!("../../../android/app/src/main/res/values/strings.xml");
assert!(android.contains(".setCancelable(false)"));
assert!(android.contains("showStartupDialog()"));
assert!(android_strings.contains("starting the node can take up to 30 seconds"));
let ios = include_str!("../../../ios/KommsApp/Sources/GateView.swift");
assert!(ios.contains("if working"));
assert!(ios.contains("Starting Komms"));
assert!(ios.contains("starting the node can take up to 30 seconds"));
}
#[test]
fn desktop_macos_bundle_declares_libp2p_local_network_access() {
let plist = include_str!("../Info.plist");
assert!(plist.contains("<key>NSLocalNetworkUsageDescription</key>"));
assert!(plist.contains("<key>NSBonjourServices</key>"));
assert!(plist.contains("<string>_p2p._udp</string>"));
}
#[test]
fn desktop_status_poll_is_bounded_and_never_leaves_loading_placeholders() {
let ffi = include_str!("../../../../crates/kult-ffi/src/lib.rs");
let frontend = include_str!("../../ui/main.js");
assert!(ffi.contains("rt.block_on(async {"));
assert!(ffi.contains("tokio::time::timeout(Duration::from_secs(1), rt.net.nat_status()).await"));
assert!(frontend.contains("l10n(\"status_discovery_unavailable\")"));
assert!(frontend.contains("l10n(\"status_nat_unavailable\")"));
assert!(frontend.contains("l10n(\"status_unavailable\")"));
}
#[test]
fn operating_mode_contract_and_familiar_status_are_present_in_every_shell() {
let fixture: serde_json::Value = serde_json::from_str(include_str!(
"../../../../fixtures/operating-mode-settings-v1.json"
))
.unwrap();
assert_eq!(fixture["mode"], "private");
assert_eq!(fixture["rendezvous"][0]["private_via_tor"], true);
assert_eq!(fixture["wake"][0]["private_via_tor"], true);
let html = include_str!("../../ui/index.html");
let frontend = include_str!("../../ui/main.js");
for value in ["standard", "private", "sovereign"] {
assert!(html.contains(&format!("name=\"set-mode\" value=\"{value}\"")));
}
for field in [
"set-provider-directory",
"set-provider-roots",
"set-rendezvous",
"set-wake",
"set-tor-proxy",
"set-standard-disclosure",
"set-sovereign-direct",
] {
assert!(html.contains(&format!("id=\"{field}\"")));
}
for status in [
"connection_connected",
"connection_fallback_ready",
"connection_waiting",
] {
assert!(frontend.contains(status));
}
assert!(frontend.contains("set_mode_private_disclosure"));
assert!(frontend.contains("sovereign-direct-row"));
let android_layout =
include_str!("../../../android/app/src/main/res/layout/activity_settings.xml");
let android_strings = include_str!("../../../android/app/src/main/res/values/strings.xml");
for field in [
"set_mode_standard",
"set_mode_private",
"set_mode_sovereign",
"set_provider_directory",
"set_provider_roots",
"set_rendezvous",
"set_tor_proxy",
] {
assert!(android_layout.contains(&format!("@+id/{field}")));
}
for status in ["Connected", "Fallback ready", "Waiting for a route"] {
assert!(android_strings.contains(status));
}
assert!(android_strings.contains("does not claim non-collusion"));
let ios_settings = include_str!("../../../ios/KommsApp/Sources/SettingsView.swift");
let ios_status = include_str!("../../../ios/KommsApp/Sources/MainView.swift");
for mode in ["mode_standard", "mode_private", "mode_sovereign"] {
assert!(ios_settings.contains(mode));
}
for status in [
"connection_connected",
"connection_fallback_ready",
"connection_waiting",
] {
assert!(ios_status.contains(status));
}
assert!(ios_settings.contains("set_mode_private_disclosure"));
}
#[test]
fn desktop_share_dialog_surfaces_generation_errors_and_scopes_its_listener() {
let html = include_str!("../../ui/index.html");
let frontend = include_str!("../../ui/main.js");
assert!(html.contains("data-f=\"share-status\" role=\"status\""));
assert!(frontend.contains("l10n(\"share_unavailable\")"));
assert!(frontend.contains("[bundle, addrSvg, nodeStatus] = await Promise.all(["));
assert!(frontend.contains("invoke(\"my_bundle\")"));
assert!(frontend.contains("invoke(\"address_qr\")"));
assert!(frontend.contains("invoke(\"status\")"));
assert!(frontend.contains("nodeStatus.connect_code"));
assert!(frontend.contains("nodeStatus.address"));
assert!(frontend.contains("view.addEventListener(\"click\""));
}
#[test]
fn android_shell_uses_the_shared_light_and_dark_brand_tokens() {
let light = include_str!("../../../android/app/src/main/res/values/colors.xml");
let dark = include_str!("../../../android/app/src/main/res/values-night/colors.xml");
for token in [
"<color name=\"background\">#FAFAFA</color>",
"<color name=\"surface\">#FFFFFF</color>",
"<color name=\"surface_raised\">#FFF8DC</color>",
"<color name=\"accent\">#B83431</color>",
] {
assert!(light.contains(token), "missing light brand token: {token}");
}
for token in [
"<color name=\"background\">#0F2633</color>",
"<color name=\"surface\">#153746</color>",
"<color name=\"surface_raised\">#193F4F</color>",
"<color name=\"accent\">#F2B705</color>",
] {
assert!(dark.contains(token), "missing dark brand token: {token}");
}
let main = include_str!("../../../android/app/src/main/res/layout/activity_main.xml");
let chat = include_str!("../../../android/app/src/main/res/layout/activity_chat.xml");
assert!(main.contains("@color/toolbar_background"));
assert!(main.contains("@drawable/bg_brand_panel"));
assert!(chat.contains("@drawable/bg_compose_input"));
assert!(chat.contains("@style/ThemeOverlay.Komms.Toolbar"));
}
#[test]
fn desktop_poll_ui_keeps_visibility_policy_and_uses_inert_exact_text() {
let html = include_str!("../../ui/index.html");
let frontend = include_str!("../../ui/main.js");
assert!(html.contains("Votes are visible to every member. This is not anonymous."));
assert!(html.contains("The poll creator can close it"));
assert!(html.contains("a group owner can also commit a signed moderation snapshot"));
assert!(frontend.contains("create_group_poll"));
assert!(frontend.contains("vote_group_poll"));
assert!(frontend.contains("close_group_poll"));
assert!(frontend.contains("moderate_group_poll_close"));
assert!(frontend.contains("new TextEncoder().encode(value).length"));
let renderer = frontend
.split("function renderPolls")
.nth(1)
.unwrap()
.split("async function renderMessages")
.next()
.unwrap();
assert!(renderer.contains("textContent = poll.question"));
assert!(renderer.contains("textContent = option.text"));
assert!(!renderer.contains("innerHTML"));
let android =
include_str!("../../../android/app/src/main/kotlin/komms/android/GroupChatActivity.kt");
let android_strings = include_str!("../../../android/app/src/main/res/values/strings.xml");
assert!(android.contains("is Event.PollUpdated -> event.group == groupId"));
assert!(android.contains("session.createGroupPoll(groupId, exactQuestion, exactChoices)"));
assert!(android.contains("session.voteGroupPoll(groupId, poll.author, poll.id, option.id)"));
assert!(android_strings.contains("This is not anonymous"));
let ios = include_str!("../../../ios/KommsApp/Sources/GroupChatView.swift");
let ios_model = include_str!("../../../ios/KommsApp/Sources/AppModel.swift");
assert!(ios.contains("private struct GroupPollCard"));
assert!(ios.contains("Create visible-vote poll"));
assert!(ios.contains("This is not anonymous"));
assert!(ios_model.contains(".pollUpdated"));
assert!(ios_model.contains("try session.createGroupPoll"));
}
#[test]
fn desktop_text_formatting_matches_shared_corpus_and_uses_inert_dom_only() {
let fixture: serde_json::Value = serde_json::from_str(include_str!(
"../../../../fixtures/b9-text-formatting-parity.json"
))
.unwrap();
let directory = tempfile::tempdir().unwrap();
let session = open(directory.path(), "text-formatting", &Events::default());
for case in fixture["cases"].as_array().unwrap() {
let highlights = case["highlights"]
.as_array()
.unwrap()
.iter()
.map(|highlight| UiTextFormatHighlight {
start: highlight["start"].as_u64().unwrap() as u32,
end: highlight["end"].as_u64().unwrap() as u32,
})
.collect();
let formatted = session
.format_text(case["source"].as_str().unwrap().to_owned(), highlights)
.unwrap();
assert_eq!(formatted.source, case["source"].as_str().unwrap());
assert_eq!(formatted.plain_text, case["plain_text"].as_str().unwrap());
assert_eq!(
formatted.used_fallback,
case["used_fallback"].as_bool().unwrap()
);
assert_eq!(
formatted
.blocks
.iter()
.map(|block| block.kind.as_str())
.collect::<Vec<_>>(),
case["block_kinds"]
.as_array()
.unwrap()
.iter()
.map(|kind| kind.as_str().unwrap())
.collect::<Vec<_>>()
);
}
let frontend = include_str!("../../ui/main.js");
assert!(frontend.contains("appendFormattedBody"));
assert!(frontend.contains("document.createTextNode(run.text)"));
assert!(frontend.contains("formatted.plain_text"));
let formatter = frontend
.split("function styledRun")
.nth(1)
.unwrap()
.split("async function refreshGroups")
.next()
.unwrap();
assert!(!formatter.contains("innerHTML"));
assert!(!formatter.contains(".src ="));
assert!(!formatter.contains(".href ="));
let android =
include_str!("../../../android/app/src/main/kotlin/komms/android/TextFormatting.kt");
assert!(android.contains("output.toString() == formatted.plainText"));
assert!(!android.contains("URLSpan"));
for source in [
include_str!("../../../android/app/src/main/kotlin/komms/android/ChatActivity.kt"),
include_str!("../../../android/app/src/main/kotlin/komms/android/GroupChatActivity.kt"),
include_str!("../../../android/app/src/main/kotlin/komms/android/NoteToSelfActivity.kt"),
include_str!("../../../android/app/src/main/kotlin/komms/android/ScheduledMessageUi.kt"),
] {
assert!(source.contains("showFormattedText"));
}
let swift_renderer = include_str!("../../../ios/KommsApp/Sources/FormattedTextView.swift");
assert!(swift_renderer.contains("formatted.plainText"));
assert!(!swift_renderer.contains("NSDataDetector"));
for source in [
include_str!("../../../ios/KommsApp/Sources/ChatView.swift"),
include_str!("../../../ios/KommsApp/Sources/GroupChatView.swift"),
include_str!("../../../ios/KommsApp/Sources/NoteToSelfView.swift"),
include_str!("../../../ios/KommsApp/Sources/ScheduledMessageView.swift"),
] {
assert!(source.contains("FormattedTextView"));
}
session.stop();
}
#[test]
fn desktop_private_contact_rename_is_normalized_warned_duplicate_capable_and_durable() {
let fixture: serde_json::Value = serde_json::from_str(include_str!(
"../../../../fixtures/b5-contact-rename-parity.json"
))
.unwrap();
let directory = tempfile::tempdir().unwrap();
let events = Events::default();
let mut alice = open(directory.path(), "contact-rename-alice", &events);
let bob = open(directory.path(), "contact-rename-bob", &Events::default());
alice
.add_contact(
fixture["duplicate_name"].as_str().unwrap().to_owned(),
&alice.my_bundle().unwrap().hex,
&[],
)
.unwrap();
let bob_peer = alice
.add_contact("Bob".to_owned(), &bob.my_bundle().unwrap().hex, &[])
.unwrap();
let queued_before = alice.status().unwrap().queued;
let normalized = alice
.rename_contact(
bob_peer.clone(),
fixture["decomposed_name"].as_str().unwrap().to_owned(),
false,
)
.unwrap();
assert_eq!(
normalized.normalized_name,
fixture["normalized_name"].as_str().unwrap()
);
assert!(normalized.changed_by_normalization);
let duplicate = alice
.assess_contact_name(
bob_peer.clone(),
fixture["duplicate_name"].as_str().unwrap().to_owned(),
)
.unwrap();
assert_eq!(duplicate.duplicate_count, 1);
assert_eq!(duplicate.warnings, ["duplicate_name"]);
assert!(alice
.rename_contact(
bob_peer.clone(),
fixture["duplicate_name"].as_str().unwrap().to_owned(),
false,
)
.is_err());
alice
.rename_contact(
bob_peer.clone(),
fixture["duplicate_name"].as_str().unwrap().to_owned(),
true,
)
.unwrap();
assert_eq!(
alice
.contacts()
.unwrap()
.into_iter()
.filter(|contact| contact.name == fixture["duplicate_name"].as_str().unwrap())
.count(),
2
);
events.wait("contact renamed", |event| {
matches!(event, UiEvent::ContactRenamed { peer, name }
if peer == &bob_peer && name == fixture["duplicate_name"].as_str().unwrap())
});
assert_eq!(alice.status().unwrap().queued, queued_before);
alice.stop();
alice = open(directory.path(), "contact-rename-alice", &Events::default());
assert_eq!(
alice
.contacts()
.unwrap()
.into_iter()
.find(|contact| contact.peer == bob_peer)
.unwrap()
.name,
fixture["duplicate_name"].as_str().unwrap()
);
alice.stop();
bob.stop();
}
#[test]
fn desktop_screen_security_is_always_on_best_effort_with_rapid_lock() {
let fixture: serde_json::Value = serde_json::from_str(include_str!(
"../../../../fixtures/b14-screen-security-parity.json"
))
.unwrap();
let policy = commands::screen_security_policy();
assert!(policy.always_on);
assert_eq!(
policy.capture_prevention,
fixture["platforms"]["desktop"]["capture_prevention"]
);
assert_eq!(
policy.background_obscuring,
fixture["platforms"]["desktop"]["background_obscuring"]
);
assert_eq!(policy.rapid_lock, "platform_enforced");
assert!(!policy.limitations.is_empty());
let config = include_str!("../tauri.conf.json");
let frontend = include_str!("../../ui/main.js");
assert!(config.contains(r#""contentProtected": true"#));
assert!(frontend.contains("event.ctrlKey || event.metaKey"));
assert!(frontend.contains("event.shiftKey"));
assert!(frontend.contains("rapidLock()"));
assert_eq!(fixture["desktop_shortcut"], "Ctrl/Cmd+Shift+L");
}
#[test]
fn desktop_incognito_keyboard_covers_every_editable_text_field_before_unlock() {
let fixture: serde_json::Value = serde_json::from_str(include_str!(
"../../../../fixtures/b15-incognito-keyboard-parity.json"
))
.unwrap();
let policy = commands::incognito_keyboard_policy();
assert!(policy.always_on);
assert!(policy.applies_before_unlock);
assert_eq!(
policy.personalized_learning,
fixture["platforms"]["desktop"]["personalized_learning"]
);
assert_eq!(
policy.protected_fields,
fixture["protected_fields"]
.as_array()
.unwrap()
.iter()
.map(|value| value.as_str().unwrap().to_owned())
.collect::<Vec<_>>()
);
assert!(policy
.limitations
.iter()
.any(|text| text.contains("webview")));
let html = include_str!("../../ui/index.html");
let javascript = include_str!("../../ui/main.js");
let editable_text_fields = html.matches("type=\"text\"").count()
+ html.matches("type=\"password\"").count()
+ html.matches("<textarea").count()
- html.matches("type=\"text\" readonly").count()
- html
.matches("<textarea class=\"share-hex\" rows=\"4\" readonly")
.count();
assert_eq!(50, editable_text_fields);
assert_eq!(
editable_text_fields,
html.matches("data-incognito-input=").count()
);
assert!(html.contains("type=\"password\" id=\"gate-mnemonic\""));
assert!(html
.contains("type=\"text\" id=\"gate-recovery-package\" data-incognito-input=\"technical\""));
assert!(html.contains(
"type=\"password\" id=\"gate-recovery-mnemonic\" data-incognito-input=\"mnemonic\""
));
for attribute in [
"autocomplete",
"autocorrect",
"autocapitalize",
"spellcheck",
] {
assert!(
javascript.contains(&format!("setAttribute(\"{attribute}\", \"off\")"))
|| javascript.contains(&format!("setAttribute(\"{attribute}\", \"false\")"))
);
}
assert!(javascript.contains("applyIncognitoInputPrivacy(body)"));
}
#[test]
fn private_theme_defaults_persists_restarts_and_emits_one_local_event() {
let fixture: serde_json::Value =
serde_json::from_str(include_str!("../../../../fixtures/b12-theme-parity.json")).unwrap();
assert_eq!(
fixture["preferences"],
serde_json::json!(["system", "light", "dark"])
);
let directory = tempfile::tempdir().unwrap();
let events = Events::default();
let session = open(directory.path(), "theme", &events);
let queued = session.status().unwrap().queued;
assert_eq!(
session.theme().unwrap().preference,
UiThemePreference::System
);
assert!(!session.theme().unwrap().persisted);
assert!(session.set_theme(UiThemePreference::Dark).unwrap());
assert!(!session.set_theme(UiThemePreference::Dark).unwrap());
events.wait("theme changed", |event| {
matches!(event, UiEvent::ThemeChanged)
});
assert_eq!(session.status().unwrap().queued, queued);
session.stop();
let reopened = open(directory.path(), "theme", &Events::default());
assert_eq!(
reopened.theme().unwrap().preference,
UiThemePreference::Dark
);
assert!(reopened.theme().unwrap().persisted);
reopened.stop();
}
#[test]
fn desktop_custom_icons_render_from_local_data_urls_and_survive_restart() {
let fixture: serde_json::Value = serde_json::from_str(include_str!(
"../../../../fixtures/b13-custom-icon-parity.json"
))
.unwrap();
let directory = tempfile::tempdir().unwrap();
let events = Events::default();
let session = open(directory.path(), "icons", &events);
let queued = session.status().unwrap().queued;
let note = UiCustomIconTarget {
kind: "note_to_self".to_owned(),
id: None,
};
assert!(session.custom_icon(note.clone()).unwrap().is_none());
let note_icon = session
.set_bundled_custom_icon(note.clone(), "compass".to_owned())
.unwrap();
assert_eq!(note_icon.media_type, "image/png");
assert_eq!((note_icon.width, note_icon.height), (256, 256));
assert!(note_icon.data_url.starts_with("data:image/png;base64,"));
events.wait("custom icons changed", |event| {
matches!(event, UiEvent::CustomIconsChanged)
});
let folder = session.create_folder("Icon target".to_owned()).unwrap();
let folder_target = UiCustomIconTarget {
kind: "folder".to_owned(),
id: Some(folder.id),
};
let source = directory.path().join("desktop-icon.png");
let pixels = image::ImageBuffer::from_fn(8, 6, |x, y| {
image::Rgba([(x * 23) as u8, (y * 37) as u8, 120, 255])
});
image::DynamicImage::ImageRgba8(pixels)
.save(&source)
.unwrap();
let folder_icon = session
.set_custom_icon_from_path(
folder_target.clone(),
source.display().to_string(),
Some(UiCustomIconCrop {
x: 1,
y: 0,