mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 23:36:30 +03:00
Use pre-generated keys for python integration tests
This changes the AccountMaker to use pre-generated keys when available, speeding up test runs. As a side-effect we no longer need to compile the integration tests in release mode with debug symbols. Losing debug symbols (-g) means cargo no longer wants to recompile everything all the time too. Tested locally and seems to works.
This commit is contained in:
committed by
Alexander Krotov
parent
0864e640ed
commit
515c753d11
@@ -698,7 +698,7 @@ pub unsafe extern "C" fn dc_preconfigure_keypair(
|
|||||||
secret_data: *const libc::c_char,
|
secret_data: *const libc::c_char,
|
||||||
) -> i32 {
|
) -> i32 {
|
||||||
if context.is_null() {
|
if context.is_null() {
|
||||||
eprintln!("ignoring careless call to _dc_save_self_keypair()");
|
eprintln!("ignoring careless call to dc_preconfigure_keypair()");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
let ffi_context = &*context;
|
let ffi_context = &*context;
|
||||||
|
|||||||
@@ -11,18 +11,15 @@ import sys
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
target = os.environ.get("DCC_RS_TARGET")
|
target = os.environ.get("DCC_RS_TARGET")
|
||||||
if target is None:
|
if target is None:
|
||||||
os.environ["DCC_RS_TARGET"] = target = "release"
|
os.environ["DCC_RS_TARGET"] = target = "debug"
|
||||||
if "DCC_RS_DEV" not in os.environ:
|
if "DCC_RS_DEV" not in os.environ:
|
||||||
dn = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
dn = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
os.environ["DCC_RS_DEV"] = dn
|
os.environ["DCC_RS_DEV"] = dn
|
||||||
|
|
||||||
# build the core library in release + debug mode because
|
cmd = ["cargo", "build", "-p", "deltachat_ffi"]
|
||||||
# as of Nov 2019 rPGP generates RSA keys which take
|
if target == 'release':
|
||||||
# prohibitively long for non-release installs
|
cmd.append("--release")
|
||||||
os.environ["RUSTFLAGS"] = "-g"
|
subprocess.check_call(cmd)
|
||||||
subprocess.check_call([
|
|
||||||
"cargo", "build", "-p", "deltachat_ffi", "--" + target
|
|
||||||
])
|
|
||||||
subprocess.check_call("rm -rf build/ src/deltachat/*.so" , shell=True)
|
subprocess.check_call("rm -rf build/ src/deltachat/*.so" , shell=True)
|
||||||
|
|
||||||
if len(sys.argv) <= 1 or sys.argv[1] != "onlybuild":
|
if len(sys.argv) <= 1 or sys.argv[1] != "onlybuild":
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ class Account(object):
|
|||||||
return from_dc_charpointer(res)
|
return from_dc_charpointer(res)
|
||||||
|
|
||||||
def _preconfigure_keypair(self, addr, public, secret):
|
def _preconfigure_keypair(self, addr, public, secret):
|
||||||
"""See _dc_save_self_keypair() in deltachat.h.
|
"""See dc_preconfigure_keypair() in deltachat.h.
|
||||||
|
|
||||||
In other words, you don't need this.
|
In other words, you don't need this.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
@@ -116,8 +117,19 @@ def session_liveconfig(request):
|
|||||||
return SessionLiveConfigFromFile(liveconfig_opt)
|
return SessionLiveConfigFromFile(liveconfig_opt)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def datadir():
|
||||||
|
"""The py.path.local object of the test-data/ directory."""
|
||||||
|
for path in reversed(py.path.local(__file__).parts()):
|
||||||
|
datadir = path.join('test-data')
|
||||||
|
if datadir.isdir():
|
||||||
|
return datadir
|
||||||
|
else:
|
||||||
|
pytest.skip('test-data directory not found')
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def acfactory(pytestconfig, tmpdir, request, session_liveconfig):
|
def acfactory(pytestconfig, tmpdir, request, session_liveconfig, datadir):
|
||||||
|
|
||||||
class AccountMaker:
|
class AccountMaker:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -125,6 +137,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig):
|
|||||||
self.offline_count = 0
|
self.offline_count = 0
|
||||||
self._finalizers = []
|
self._finalizers = []
|
||||||
self.init_time = time.time()
|
self.init_time = time.time()
|
||||||
|
self._generated_keys = ["alice", "bob"]
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
while self._finalizers:
|
while self._finalizers:
|
||||||
@@ -144,12 +157,23 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig):
|
|||||||
ac._evlogger.set_timeout(2)
|
ac._evlogger.set_timeout(2)
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
|
def _preconfigure_key(self, account, addr):
|
||||||
|
# Only set a key if we haven't used it yet for another account.
|
||||||
|
if self._generated_keys:
|
||||||
|
keyname = self._generated_keys.pop(0)
|
||||||
|
fname_pub = "key/{name}-public.asc".format(name=keyname)
|
||||||
|
fname_sec = "key/{name}-secret.asc".format(name=keyname)
|
||||||
|
account._preconfigure_keypair(addr,
|
||||||
|
datadir.join(fname_pub).read(),
|
||||||
|
datadir.join(fname_sec).read())
|
||||||
|
|
||||||
def get_configured_offline_account(self):
|
def get_configured_offline_account(self):
|
||||||
ac = self.get_unconfigured_account()
|
ac = self.get_unconfigured_account()
|
||||||
|
|
||||||
# do a pseudo-configured account
|
# do a pseudo-configured account
|
||||||
addr = "addr{}@offline.org".format(self.offline_count)
|
addr = "addr{}@offline.org".format(self.offline_count)
|
||||||
ac.set_config("addr", addr)
|
ac.set_config("addr", addr)
|
||||||
|
self._preconfigure_key(ac, addr)
|
||||||
lib.dc_set_config(ac._dc_context, b"configured_addr", addr.encode("ascii"))
|
lib.dc_set_config(ac._dc_context, b"configured_addr", addr.encode("ascii"))
|
||||||
ac.set_config("mail_pw", "123")
|
ac.set_config("mail_pw", "123")
|
||||||
lib.dc_set_config(ac._dc_context, b"configured_mail_pw", b"123")
|
lib.dc_set_config(ac._dc_context, b"configured_mail_pw", b"123")
|
||||||
@@ -175,6 +199,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig):
|
|||||||
|
|
||||||
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
||||||
ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.live_count))
|
ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.live_count))
|
||||||
|
self._preconfigure_key(ac, configdict['addr'])
|
||||||
ac._evlogger.init_time = self.init_time
|
ac._evlogger.init_time = self.init_time
|
||||||
ac._evlogger.set_timeout(30)
|
ac._evlogger.set_timeout(30)
|
||||||
return ac, dict(configdict)
|
return ac, dict(configdict)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import py
|
|
||||||
import pytest
|
import pytest
|
||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
@@ -7,17 +6,9 @@ import time
|
|||||||
from deltachat import const, Account
|
from deltachat import const, Account
|
||||||
from deltachat.message import Message
|
from deltachat.message import Message
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from conftest import wait_configuration_progress, wait_successful_IMAP_SMTP_connection, wait_securejoin_inviter_progress
|
from conftest import (wait_configuration_progress,
|
||||||
|
wait_successful_IMAP_SMTP_connection,
|
||||||
|
wait_securejoin_inviter_progress)
|
||||||
@pytest.fixture
|
|
||||||
def datadir():
|
|
||||||
"""The py.path.local object of the test-data/ directory."""
|
|
||||||
for path in reversed(py.path.local(__file__).parts()):
|
|
||||||
datadir = path.join('test-data')
|
|
||||||
if datadir.isdir():
|
|
||||||
return datadir
|
|
||||||
pytest.skip('test-data directory not found')
|
|
||||||
|
|
||||||
|
|
||||||
class TestOfflineAccountBasic:
|
class TestOfflineAccountBasic:
|
||||||
@@ -38,8 +29,8 @@ class TestOfflineAccountBasic:
|
|||||||
def test_preconfigure_keypair(self, acfactory, datadir):
|
def test_preconfigure_keypair(self, acfactory, datadir):
|
||||||
ac = acfactory.get_unconfigured_account()
|
ac = acfactory.get_unconfigured_account()
|
||||||
ac._preconfigure_keypair("alice@example.com",
|
ac._preconfigure_keypair("alice@example.com",
|
||||||
datadir.join('key/alice-public.asc').read(),
|
datadir.join("key/alice-public.asc").read(),
|
||||||
datadir.join('key/alice-secret.asc').read())
|
datadir.join("key/alice-secret.asc").read())
|
||||||
|
|
||||||
def test_getinfo(self, acfactory):
|
def test_getinfo(self, acfactory):
|
||||||
ac1 = acfactory.get_unconfigured_account()
|
ac1 = acfactory.get_unconfigured_account()
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ impl Key {
|
|||||||
|
|
||||||
/// Use of a [KeyPair] for encryption or decryption.
|
/// Use of a [KeyPair] for encryption or decryption.
|
||||||
///
|
///
|
||||||
/// This is used by [save_self_keypair] to know what kind of key is
|
/// This is used by [store_self_keypair] to know what kind of key is
|
||||||
/// being saved.
|
/// being saved.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum KeyPairUse {
|
pub enum KeyPairUse {
|
||||||
|
|||||||
Reference in New Issue
Block a user