[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/master] Add integration tests which start the BridgeDB servers through the cli scripts.
commit 87360c1064f268c52e94b45983e6c902b236c565
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Tue Nov 19 03:52:31 2013 +0000
Add integration tests which start the BridgeDB servers through the cli scripts.
---
lib/bridgedb/test/bridgedb.conf | 55 ++++++++++++++++++
lib/bridgedb/test/test_bridgedb.py | 108 ++++++++++++++++++++++++++++++++++++
2 files changed, 163 insertions(+)
diff --git a/lib/bridgedb/test/bridgedb.conf b/lib/bridgedb/test/bridgedb.conf
new file mode 100644
index 0000000..ce12096
--- /dev/null
+++ b/lib/bridgedb/test/bridgedb.conf
@@ -0,0 +1,55 @@
+BRIDGE_FILES = ["bridge-descriptors"]
+EXTRA_INFO_FILES = ["cached-extrainfo", "cached-extrainfo.new"]
+STATUS_FILE = "networkstatus-bridges"
+HTTPS_CERT_FILE="cert"
+HTTPS_KEY_FILE="privkey.pem"
+LOGFILE = "bridgedb.log"
+ASSIGNMENTS_FILE = "assignments.log"
+PIDFILE = "bridgedb.pid"
+DB_FILE = "bridgedist.db"
+DB_LOG_FILE = "bridgedist.log"
+MASTER_KEY_FILE = "secret_key"
+PROXY_LIST_FILES = []
+LOGLEVEL = "DEBUG"
+SAFELOGGING = True
+LOGFILE_COUNT = 5
+LOGFILE_ROTATE_SIZE = 10000000
+BRIDGE_PURPOSE = "bridge"
+N_IP_CLUSTERS = 4
+FORCE_PORTS = [(443, 1)]
+FORCE_FLAGS = [("Stable", 1)]
+HTTPS_DIST = True
+HTTPS_BIND_IP = '127.0.0.1'
+HTTPS_PORT = 6789
+HTTPS_N_BRIDGES_PER_ANSWER = 3
+HTTPS_INCLUDE_FINGERPRINTS = True
+HTTPS_USE_IP_FROM_FORWARDED_HEADER = False
+HTTP_UNENCRYPTED_BIND_IP = None
+HTTP_UNENCRYPTED_PORT = None
+HTTP_USE_IP_FROM_FORWARDED_HEADER = False
+HTTP_N_BRIDGES_PER_ANSWER = 3
+EMAIL_DIST = True
+EMAIL_FROM_ADDR = "bridges@xxxxxxxxxxxxxx"
+EMAIL_SMTP_FROM_ADDR = "bridges@xxxxxxxxxxxxxx"
+EMAIL_SMTP_HOST = "127.0.0.1"
+EMAIL_SMTP_PORT = 25
+EMAIL_USERNAME = "bridges"
+EMAIL_DOMAINS = ["gmail.com", "yahoo.com"]
+EMAIL_DOMAIN_MAP = { "mail.google.com" : "gmail.com",
+ "googlemail.com" : "gmail.com"}
+EMAIL_DOMAIN_RULES = { 'gmail.com' : ["ignore_dots", "dkim"],
+ 'yahoo.com' : ["dkim"]}
+EMAIL_RESTRICT_IPS = []
+EMAIL_BIND_IP="127.0.0.1"
+EMAIL_PORT=6725
+EMAIL_N_BRIDGES_PER_ANSWER=3
+EMAIL_INCLUDE_FINGERPRINTS = True
+EMAIL_GPG_SIGNING_ENABLED = True
+EMAIL_GPG_SIGNING_KEY = 'TESTING.subkeys.sec'
+HTTPS_SHARE = 10
+EMAIL_SHARE = 10
+RESERVED_SHARE = 2
+FILE_BUCKETS = {}
+RECAPTCHA_ENABLED = False
+RECAPTCHA_PUB_KEY = ''
+RECAPTCHA_PRIV_KEY = ''
diff --git a/lib/bridgedb/test/test_bridgedb.py b/lib/bridgedb/test/test_bridgedb.py
new file mode 100644
index 0000000..1c5b649
--- /dev/null
+++ b/lib/bridgedb/test/test_bridgedb.py
@@ -0,0 +1,108 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of BridgeDB, a Tor bridge distribution system.
+#
+# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 <isis@xxxxxxxxxxxxxx>
+# please also see AUTHORS file
+# :copyright: (c) 2013, Isis Lovecruft
+# (c) 2007-2013, The Tor Project, Inc.
+# (c) 2007-2013, all entities within the AUTHORS file
+# :license: 3-Clause BSD, see LICENSE for licensing information
+
+"""Unittests for the `bridgedb` commandline script."""
+
+from __future__ import print_function
+
+import os
+import shutil
+import signal
+import time
+
+from functools import wraps
+from os.path import join as pjoin
+from subprocess import Popen, PIPE
+
+from twisted.python import log
+from twisted.python.procutils import which
+from twisted.trial import unittest
+
+
+def fileCheckDecorator(func):
+ @wraps(func)
+ def wrapper(self, src, dst, description):
+ print("Copying %s:\n %r\n\t\tâ?? â?? â??\n %r\n"
+ % (str(description), src, dst))
+ self.assertTrue(
+ os.path.isfile(src),
+ "Couldn't find original %s file: %r" % (str(description), src))
+ func(self, src, dst, description)
+ self.assertTrue(
+ os.path.isfile(dst),
+ "Couldn't find new %s file: %r" % (str(description), dst))
+ return wrapper
+
+class BridgeDBCliTest(unittest.TestCase):
+ """Test the `bridgedb` command."""
+
+ @fileCheckDecorator
+ def doCopyFile(self, src, dst, description=None):
+ shutil.copy(src, dst)
+
+ @fileCheckDecorator
+ def doMoveFile(self, src, dst, description=None):
+ shutil.move(src, dst)
+
+ def test_bridgedb_commands(self):
+ print('')
+ here = os.getcwd()
+ runDir = pjoin(here, 'rundir')
+ topDir = here.rstrip('_trial_temp')
+ scriptsDir = pjoin(topDir, 'scripts')
+
+ # Create the lowest directory we need, and all its parents:
+ os.makedirs(os.path.join(runDir, 'gnupghome'))
+
+ conf = pjoin(topDir, 'bridgedb.conf')
+ confMoved = pjoin(runDir, 'bridgedb.conf')
+ gpgFile = pjoin(topDir, 'gnupghome', 'TESTING.subkeys.sec')
+ gpgMoved = pjoin(runDir, 'gnupghome', 'TESTING.subkeys.sec')
+ certFile = pjoin(scriptsDir, 'cert')
+ certMoved = pjoin(runDir, 'cert')
+ keyFile = pjoin(scriptsDir, 'privkey.pem')
+ keyMoved = pjoin(runDir, 'privkey.pem')
+
+ makeSSLCertScript = os.path.join(scriptsDir, 'make-ssl-cert')
+ bridgedbScript = which('bridgedb') # this returns a list
+
+ self.doCopyFile(conf, confMoved, 'config')
+ self.doCopyFile(gpgFile, gpgMoved, 'GPG test key')
+ print("Running subcommands from directory:\n %r" % runDir)
+ print("Running %r..." % makeSSLCertScript)
+ makeSSLCertProcess = Popen(makeSSLCertScript)
+ makeSSLCertProcess.wait()
+ self.doMoveFile(certFile, certMoved, 'certificate')
+ self.doMoveFile(keyFile, keyMoved, 'SSL private key')
+
+ self.assertTrue(os.path.isfile(bridgedbScript[0]),
+ "Couldn't find bridgedb script %r" % bridgedbScript[0])
+ bridgedbScript = bridgedbScript[0]
+ print("Running bridgedb script %r..." % bridgedbScript)
+
+ print("Running `bridgedb mock' to generate mock bridge descriptors...")
+ mockProc = Popen([bridgedbScript, 'mock',
+ '-n', '50',
+ '-r', runDir])
+ mockProcCode = mockProc.wait()
+ #mockProcCode = os.system("%s mock -n 50 -r %s -c bridgedb.conf"
+ # % (bridgedbScript, runDir))
+ print("`bridgedb mock' exited with status code %d" % int(mockProcCode))
+
+ print("Running `bridgedb' to test server startups...")
+ bridgedbProc = Popen([bridgedbScript, '-r', runDir])
+ #bridgedbProcCode = os.system("%s -r %s -c bridgedb.conf"
+ # % (bridgedbScript, runDir))
+ time.sleep(30)
+ bridgedbProc.send_signal(signal.SIGINT)
+ bridgedbProcCode = bridgedbProc.wait()
+ print("`bridgedb' exited with status code %d" % int(bridgedbProcCode))
+ self.assertEqual(bridgedbProcCode, 0)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits