Skip to content

Commit

Permalink
asymmetric: add tests for key restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
mathstuf committed Sep 27, 2020
1 parent 6dfa5e9 commit 34b88a8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/keytypes/asymmetric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,66 @@ impl KeyRestriction for AsymmetricRestriction {
impl RestrictableKeyType for Asymmetric {
type Restriction = AsymmetricRestriction;
}

#[cfg(test)]
mod tests {
use crate::keytypes::{AsymmetricRestriction, User};
use crate::tests::utils;
use crate::KeyRestriction;

#[test]
fn test_restriction_str() {
let mut keyring = utils::new_test_keyring();
let description = &b"description"[..];
let key = keyring
.add_key::<User, _, _>("test_restriction_str", description)
.unwrap();

let cases = [
(
AsymmetricRestriction::BuiltinTrusted,
"builtin_trusted".into(),
),
(
AsymmetricRestriction::BuiltinAndSecondaryTrusted,
"builtin_and_secondary_trusted".into(),
),
(
AsymmetricRestriction::Key {
key: key.clone(),
chained: false,
},
format!("key_or_keyring:{}", key.serial()),
),
(
AsymmetricRestriction::Key {
key: key.clone(),
chained: true,
},
format!("key_or_keyring:{}:chain", key.serial()),
),
(
AsymmetricRestriction::Keyring {
keyring: keyring.clone(),
chained: false,
},
format!("key_or_keyring:{}", keyring.serial()),
),
(
AsymmetricRestriction::Keyring {
keyring: keyring.clone(),
chained: true,
},
format!("key_or_keyring:{}:chain", key.serial()),
),
(
AsymmetricRestriction::Chained,
"key_or_keyring:0:chain".into(),
),
];

for (restriction, expected) in cases.iter() {
assert_eq!(restriction.restriction(), expected.as_ref());
}
}
}
1 change: 1 addition & 0 deletions src/keytypes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use std::fmt;

pub mod asymmetric;
pub use self::asymmetric::Asymmetric;
pub use self::asymmetric::AsymmetricRestriction;

pub mod big_key;
pub use self::big_key::BigKey;
Expand Down

0 comments on commit 34b88a8

Please sign in to comment.