Skip to content

Commit

Permalink
let's include the test in the PR, shall we?
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fulton committed Jul 28, 2016
1 parent dbb066d commit 9fda363
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/ZEO/tests/test_client_credentials.py
@@ -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)

0 comments on commit 9fda363

Please sign in to comment.