mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
The user-visible change here is that it allows the FFI API to save keys in the database for a context. This is primarily intended for testing purposes as it allows you to get a key without having to generate it. Internally the most important change is to start using the SignedPublicKey and SignedPrivateKey types from rpgp instead of wrapping them into a single Key object. This allows APIs to be specific about which they want instead of having to do runtime checks like .is_public() or so. This means some of the functionality of the Key impl now needs to be a trait. A thid API change is to introduce the KeyPair struct, which binds together the email address, public and private key for a keypair. All these changes result in a bunch of cleanups, though more more should be done to completely replace the Key type with the SignedPublicKye/SignedPrivateKey + traits. But this change is large enough already. Testing-wise this adds two new keys which can be loaded from disk and and avoids a few more key-generating tests. The encrypt/decrypt tests are moved from the stress tests into the pgp tests and split up.
113 lines
3.7 KiB
Rust
113 lines
3.7 KiB
Rust
//! Stress some functions for testing; if used as a lib, this file is obsolete.
|
|
|
|
use deltachat::config;
|
|
use deltachat::context::*;
|
|
use deltachat::Event;
|
|
use tempfile::{tempdir, TempDir};
|
|
|
|
/* some data used for testing
|
|
******************************************************************************/
|
|
|
|
fn stress_functions(context: &Context) {
|
|
let res = context.get_config(config::Config::SysConfigKeys).unwrap();
|
|
|
|
assert!(!res.contains(" probably_never_a_key "));
|
|
assert!(res.contains(" addr "));
|
|
assert!(res.contains(" mail_server "));
|
|
assert!(res.contains(" mail_user "));
|
|
assert!(res.contains(" mail_pw "));
|
|
assert!(res.contains(" mail_port "));
|
|
assert!(res.contains(" send_server "));
|
|
assert!(res.contains(" send_user "));
|
|
assert!(res.contains(" send_pw "));
|
|
assert!(res.contains(" send_port "));
|
|
assert!(res.contains(" server_flags "));
|
|
assert!(res.contains(" imap_folder "));
|
|
assert!(res.contains(" displayname "));
|
|
assert!(res.contains(" selfstatus "));
|
|
assert!(res.contains(" selfavatar "));
|
|
assert!(res.contains(" e2ee_enabled "));
|
|
assert!(res.contains(" mdns_enabled "));
|
|
assert!(res.contains(" save_mime_headers "));
|
|
assert!(res.contains(" configured_addr "));
|
|
assert!(res.contains(" configured_mail_server "));
|
|
assert!(res.contains(" configured_mail_user "));
|
|
assert!(res.contains(" configured_mail_pw "));
|
|
assert!(res.contains(" configured_mail_port "));
|
|
assert!(res.contains(" configured_send_server "));
|
|
assert!(res.contains(" configured_send_user "));
|
|
assert!(res.contains(" configured_send_pw "));
|
|
assert!(res.contains(" configured_send_port "));
|
|
assert!(res.contains(" configured_server_flags "));
|
|
|
|
// Cant check, no configured context
|
|
// assert!(dc_is_configured(context) != 0, "Missing configured context");
|
|
|
|
// let setupcode = dc_create_setup_code(context);
|
|
// let setupcode_c = CString::yolo(setupcode.clone());
|
|
// let setupfile = dc_render_setup_file(context, &setupcode).unwrap();
|
|
// let setupfile_c = CString::yolo(setupfile);
|
|
// let mut headerline_2: *const libc::c_char = ptr::null();
|
|
// let payload = dc_decrypt_setup_file(context, setupcode_c.as_ptr(), setupfile_c.as_ptr());
|
|
|
|
// assert!(payload.is_null());
|
|
// assert!(!dc_split_armored_data(
|
|
// payload,
|
|
// &mut headerline_2,
|
|
// ptr::null_mut(),
|
|
// ptr::null_mut(),
|
|
// ptr::null_mut(),
|
|
// ));
|
|
// assert!(!headerline_2.is_null());
|
|
// assert_eq!(
|
|
// strcmp(
|
|
// headerline_2,
|
|
// b"-----BEGIN PGP PRIVATE KEY BLOCK-----\x00" as *const u8 as *const libc::c_char,
|
|
// ),
|
|
// 0
|
|
// );
|
|
// free(payload as *mut libc::c_void);
|
|
|
|
// Cant check, no configured context
|
|
// assert!(dc_is_configured(context) != 0, "missing configured context");
|
|
|
|
// let qr = dc_get_securejoin_qr(context, 0);
|
|
// assert!(!qr.is_null(), "Invalid qr code generated");
|
|
// let qr_r = as_str(qr);
|
|
|
|
// assert!(qr_r.len() > 55);
|
|
// assert!(qr_r.starts_with("OPENPGP4FPR:"));
|
|
|
|
// let res = dc_check_qr(context, qr);
|
|
// let s = res.get_state();
|
|
|
|
// assert!(
|
|
// s == QrState::AskVerifyContact
|
|
// || s == QrState::FprMissmatch
|
|
// || s == QrState::FprWithoutAddr
|
|
// );
|
|
|
|
// free(qr.cast());
|
|
}
|
|
|
|
fn cb(_context: &Context, _event: Event) {}
|
|
|
|
#[allow(dead_code)]
|
|
struct TestContext {
|
|
ctx: Context,
|
|
dir: TempDir,
|
|
}
|
|
|
|
fn create_test_context() -> TestContext {
|
|
let dir = tempdir().unwrap();
|
|
let dbfile = dir.path().join("db.sqlite");
|
|
let ctx = Context::new(Box::new(cb), "FakeOs".into(), dbfile).unwrap();
|
|
TestContext { ctx, dir }
|
|
}
|
|
|
|
#[test]
|
|
fn test_stress_tests() {
|
|
let context = create_test_context();
|
|
stress_functions(&context.ctx);
|
|
}
|