Skip to content

Commit a5d0765

Browse files
committed
Finish GC code for SSLSession and increase test coverage
1 parent 22ecc4b commit a5d0765

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

Lib/test/test_ssl.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,13 +1474,15 @@ def test_connect(self):
14741474
cert_reqs=ssl.CERT_NONE) as s:
14751475
s.connect(self.server_addr)
14761476
self.assertEqual({}, s.getpeercert())
1477+
self.assertFalse(s.server_side)
14771478

14781479
# this should succeed because we specify the root cert
14791480
with test_wrap_socket(socket.socket(socket.AF_INET),
14801481
cert_reqs=ssl.CERT_REQUIRED,
14811482
ca_certs=SIGNING_CA) as s:
14821483
s.connect(self.server_addr)
14831484
self.assertTrue(s.getpeercert())
1485+
self.assertFalse(s.server_side)
14841486

14851487
def test_connect_fail(self):
14861488
# This should fail because we have no verification certs. Connection
@@ -3028,6 +3030,7 @@ def test_server_accept(self):
30283030
host = "127.0.0.1"
30293031
port = support.bind_port(server)
30303032
server = context.wrap_socket(server, server_side=True)
3033+
self.assertTrue(server.server_side)
30313034

30323035
evt = threading.Event()
30333036
remote = None

Modules/_ssl.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne)
149149
}
150150

151151
#ifndef OPENSSL_NO_COMP
152+
/* LCOV_EXCL_START */
152153
static int COMP_get_type(const COMP_METHOD *meth)
153154
{
154155
return meth->type;
155156
}
157+
/* LCOV_EXCL_END */
156158
#endif
157159

158160
static pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx)
@@ -2408,8 +2410,7 @@ PySSL_get_session(PySSLSocket *self, void *closure) {
24082410
Py_RETURN_NONE;
24092411
}
24102412
#endif
2411-
2412-
pysess = PyObject_New(PySSLSession, &PySSLSession_Type);
2413+
pysess = PyObject_GC_New(PySSLSession, &PySSLSession_Type);
24132414
if (pysess == NULL) {
24142415
SSL_SESSION_free(session);
24152416
return NULL;
@@ -2419,6 +2420,7 @@ PySSL_get_session(PySSLSocket *self, void *closure) {
24192420
pysess->ctx = self->ctx;
24202421
Py_INCREF(pysess->ctx);
24212422
pysess->session = session;
2423+
PyObject_GC_Track(pysess);
24222424
return (PyObject *)pysess;
24232425
}
24242426

@@ -4289,11 +4291,12 @@ static PyTypeObject PySSLMemoryBIO_Type = {
42894291
static void
42904292
PySSLSession_dealloc(PySSLSession *self)
42914293
{
4294+
PyObject_GC_UnTrack(self);
42924295
Py_XDECREF(self->ctx);
42934296
if (self->session != NULL) {
42944297
SSL_SESSION_free(self->session);
42954298
}
4296-
PyObject_Del(self);
4299+
PyObject_GC_Del(self);
42974300
}
42984301

42994302
static PyObject *
@@ -4455,7 +4458,7 @@ static PyTypeObject PySSLSession_Type = {
44554458
0, /*tp_getattro*/
44564459
0, /*tp_setattro*/
44574460
0, /*tp_as_buffer*/
4458-
Py_TPFLAGS_DEFAULT, /*tp_flags*/
4461+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
44594462
0, /*tp_doc*/
44604463
(traverseproc)PySSLSession_traverse, /*tp_traverse*/
44614464
(inquiry)PySSLSession_clear, /*tp_clear*/
@@ -4590,6 +4593,7 @@ _ssl_RAND_status_impl(PyObject *module)
45904593
}
45914594

45924595
#ifndef OPENSSL_NO_EGD
4596+
/* LCOV_EXCL_START */
45934597
/*[clinic input]
45944598
_ssl.RAND_egd
45954599
path: object(converter="PyUnicode_FSConverter")
@@ -4615,6 +4619,7 @@ _ssl_RAND_egd_impl(PyObject *module, PyObject *path)
46154619
}
46164620
return PyLong_FromLong(bytes);
46174621
}
4622+
/* LCOV_EXCL_STOP */
46184623
#endif /* OPENSSL_NO_EGD */
46194624

46204625

0 commit comments

Comments
 (0)