| 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 |
let fpr = &cert.fingerprint().to_string(); |
| 24 |
sq.key_import(cert_path); |
| 25 |
|
| 26 |
|
| 27 |
// Link the good self-signed user ID. |
| 28 |
sq.pki_link_add(&[], cert.key_handle(), &[ good_self_signed_userid ]); |
| 29 |
|
| 30 |
// Link a non-self-signed user ID. |
| 31 |
sq.pki_link_add(&[], cert.key_handle(), |
| 32 |
&[ UserIDArg::AddUserID(other_userid) ]); |
| 33 |
|
| 34 |
// --userid matches user IDs that are authenticated. It doesn't |
| 35 |
// matter if they are self-signed. |
| 36 |
|
| 37 |
// Self signed and authenticated. |
| 38 |
assert!(sq.pki_authenticate( |
| 39 |
&[], &fpr, UserIDArg::UserID(good_self_signed_userid)).is_ok()); |
| 40 |
// Not self signed, but authenticated. |
| 41 |
assert!(sq.pki_authenticate( |
| 42 |
&[], &fpr, UserIDArg::UserID(other_userid)).is_ok()); |
| 43 |
// Self signed, but not authenticated. |
| 44 |
assert!(sq.pki_authenticate( |
| 45 |
&[], &fpr, UserIDArg::UserID(bad_self_signed_userid)).is_err()); |
| 46 |
|
| 47 |
assert!(sq.pki_authenticate( |
| 48 |
&[], &fpr, UserIDArg::UserID(good_self_signed_email)).is_err()); |
| 49 |
assert!(sq.pki_authenticate( |
| 50 |
&[], &fpr, UserIDArg::UserID(other_email)).is_err()); |
| 51 |
assert!(sq.pki_authenticate( |
| 52 |
&[], &fpr, UserIDArg::UserID(bad_self_signed_email)).is_err()); |
| 53 |
|
| 54 |
// --email matches user IDs that are authenticated. It doesn't |
| 55 |
// matter if they are self-signed. |
| 56 |
|
| 57 |
// Self signed and authenticated. |
| 58 |
assert!(sq.pki_authenticate( |
| 59 |
&[], &fpr, UserIDArg::Email(good_self_signed_email)).is_ok()); |
| 60 |
// Not self signed, but authenticated. |
| 61 |
assert!(sq.pki_authenticate( |
| 62 |
&[], &fpr, UserIDArg::Email(other_email)).is_ok()); |
| 63 |
// Self signed, but not authenticated. |
| 64 |
assert!(sq.pki_authenticate( |
| 65 |
&[], &fpr, UserIDArg::Email(bad_self_signed_email)).is_err()); |
| 66 |
} |