diff options
author | Justus Winter <justus@pep-project.org> | 2018-01-09 16:19:57 +0100 |
---|---|---|
committer | Justus Winter <justus@pep-project.org> | 2018-01-09 16:19:57 +0100 |
commit | 8c70dbd517e99ecc52b389616f32788b451ebf0e (patch) | |
tree | c491deed1aa7c7a91c019e696348063fb646bfcd /store/src/lib.rs | |
parent | 2de3f8b7da3ee35dd44596ab8b29625f0de00723 (diff) |
store: Fix conflict detection.
- Detect conflicts when no key is present in the database.
- Add comments.
Diffstat (limited to 'store/src/lib.rs')
-rw-r--r-- | store/src/lib.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/store/src/lib.rs b/store/src/lib.rs index 38893d68..85fe97b6 100644 --- a/store/src/lib.rs +++ b/store/src/lib.rs @@ -704,7 +704,11 @@ impl From<rusqlite::Error> for Error { #[cfg(test)] mod store_test { - use super::{core, Store, Error}; + use super::{core, Store, Error, TPK, Fingerprint}; + + macro_rules! bytes { + ( $x:expr ) => { include_bytes!(concat!("../../openpgp/tests/data/keys/", $x)) }; + } #[test] fn store_network_policy_mismatch() { @@ -722,5 +726,19 @@ mod store_test { let store = Store::open(&ctx2, "default"); assert_match!(Err(Error::CoreError(core::Error::NetworkPolicyViolation(_))) = store); } + + #[test] + fn add_then_import_wrong_key() { + let ctx = core::Context::configure("org.sequoia-pgp.tests") + .ephemeral() + .network_policy(core::NetworkPolicy::Offline) + .build().unwrap(); + let mut store = Store::open(&ctx, "default").unwrap(); + let tpk = TPK::from_bytes(bytes!("testy.pgp")).unwrap(); + let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb"); + let binding = store.add("Mister B.", &fp).unwrap(); + let r = binding.import(&tpk); + assert_match!(Err(Error::Conflict) = r); + } } |