1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
import os
import pytest
import subprocess
import ssl
import time
import trustme
import bmemcached
import test_simple_functions
ca = trustme.CA()
server_cert = ca.issue_cert(os.environ["MEMCACHED_HOST"] + u"")
@pytest.yield_fixture(scope="module", autouse=True)
def memcached_tls():
key = server_cert.private_key_pem
cert = server_cert.cert_chain_pems[0]
with cert.tempfile() as c, key.tempfile() as k:
p = subprocess.Popen(
[
"memcached",
"-p5001",
"-Z",
"-o",
"ssl_key={}".format(k),
"-o",
"ssl_chain_cert={}".format(c),
"-o",
"ssl_verify_mode=1",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
time.sleep(0.1)
if p.poll() is not None:
pytest.skip("Memcached server is not built with TLS support.")
yield p
p.kill()
p.wait()
class TLSMemcachedTests(test_simple_functions.MemcachedTests):
"""
Same tests as above, just make sure it works with TLS.
"""
def setUp(self):
ctx = ssl.create_default_context()
ca.configure_trust(ctx)
self.server = "{}:5001".format(os.environ["MEMCACHED_HOST"])
self.client = bmemcached.Client(self.server, tls_context=ctx)
self.reset()
|