Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3374335
D12886.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D12886.diff
View Options
diff --git a/services/identity/src/device_list.rs b/services/identity/src/device_list.rs
--- a/services/identity/src/device_list.rs
+++ b/services/identity/src/device_list.rs
@@ -326,6 +326,12 @@
== 1
}
+ /// Verifies if the device list contains duplicated device IDs
+ fn has_duplicates(device_list: &[&str]) -> bool {
+ let devices_set: HashSet<&str> = device_list.iter().copied().collect();
+ devices_set.len() != device_list.len()
+ }
+
// This is going to be used when doing primary devicd keys rotation
#[allow(unused)]
pub fn primary_device_rotation_validator(
@@ -347,6 +353,10 @@
return false;
}
+ if has_duplicates(new_device_list) {
+ return false;
+ }
+
// allow replacing a keyserver
if is_device_replaced(previous_device_list, new_device_list) {
return true;
@@ -407,6 +417,17 @@
assert!(is_device_replaced(&list3, &list3).not(), "Unchanged");
assert!(is_device_replaced(&list3, &list4).not(), "Reorder");
}
+
+ #[test]
+ fn test_duplicated_devices() {
+ use std::ops::Not;
+
+ let list1 = vec!["device1", "device2", "device3"];
+ let list2 = vec!["device1", "device2", "device2"];
+
+ assert!(has_duplicates(&list1).not(), "No duplicates");
+ assert!(has_duplicates(&list2), "With duplicates");
+ }
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 3:06 PM (20 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2590762
Default Alt Text
D12886.diff (1 KB)
Attached To
Mode
D12886: [identity] Forbid duplicated devices in device lists
Attached
Detach File
Event Timeline
Log In to Comment