Debian Codegraph @

third_party/rust/webrtc-sdp/src/anonymizer_tests.rs

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 use super::*;
6
7 #[test]
8 fn test_mask_ip() {
9 let mut anon = StatefulSdpAnonymizer::default();
10 let v4 = [
11 Ipv4Addr::new(127, 0, 0, 1),
12 Ipv4Addr::new(10, 0, 0, 1),
13 Ipv4Addr::new(1, 1, 1, 1),
14 ];
15 let v4_masked = [
16 Ipv4Addr::new(0, 0, 0, 1),
17 Ipv4Addr::new(0, 0, 0, 2),
18 Ipv4Addr::new(0, 0, 0, 3),
19 ];
20 let v6 = [
21 Ipv6Addr::from(0),
22 Ipv6Addr::from(528_189_235),
23 Ipv6Addr::from(1_623_734_988_148_990),
24 ];
25 let v6_masked = [Ipv6Addr::from(1), Ipv6Addr::from(2), Ipv6Addr::from(3)];
26 for _ in 0..2 {
27 assert_eq!(anon.mask_ip(&IpAddr::V4(v4[0])), v4_masked[0]);
28 assert_eq!(anon.mask_ip(&IpAddr::V6(v6[0])), v6_masked[0]);
29
30 assert_eq!(anon.mask_ip(&IpAddr::V4(v4[1])), v4_masked[1]);
31 assert_eq!(anon.mask_ip(&IpAddr::V6(v6[1])), v6_masked[1]);
32
33 assert_eq!(anon.mask_ip(&IpAddr::V4(v4[2])), v4_masked[2]);
34 assert_eq!(anon.mask_ip(&IpAddr::V6(v6[2])), v6_masked[2]);
35 }
36 }
37
38 #[test]
39 fn test_mask_port() {
40 let mut anon = StatefulSdpAnonymizer::default();
41 let ports = [0, 125, 12346];
42 let masked_ports = [1, 2, 3];
43 for _ in 0..2 {
44 assert_eq!(anon.mask_port(ports[0]), masked_ports[0]);
45 assert_eq!(anon.mask_port(ports[1]), masked_ports[1]);
46 assert_eq!(anon.mask_port(ports[2]), masked_ports[2]);
47 }
48 }
49
50 #[test]
51 fn test_mask_ice_password() {
52 let mut anon = StatefulSdpAnonymizer::default();
53 let passwords = ["vasdfioqwenl14082`14", "0", "ncp HY878hp(poh"];
54 let masked_passwords = [
55 "ice-password-00000001",
56 "ice-password-00000002",
57 "ice-password-00000003",
58 ];
59 for _ in 0..2 {
60 assert_eq!(anon.mask_ice_password(passwords[0]), masked_passwords[0]);
61 assert_eq!(anon.mask_ice_password(passwords[1]), masked_passwords[1]);
62 assert_eq!(anon.mask_ice_password(passwords[2]), masked_passwords[2]);
63 }
64 }
65
66 #[test]
67 fn test_mask_ice_user() {
68 let mut anon = StatefulSdpAnonymizer::default();
69 let users = ["user1", "user2", "8109q2asdf"];
70 let masked_users = [
71 "ice-user-00000001",
72 "ice-user-00000002",
73 "ice-user-00000003",
74 ];
75 for _ in 0..2 {
76 assert_eq!(anon.mask_ice_user(users[0]), masked_users[0]);
77 assert_eq!(anon.mask_ice_user(users[1]), masked_users[1]);
78 assert_eq!(anon.mask_ice_user(users[2]), masked_users[2]);
79 }
80 }
81
82 #[test]
83 fn test_mask_cert_fingerprint() {
84 let mut anon = StatefulSdpAnonymizer::default();
85 let prints: [Vec<u8>; 3] = [
86 vec![
87 0x59u8, 0x4A, 0x8B, 0x73, 0xA7, 0x73, 0x53, 0x71, 0x88, 0xD7, 0x4D, 0x58, 0x28, 0x0C,
88 0x79, 0x72, 0x31, 0x29, 0x9B, 0x05, 0x37, 0xDD, 0x58, 0x43, 0xC2, 0xD4, 0x85, 0xA2,
89 0xB3, 0x66, 0x38, 0x7A,
90 ],
91 vec![
92 0x30u8, 0xFF, 0x8E, 0x2B, 0xAC, 0x9D, 0xED, 0x70, 0x18, 0x10, 0x67, 0xC8, 0xAE, 0x9E,
93 0x68, 0xF3, 0x86, 0x53, 0x51, 0xB0, 0xAC, 0x31, 0xB7, 0xBE, 0x6D, 0xCF, 0xA4, 0x2E,
94 0xD3, 0x6E, 0xB4, 0x28,
95 ],
96 vec![
97 0xDFu8, 0x2E, 0xAC, 0x8A, 0xFD, 0x0A, 0x8E, 0x99, 0xBF, 0x5D, 0xE8, 0x3C, 0xE7, 0xFA,
98 0xFB, 0x08, 0x3B, 0x3C, 0x54, 0x1D, 0xD7, 0xD4, 0x05, 0x77, 0xA0, 0x72, 0x9B, 0x14,
99 0x08, 0x6D, 0x0F, 0x4C,
100 ],
101 ];
102
103 let masked_prints = [1u64.to_byte_vec(), 2u64.to_byte_vec(), 3u64.to_byte_vec()];
104 for _ in 0..2 {
105 assert_eq!(anon.mask_cert_finger_print(&prints[0]), masked_prints[0]);
106 assert_eq!(anon.mask_cert_finger_print(&prints[1]), masked_prints[1]);
107 assert_eq!(anon.mask_cert_finger_print(&prints[2]), masked_prints[2]);
108 }
109 }
110
111 #[test]
112 fn test_mask_cname() {
113 let mut anon = StatefulSdpAnonymizer::default();
114 let cnames = ["mailto:foo@bar", "JohnDoe", "Jane Doe"];
115 let masked_cnames = ["cname-00000001", "cname-00000002", "cname-00000003"];
116 for _ in 0..2 {
117 assert_eq!(anon.mask_cname(cnames[0]), masked_cnames[0]);
118 assert_eq!(anon.mask_cname(cnames[1]), masked_cnames[1]);
119 assert_eq!(anon.mask_cname(cnames[2]), masked_cnames[2]);
120 }
121 }