Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
let's include the test in the PR, shall we?
- Loading branch information
Jim Fulton
committed
Jul 28, 2016
1 parent
dbb066d
commit 9fda363
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Clients can pass credentials to a server. | ||
This is an experimental feature to enable server authentication and | ||
authorization. | ||
""" | ||
from zope.testing import setupstack | ||
import unittest | ||
|
||
import ZEO.StorageServer | ||
|
||
class ClientAuthTests(setupstack.TestCase): | ||
|
||
def setUp(self): | ||
self.setUpDirectory() | ||
self.__register = ZEO.StorageServer.ZEOStorage.register | ||
|
||
def tearDown(self): | ||
ZEO.StorageServer.ZEOStorage.register = self.__register | ||
|
||
def test_passing_credentials(self): | ||
|
||
# First, we'll temporarily swap the storage server register | ||
# method with one that let's is see credentials that were passed: | ||
|
||
creds_log = [] | ||
|
||
def register(zs, storage_id, read_only, credentials=self): | ||
creds_log.append(credentials) | ||
return self.__register(zs, storage_id, read_only) | ||
|
||
ZEO.StorageServer.ZEOStorage.register = register | ||
|
||
# Now start an in process server | ||
addr, stop = ZEO.server() | ||
|
||
# If we connect, without providing credentials, then no | ||
# credentials will be passed to register: | ||
|
||
client = ZEO.client(addr) | ||
|
||
self.assertEqual(creds_log, [self]) | ||
client.close() | ||
creds_log.pop() | ||
|
||
# But if we pass credentials, they'll be passed to register: | ||
creds = dict(user='me', password='123') | ||
client = ZEO.client(addr, credentials=creds) | ||
self.assertEqual(creds_log, [creds]) | ||
client.close() | ||
|
||
stop() | ||
|
||
|
||
def test_suite(): | ||
return unittest.makeSuite(ClientAuthTests) | ||
|