Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZEO
Commits
9b421915
Commit
9b421915
authored
Jul 07, 2016
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mock asyncio in mockiavellian tests
parent
c0b96879
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
16 deletions
+28
-16
src/ZEO/tests/testConfig.py
src/ZEO/tests/testConfig.py
+3
-1
src/ZEO/tests/testssl.py
src/ZEO/tests/testssl.py
+25
-15
No files found.
src/ZEO/tests/testConfig.py
View file @
9b421915
...
@@ -20,7 +20,7 @@ from ZODB.config import storageFromString
...
@@ -20,7 +20,7 @@ from ZODB.config import storageFromString
from
.forker
import
start_zeo_server
from
.forker
import
start_zeo_server
class
ZEOConfigTest
(
setupstack
.
TestCase
):
class
ZEOConfigTest
Base
(
setupstack
.
TestCase
):
setUp
=
setupstack
.
setUpDirectory
setUp
=
setupstack
.
setUpDirectory
...
@@ -86,6 +86,8 @@ class ZEOConfigTest(setupstack.TestCase):
...
@@ -86,6 +86,8 @@ class ZEOConfigTest(setupstack.TestCase):
self
.
assertEqual
(
client
.
__name__
,
self
.
assertEqual
(
client
.
__name__
,
name
if
name
is
not
None
else
str
(
client
.
_addr
))
name
if
name
is
not
None
else
str
(
client
.
_addr
))
class
ZEOConfigTest
(
ZEOConfigTestBase
):
def
test_default_zeo_config
(
self
,
**
client_settings
):
def
test_default_zeo_config
(
self
,
**
client_settings
):
addr
,
stop
=
self
.
start_server
()
addr
,
stop
=
self
.
start_server
()
...
...
src/ZEO/tests/testssl.py
View file @
9b421915
from
.._compat
import
PY3
import
mock
import
mock
import
os
import
os
import
ssl
import
ssl
...
@@ -7,7 +9,7 @@ from ZODB.config import storageFromString
...
@@ -7,7 +9,7 @@ from ZODB.config import storageFromString
from
..Exceptions
import
ClientDisconnected
from
..Exceptions
import
ClientDisconnected
from
..
import
runzeo
from
..
import
runzeo
from
.testConfig
import
ZEOConfigTest
from
.testConfig
import
ZEOConfigTest
Base
here
=
os
.
path
.
dirname
(
__file__
)
here
=
os
.
path
.
dirname
(
__file__
)
server_cert
=
os
.
path
.
join
(
here
,
'server.pem'
)
server_cert
=
os
.
path
.
join
(
here
,
'server.pem'
)
...
@@ -17,7 +19,7 @@ serverpw_key = os.path.join(here, 'serverpw_key.pem')
...
@@ -17,7 +19,7 @@ serverpw_key = os.path.join(here, 'serverpw_key.pem')
client_cert
=
os
.
path
.
join
(
here
,
'client.pem'
)
client_cert
=
os
.
path
.
join
(
here
,
'client.pem'
)
client_key
=
os
.
path
.
join
(
here
,
'client_key.pem'
)
client_key
=
os
.
path
.
join
(
here
,
'client_key.pem'
)
class
SSLConfigTest
(
ZEOConfigTest
):
class
SSLConfigTest
(
ZEOConfigTest
Base
):
def
test_ssl_basic
(
self
):
def
test_ssl_basic
(
self
):
# This shows that configuring ssl has an actual effect on connections.
# This shows that configuring ssl has an actual effect on connections.
...
@@ -112,8 +114,13 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -112,8 +114,13 @@ class SSLConfigTest(ZEOConfigTest):
)
)
stop
()
stop
()
@
mock
.
patch
((
'asyncio'
if
PY3
else
'trollius'
)
+
'.async'
)
@
mock
.
patch
((
'asyncio'
if
PY3
else
'trollius'
)
+
'.set_event_loop'
)
@
mock
.
patch
((
'asyncio'
if
PY3
else
'trollius'
)
+
'.new_event_loop'
)
class
SSLConfigTestMockiavellian
(
ZEOConfigTestBase
):
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
def
test_ssl_mockiavellian_server_no_ssl
(
self
,
factory
):
def
test_ssl_mockiavellian_server_no_ssl
(
self
,
factory
,
*
_
):
server
=
create_server
()
server
=
create_server
()
self
.
assertFalse
(
factory
.
called
)
self
.
assertFalse
(
factory
.
called
)
self
.
assertEqual
(
server
.
acceptor
.
ssl_context
,
None
)
self
.
assertEqual
(
server
.
acceptor
.
ssl_context
,
None
)
...
@@ -134,13 +141,13 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -134,13 +141,13 @@ class SSLConfigTest(ZEOConfigTest):
self
.
assertEqual
(
context
.
check_hostname
,
check_hostname
)
self
.
assertEqual
(
context
.
check_hostname
,
check_hostname
)
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
def
test_ssl_mockiavellian_server_ssl_no_auth
(
self
,
factory
):
def
test_ssl_mockiavellian_server_ssl_no_auth
(
self
,
factory
,
*
_
):
with
self
.
assertRaises
(
SystemExit
):
with
self
.
assertRaises
(
SystemExit
):
# auth is required
# auth is required
create_server
(
certificate
=
server_cert
,
key
=
server_key
)
create_server
(
certificate
=
server_cert
,
key
=
server_key
)
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
def
test_ssl_mockiavellian_server_ssl_auth_file
(
self
,
factory
):
def
test_ssl_mockiavellian_server_ssl_auth_file
(
self
,
factory
,
*
_
):
server
=
create_server
(
server
=
create_server
(
certificate
=
server_cert
,
key
=
server_key
,
authenticate
=
__file__
)
certificate
=
server_cert
,
key
=
server_key
,
authenticate
=
__file__
)
context
=
server
.
acceptor
.
ssl_context
context
=
server
.
acceptor
.
ssl_context
...
@@ -148,7 +155,7 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -148,7 +155,7 @@ class SSLConfigTest(ZEOConfigTest):
server
.
close
()
server
.
close
()
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
def
test_ssl_mockiavellian_server_ssl_auth_dir
(
self
,
factory
):
def
test_ssl_mockiavellian_server_ssl_auth_dir
(
self
,
factory
,
*
_
):
server
=
create_server
(
server
=
create_server
(
certificate
=
server_cert
,
key
=
server_key
,
authenticate
=
here
)
certificate
=
server_cert
,
key
=
server_key
,
authenticate
=
here
)
context
=
server
.
acceptor
.
ssl_context
context
=
server
.
acceptor
.
ssl_context
...
@@ -156,7 +163,7 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -156,7 +163,7 @@ class SSLConfigTest(ZEOConfigTest):
server
.
close
()
server
.
close
()
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
def
test_ssl_mockiavellian_server_ssl_pw
(
self
,
factory
):
def
test_ssl_mockiavellian_server_ssl_pw
(
self
,
factory
,
*
_
):
server
=
create_server
(
server
=
create_server
(
certificate
=
server_cert
,
certificate
=
server_cert
,
key
=
server_key
,
key
=
server_key
,
...
@@ -170,7 +177,7 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -170,7 +177,7 @@ class SSLConfigTest(ZEOConfigTest):
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
def
test_ssl_mockiavellian_client_no_ssl
(
self
,
ClientStorage
,
factory
):
def
test_ssl_mockiavellian_client_no_ssl
(
self
,
ClientStorage
,
factory
,
*
_
):
client
=
ssl_client
()
client
=
ssl_client
()
self
.
assertFalse
(
'ssl'
in
ClientStorage
.
call_args
[
1
])
self
.
assertFalse
(
'ssl'
in
ClientStorage
.
call_args
[
1
])
self
.
assertFalse
(
'ssl_server_hostname'
in
ClientStorage
.
call_args
[
1
])
self
.
assertFalse
(
'ssl_server_hostname'
in
ClientStorage
.
call_args
[
1
])
...
@@ -178,7 +185,7 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -178,7 +185,7 @@ class SSLConfigTest(ZEOConfigTest):
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
def
test_ssl_mockiavellian_client_server_signed
(
def
test_ssl_mockiavellian_client_server_signed
(
self
,
ClientStorage
,
factory
self
,
ClientStorage
,
factory
,
*
_
):
):
client
=
ssl_client
(
certificate
=
client_cert
,
key
=
client_key
)
client
=
ssl_client
(
certificate
=
client_cert
,
key
=
client_key
)
context
=
ClientStorage
.
call_args
[
1
][
'ssl'
]
context
=
ClientStorage
.
call_args
[
1
][
'ssl'
]
...
@@ -191,7 +198,7 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -191,7 +198,7 @@ class SSLConfigTest(ZEOConfigTest):
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
def
test_ssl_mockiavellian_client_auth_dir
(
def
test_ssl_mockiavellian_client_auth_dir
(
self
,
ClientStorage
,
factory
self
,
ClientStorage
,
factory
,
*
_
):
):
client
=
ssl_client
(
client
=
ssl_client
(
certificate
=
client_cert
,
key
=
client_key
,
authenticate
=
here
)
certificate
=
client_cert
,
key
=
client_key
,
authenticate
=
here
)
...
@@ -207,7 +214,7 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -207,7 +214,7 @@ class SSLConfigTest(ZEOConfigTest):
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
def
test_ssl_mockiavellian_client_auth_file
(
def
test_ssl_mockiavellian_client_auth_file
(
self
,
ClientStorage
,
factory
self
,
ClientStorage
,
factory
,
*
_
):
):
client
=
ssl_client
(
client
=
ssl_client
(
certificate
=
client_cert
,
key
=
client_key
,
authenticate
=
server_cert
)
certificate
=
client_cert
,
key
=
client_key
,
authenticate
=
server_cert
)
...
@@ -223,7 +230,7 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -223,7 +230,7 @@ class SSLConfigTest(ZEOConfigTest):
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
def
test_ssl_mockiavellian_client_pw
(
def
test_ssl_mockiavellian_client_pw
(
self
,
ClientStorage
,
factory
self
,
ClientStorage
,
factory
,
*
_
):
):
client
=
ssl_client
(
client
=
ssl_client
(
certificate
=
client_cert
,
key
=
client_key
,
certificate
=
client_cert
,
key
=
client_key
,
...
@@ -241,7 +248,7 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -241,7 +248,7 @@ class SSLConfigTest(ZEOConfigTest):
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
def
test_ssl_mockiavellian_client_server_hostname
(
def
test_ssl_mockiavellian_client_server_hostname
(
self
,
ClientStorage
,
factory
self
,
ClientStorage
,
factory
,
*
_
):
):
client
=
ssl_client
(
client
=
ssl_client
(
certificate
=
client_cert
,
key
=
client_key
,
authenticate
=
server_cert
,
certificate
=
client_cert
,
key
=
client_key
,
authenticate
=
server_cert
,
...
@@ -258,7 +265,7 @@ class SSLConfigTest(ZEOConfigTest):
...
@@ -258,7 +265,7 @@ class SSLConfigTest(ZEOConfigTest):
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ssl.create_default_context'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
@
mock
.
patch
(
'ZEO.ClientStorage.ClientStorage'
)
def
test_ssl_mockiavellian_client_check_hostname
(
def
test_ssl_mockiavellian_client_check_hostname
(
self
,
ClientStorage
,
factory
self
,
ClientStorage
,
factory
,
*
_
):
):
client
=
ssl_client
(
client
=
ssl_client
(
certificate
=
client_cert
,
key
=
client_key
,
authenticate
=
server_cert
,
certificate
=
client_cert
,
key
=
client_key
,
authenticate
=
server_cert
,
...
@@ -320,7 +327,10 @@ pwfunc = lambda : '1234'
...
@@ -320,7 +327,10 @@ pwfunc = lambda : '1234'
def
test_suite
():
def
test_suite
():
return
unittest
.
makeSuite
(
SSLConfigTest
)
return
unittest
.
TestSuite
((
unittest
.
makeSuite
(
SSLConfigTest
),
unittest
.
makeSuite
(
SSLConfigTestMockiavellian
),
))
# Helpers for other tests:
# Helpers for other tests:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment