Skip to content

Commit

Permalink
test: add SSL test
Browse files Browse the repository at this point in the history
This adds a simple SSL test along with the framework for running
the test Zookeeper in a mode where it listens on both SSL and
non-SSL ports.
  • Loading branch information
James E. Blair committed Jun 26, 2020
1 parent 13c73ec commit f76e2d7
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 12 deletions.
6 changes: 4 additions & 2 deletions kazoo/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from kazoo.testing.harness import KazooTestCase, KazooTestHarness

from kazoo.testing.harness import (
KazooTestCase,
KazooTestHarness
)

__all__ = ('KazooTestHarness', 'KazooTestCase', )
39 changes: 37 additions & 2 deletions kazoo/testing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import tempfile
import traceback

from kazoo.testing import sslfixtures


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -63,7 +65,8 @@ def to_java_compatible_path(path):

ServerInfo = namedtuple(
"ServerInfo",
"server_id client_port election_port leader_port admin_port peer_type")
"server_id client_port secure_client_port "
"election_port leader_port admin_port peer_type")


class ManagedZooKeeper(object):
Expand Down Expand Up @@ -105,6 +108,8 @@ def run(self):
log_path = os.path.join(self.working_path, "log")
log4j_path = os.path.join(self.working_path, "log4j.properties")
data_path = os.path.join(self.working_path, "data")
truststore_path = os.path.join(self.working_path, "cacert.pem")
keystore_path = os.path.join(self.working_path, "keystore.pem")

# various setup steps
if not os.path.exists(self.working_path):
Expand All @@ -114,18 +119,31 @@ def run(self):
if not os.path.exists(data_path):
os.mkdir(data_path)

with open(truststore_path, "w") as truststore:
truststore.write(sslfixtures.ca_cert)
with open(keystore_path, "w") as keystore:
keystore.write(sslfixtures.server_cert)
keystore.write(sslfixtures.server_key)

with open(config_path, "w") as config:
config.write("""
tickTime=2000
dataDir=%s
clientPort=%s
secureClientPort=%s
maxClientCnxns=0
admin.serverPort=%s
serverCnxnFactory=org.apache.zookeeper.server.NettyServerCnxnFactory
authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
ssl.keyStore.location=%s
ssl.trustStore.location=%s
%s
""" % (to_java_compatible_path(data_path),
self.server_info.client_port,
self.server_info.secure_client_port,
self.server_info.admin_port,
keystore_path,
truststore_path,
"\n".join(self.configuration_entries))) # NOQA

