[Zodb-checkins] CVS: ZODB3/ZEO/tests - testAuth.py:1.1.2.9
ConnectionTests.py:1.22.2.3
Jeremy Hylton
jeremy at zope.com
Thu May 29 20:33:26 EDT 2003
Update of /cvs-repository/ZODB3/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv10787/ZEO/tests
Modified Files:
Tag: ZODB3-auth-branch
testAuth.py ConnectionTests.py
Log Message:
Refactor the auth tests to use ConnectionTest.
=== ZODB3/ZEO/tests/testAuth.py 1.1.2.8 => 1.1.2.9 ===
--- ZODB3/ZEO/tests/testAuth.py:1.1.2.8 Thu May 29 17:39:29 2003
+++ ZODB3/ZEO/tests/testAuth.py Thu May 29 19:33:26 2003
@@ -57,47 +57,33 @@
zconf.authentication_realm = self.realm
return zconf
+ def wait(self):
+ for i in range(25):
+ if self._storage.test_connection:
+ return
+ time.sleep(0.1)
+ self.fail("Timed out waiting for client to authenticate")
+
def testOK(self):
# Sleep for 0.2 seconds to give the server some time to start up
# seems to be needed before and after creating the storage
- time.sleep(self.wait)
- cs = self.openClientStorage(wait=0, username="foo", password="bar",
- realm=self.realm)
- try:
- time.sleep(self.wait)
-
- if cs is None:
- raise AssertionError, \
- "authentication for %s failed" % self.protocol
-
- if cs._connection == None:
- raise AssertionError, \
- "authentication for %s failed" % self.protocol
-
- cs._connection.poll()
- if not cs.is_connected():
- raise AssertionError, \
- "authentication for %s failed" % self.protocol
- finally:
- cs.close()
+ self._storage = self.openClientStorage(wait=0, username="foo",
+ password="bar", realm=self.realm)
+ print "ocs return", self._storage
+ self.wait()
+
+ self.assert_(self._storage._connection)
+ self._storage._connection.poll()
+ self.assert_(self._storage.is_connected())
def testNOK(self):
- time.sleep(self.wait)
- cs = self.openClientStorage(wait=0, username="foo", password="noogie",
- realm=self.realm)
- time.sleep(self.wait)
-
- # Normally a wrong password will return None immediately.
- if cs is None:
- return
-
- if cs._connection is None:
- return
-
- cs._connection.poll()
-
- if cs.is_connected():
- raise AssertionError, "authenticated with incorrect password"
+ self._storage = self.openClientStorage(wait=0, username="foo",
+ password="noogie",
+ realm=self.realm)
+ self.wait()
+ print self._storage
+ # If the test established a connection, then it failed.
+ self.failIf(self._storage._connection)
class PlainTextAuth(AuthTest):
import ZEO.tests.auth_plaintext
@@ -105,14 +91,6 @@
database = 'authdb.sha'
realm = "Plaintext Realm"
dbclass = ZEO.tests.auth_plaintext.Database
- wait = 0.2
-
-
-##class SRPAuth(AuthTest):
-## protocol = 'srp'
-## database = 'authdb.srp'
-## dbclass = SRPDatabase
-## wait = 1.0
class DigestAuth(AuthTest):
import ZEO.auth.auth_digest
@@ -120,7 +98,6 @@
database = "authdb.digest"
dbclass = ZEO.auth.auth_digest.DigestDatabase
realm = "Digest Realm"
- wait = 0.5
test_classes = [PlainTextAuth, DigestAuth]
=== ZODB3/ZEO/tests/ConnectionTests.py 1.22.2.2 => 1.22.2.3 ===
--- ZODB3/ZEO/tests/ConnectionTests.py:1.22.2.2 Thu May 29 17:30:09 2003
+++ ZODB3/ZEO/tests/ConnectionTests.py Thu May 29 19:33:26 2003
@@ -41,6 +41,8 @@
class TestClientStorage(ClientStorage):
+ test_connection = 0
+
def verify_cache(self, stub):
self.end_verify = threading.Event()
self.verify_result = ClientStorage.verify_cache(self, stub)
@@ -49,6 +51,12 @@
ClientStorage.endVerify(self)
self.end_verify.set()
+ def testConnection(self, conn):
+ try:
+ return ClientStorage.testConnection(self, conn)
+ finally:
+ self.test_connection = 1
+
class DummyDB:
def invalidate(self, *args, **kwargs):
pass
@@ -119,17 +127,16 @@
def openClientStorage(self, cache='', cache_size=200000, wait=1,
read_only=0, read_only_fallback=0,
username=None, password=None, realm=None):
- base = TestClientStorage(self.addr,
- client=cache,
- cache_size=cache_size,
- wait=wait,
- min_disconnect_poll=0.1,
- read_only=read_only,
- read_only_fallback=read_only_fallback,
- username=username,
- password=password,
- realm=realm)
- storage = base
+ storage = TestClientStorage(self.addr,
+ client=cache,
+ cache_size=cache_size,
+ wait=wait,
+ min_disconnect_poll=0.1,
+ read_only=read_only,
+ read_only_fallback=read_only_fallback,
+ username=username,
+ password=password,
+ realm=realm)
storage.registerDB(DummyDB(), None)
return storage
More information about the Zodb-checkins
mailing list