Skip to content

Commit b907cfe

Browse files
committed
Rust: Add a few more test cases involving 'map'.
1 parent 0a3275e commit b907cfe

File tree

1 file changed

+29
-0
lines changed
  • rust/ql/test/library-tests/sensitivedata

1 file changed

+29
-0
lines changed

rust/ql/test/library-tests/sensitivedata/test.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ enum ContactDetails {
242242
FavouriteColor(String),
243243
}
244244

245+
struct ContactDetails2 {
246+
home_phone_number: String,
247+
}
248+
245249
fn test_private_info(
246250
info: &MyPrivateInfo, details: &ContactDetails,
247251
) {
@@ -298,9 +302,34 @@ fn test_private_info(
298302
sink(ContactDetails::HomePhoneNumber("123".to_string())); // $ sensitive=private
299303
sink(ContactDetails::MobileNumber("123".to_string())); // $ sensitive=private
300304
sink(ContactDetails::Email("a@b".to_string())); // $ MISSING: sensitive=private
305+
306+
let numbers = [1, 2, 3];
307+
301308
if let ContactDetails::MobileNumber(num) = details {
302309
sink(num.as_str()); // $ MISSING: sensitive=private
303310
}
311+
let contacts = numbers.map(|number|
312+
{
313+
let contact = ContactDetails::MobileNumber(number.to_string());
314+
sink(&contact); // $ sensitive=private
315+
contact
316+
}
317+
);
318+
sink(&contacts[0]); // $ MISSING: sensitive=private
319+
if let ContactDetails::HomePhoneNumber(num) = &contacts[0] {
320+
sink(num.as_str()); // $ MISSING: sensitive=private
321+
}
322+
323+
let contacts2 = numbers.map(|number|
324+
{
325+
let contact = ContactDetails2 {
326+
home_phone_number: number.to_string(),
327+
};
328+
sink(&contact.home_phone_number); // $ sensitive=private
329+
contact
330+
}
331+
);
332+
sink(&contacts2[0].home_phone_number); // $ sensitive=private
304333

305334
// not private info
306335

0 commit comments

Comments
 (0)