# setup a replicated setup if peers are specified
Expand Down Expand Up @@ -202,6 +220,9 @@ def classpath(self):
# Check for a release - top-level zookeeper-*.jar?
jars = glob((os.path.join(
self.install_path, 'zookeeper-*.jar')))
# Later releases put zookeeper.jar in lib/
libjars = glob((os.path.join(
self.install_path, 'lib', 'zookeeper-*.jar')))
if jars:
# Release build (`ant package`)
jars.extend(glob(os.path.join(
Expand All @@ -217,6 +238,11 @@ def classpath(self):
jars.extend(glob(os.path.join(
self.install_path,
"slf4j-log4j*.jar")))
elif libjars:
# Release build (`ant package`)
jars.extend(glob(os.path.join(
self.install_path,
"lib/*.jar")))
else:
# Development build (plain `ant`)
jars = glob((os.path.join(
Expand All @@ -232,6 +258,11 @@ def address(self):
"""Get the address of the ZooKeeper instance."""
return "%s:%s" % (self.host, self.client_port)

@property
def secure_address(self):
"""Get the address of the SSL ZooKeeper instance."""
return "%s:%s" % (self.host, self.secure_client_port)

@property
def running(self):
return self._running
Expand All @@ -240,6 +271,10 @@ def running(self):
def client_port(self):
return self.server_info.client_port

@property
def secure_client_port(self):
return self.server_info.secure_client_port

def reset(self):
"""Stop the zookeeper instance, cleaning out its on disk-data."""
self.stop()
Expand Down Expand Up @@ -291,7 +326,7 @@ def __init__(self, install_path=None, classpath=None,
else:
peer_type = 'participant'
info = ServerInfo(server_id, port, port + 1, port + 2, port + 3,
peer_type)
port + 4, peer_type)
peers.append(info)
port += 10

Expand Down
14 changes: 13 additions & 1 deletion kazoo/testing/harness.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Kazoo testing harnesses"""
import logging
import os
import tempfile
import uuid
import unittest

import pytest

from kazoo import python2atexit as atexit
from kazoo.client import KazooClient
from kazoo.exceptions import KazooException
Expand All @@ -12,6 +15,8 @@
KazooState
)
from kazoo.testing.common import ZookeeperCluster
from kazoo.testing import sslfixtures
from kazoo.tests.util import TRAVIS_ZK_VERSION

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -158,6 +163,10 @@ def cluster(self):
def servers(self):
return ",".join([s.address for s in self.cluster])

@property
def secure_servers(self):
return ",".join([s.secure_address for s in self.cluster])

def _get_nonchroot_client(self):
c = KazooClient(self.servers)
self._clients.append(c)
Expand Down Expand Up @@ -193,7 +202,10 @@ def setup_zookeeper(self, **client_options):
if do_start:
self.cluster.start()
namespace = "/kazootests" + uuid.uuid4().hex
self.hosts = self.servers + namespace
if client_options.get('use_ssl'):
self.hosts = self.secure_servers + namespace
else:
self.hosts = self.servers + namespace
if 'timeout' not in client_options:
client_options['timeout'] = self.DEFAULT_CLIENT_TIMEOUT
self.client = self._get_client(**client_options)
Expand Down
138 changes: 138 additions & 0 deletions kazoo/testing/sslfixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
ca_cert = """
-----BEGIN CERTIFICATE-----
MIIDkTCCAnmgAwIBAgIUG8baUt2UBIoO569cnAU8xPP6l2UwDQYJKoZIhvcNAQEL
BQAwWDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFTATBgNVBAoM
DENvbXBhbnkgTmFtZTEMMAoGA1UECwwDT3JnMQ8wDQYDVQQDDAZjYXJvb3QwHhcN
MjAwNjE2MjI0NjA4WhcNMzAwMzE2MjI0NjA4WjBYMQswCQYDVQQGEwJVUzETMBEG
A1UECAwKQ2FsaWZvcm5pYTEVMBMGA1UECgwMQ29tcGFueSBOYW1lMQwwCgYDVQQL
DANPcmcxDzANBgNVBAMMBmNhcm9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
AQoCggEBAOt8elMFE46KAP+YzLuFaRoYIeeWtTEi5WUZBtwRCDTcquW/tiQX7Kfj
bjcEEjbtuTY1386qIWOC9muQfbt/uFdAi6AN+o1Ta4/IC2olG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mFJYvHEVZxWC71YiN
BxIA1kfkf8rjmtbpayFMzyvv38oWBQbFRgTIP55nzVtiOAOvlt0fAn9lkQKBgBtA
YwTPwdYdLExfMrSxeRtd1jRXUplUfWPQAYhV/MFIDMFKFYOo/CyhAb3dcF6Jb/NL
VQofVOhZMojfThVVnGu+t6E8G9xL1cdsc8GtHGnr48acEoZaAWQXK6S/WGEvD54u
BQ7BqFiFtIGdpfmukkEF4nBe6iMoNpHXKZickqYlAoGBALpCmyjQCkT1viIIXR3a
H55RR6pgCBqSguscSJFgR9PC7SPTQQI+qayv5LsMZ+vjBLgf7ykq4LS0PKIYLhtT
HAAfk0QZ6J/MD1rqT8kJ54qxHaq35hp1l4kFozx+PU3NiYrpylu20886TXj9P7qH
TKEjqmurkUcofeaRqrUmU+aK
-----END PRIVATE KEY-----
"""
33 changes: 31 additions & 2 deletions kazoo/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import socket
import sys
import tempfile
import threading
import time
import uuid
Expand All @@ -9,7 +11,7 @@
from mock import patch
import pytest

from kazoo.testing import KazooTestCase
from kazoo.testing import KazooTestCase, sslfixtures
from kazoo.exceptions import (
AuthFailedError,
BadArgumentsError,
Expand All @@ -26,7 +28,7 @@
)
from kazoo.protocol.connection import _CONNECTION_DROP
from kazoo.protocol.states import KeeperState, KazooState
from kazoo.tests.util import TRAVIS_ZK_VERSION
from kazoo.tests.util import TRAVIS_ZK_VERSION, ZK_VERSION


if sys.version_info > (3, ): # pragma: nocover
Expand Down Expand Up @@ -1157,6 +1159,33 @@ def test_request_queuing_session_expired(self):
client.stop()


class TestSSLClient(KazooTestCase):
def setUp(self):
ssl_path = tempfile.mkdtemp()
key_path = os.path.join(ssl_path, 'key.pem')
cert_path = os.path.join(ssl_path, 'cert.pem')
cacert_path = os.path.join(ssl_path, 'cacert.pem')
with open(key_path, 'w') as key_file:
key_file.write(sslfixtures.client_key)
with open(cert_path, 'w') as cert_file:
cert_file.write(sslfixtures.client_cert)
with open(cacert_path, 'w') as cacert_file:
cacert_file.write(sslfixtures.ca_cert)
if ZK_VERSION and ZK_VERSION < (3, 5):
pytest.skip("Must use Zookeeper 3.5 or above")
self.setup_zookeeper(
use_ssl=True,
keyfile=key_path,
certfile=cert_path,
ca=cacert_path)

def test_create(self):
client = self.client
path = client.create("/1")
assert path == "/1"
assert client.exists("/1")


dummy_dict = {
'aversion': 1,
'ctime': 0,
Expand Down
11 changes: 6 additions & 5 deletions kazoo/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
import time

TRAVIS = os.environ.get('TRAVIS', False)
TRAVIS_ZK_VERSION = TRAVIS and os.environ.get('ZOOKEEPER_VERSION', None)
if TRAVIS_ZK_VERSION:
if '-' in TRAVIS_ZK_VERSION:
ZK_VERSION = os.environ.get('ZOOKEEPER_VERSION', None)
if ZK_VERSION:
if '-' in ZK_VERSION:
# Ignore pre-release markers like -alpha
TRAVIS_ZK_VERSION = TRAVIS_ZK_VERSION.split('-')[0]
TRAVIS_ZK_VERSION = tuple([int(n) for n in TRAVIS_ZK_VERSION.split('.')])
ZK_VERSION = ZK_VERSION.split('-')[0]
ZK_VERSION = tuple([int(n) for n in ZK_VERSION.split('.')])
TRAVIS_ZK_VERSION = TRAVIS and ZK_VERSION or None


class Handler(logging.Handler):
Expand Down

0 comments on commit f76e2d7

Please sign in to comment.