Adapt for new request_client_cert option in netlib.

This commit is contained in:
Aldo Cortesi 2013-05-13 09:03:48 +12:00
parent 3217fcad14
commit 5eeb52183a
2 changed files with 11 additions and 5 deletions

View File

@ -9,10 +9,11 @@ class PathodError(Exception): pass
class SSLOptions:
def __init__(self, certfile=None, keyfile=None, not_after_connect=None):
def __init__(self, certfile=None, keyfile=None, not_after_connect=None, request_client_cert=False):
self.keyfile = keyfile or utils.data.path("resources/server.key")
self.certfile = certfile or utils.data.path("resources/server.crt")
self.not_after_connect = not_after_connect
self.request_client_cert = request_client_cert
class PathodHandler(tcp.BaseHandler):
@ -76,7 +77,8 @@ class PathodHandler(tcp.BaseHandler):
self.convert_to_ssl(
self.server.ssloptions.certfile,
self.server.ssloptions.keyfile,
handle_sni = self.handle_sni
handle_sni = self.handle_sni,
request_client_cert = self.server.ssloptions.request_client_cert
)
except tcp.NetLibError, v:
s = str(v)
@ -181,7 +183,8 @@ class PathodHandler(tcp.BaseHandler):
self.convert_to_ssl(
self.server.ssloptions.certfile,
self.server.ssloptions.keyfile,
handle_sni = self.handle_sni
handle_sni = self.handle_sni,
request_client_cert = self.server.ssloptions.request_client_cert
)
except tcp.NetLibError, v:
s = str(v)
@ -222,7 +225,7 @@ class Pathod(tcp.TCPServer):
"""
addr: (address, port) tuple. If port is 0, a free port will be
automatically chosen.
ssloptions: a dictionary containing certfile and keyfile specifications.
ssloptions: an SSLOptions object.
craftanchor: string specifying the path under which to anchor response generation.
staticdir: path to a directory of static resources, or None.
anchors: A list of (regex, spec) tuples, or None.

View File

@ -1,5 +1,5 @@
import json, cStringIO
from libpathod import pathoc, test, version
from libpathod import pathoc, test, version, pathod
import tutils
def test_response():
@ -8,10 +8,12 @@ def test_response():
class _TestDaemon:
ssloptions = pathod.SSLOptions()
@classmethod
def setUpAll(self):
self.d = test.Daemon(
ssl=self.ssl,
ssloptions=self.ssloptions,
staticdir=tutils.test_data.path("data"),
anchors=[("/anchor/.*", "202")]
)
@ -36,6 +38,7 @@ class _TestDaemon:
class TestDaemonSSL(_TestDaemon):
ssl = True
ssloptions = pathod.SSLOptions(request_client_cert=True)
def test_sni(self):
c = pathoc.Pathoc(
"127.0.0.1",