Debian Codegraph @

tests/integration/sq_pki_lookup.rs

raw
1 use super::common::Sq;
2 use super::common::UserIDArg;
3
4 #[test]
5 fn userid_designators() {
6 // Check the different user ID designators.
7
8 let sq = Sq::new();
9
10 let good_self_signed_email = "[email protected]";
11 let good_self_signed_userid
12 = &format!("Alice <{}>", good_self_signed_email);
13
14 let other_email = "[email protected]";
15 let other_userid = &format!("Alice <{}>", other_email);
16
17 let bad_self_signed_email = "[email protected]";
18 let bad_self_signed_userid
19 = &format!("Alice <{}>", bad_self_signed_email);
20
21 let (cert, cert_path, _rev_path)
22 = sq.key_generate(&[], &[ good_self_signed_userid ]);
23 sq.key_import(cert_path);
24
25
26 // Link the good self-signed user ID.
27 sq.pki_link_add(&[], cert.key_handle(), &[ good_self_signed_userid ]);
28
29 // Link a non-self-signed user ID.
30 sq.pki_link_add(&[], cert.key_handle(),
31 &[ UserIDArg::AddUserID(other_userid) ]);
32
33 // --userid matches user IDs that are authenticated. It doesn't
34 // matter if they are self-signed.
35
36 // Self signed and authenticated.
37 assert!(sq.pki_lookup(
38 &[], UserIDArg::UserID(good_self_signed_userid)).is_ok());
39 // Not self signed, but authenticated.
40 assert!(sq.pki_lookup(
41 &[], UserIDArg::UserID(other_userid)).is_ok());
42 // Self signed, but not authenticated.
43 assert!(sq.pki_lookup(
44 &[], UserIDArg::UserID(bad_self_signed_userid)).is_err());
45
46 assert!(sq.pki_lookup(
47 &[], UserIDArg::UserID(good_self_signed_email)).is_err());
48 assert!(sq.pki_lookup(
49 &[], UserIDArg::UserID(other_email)).is_err());
50 assert!(sq.pki_lookup(
51 &[], UserIDArg::UserID(bad_self_signed_email)).is_err());
52
53 // --email matches user IDs that are authenticated. It doesn't
54 // matter if they are self-signed.
55
56 // Self signed and authenticated.
57 assert!(sq.pki_lookup(
58 &[], UserIDArg::Email(good_self_signed_email)).is_ok());
59 // Not self signed, but authenticated.
60 assert!(sq.pki_lookup(
61 &[], UserIDArg::Email(other_email)).is_ok());
62 // Self signed, but not authenticated.
63 assert!(sq.pki_lookup(
64 &[], UserIDArg::Email(bad_self_signed_email)).is_err());
65 }