summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-04-24 15:28:57 -0400
committerSimo Sorce <simo@redhat.com>2015-04-27 15:06:28 -0400
commitdb42ea6f015d3d15728d1c26576531286c522ce7 (patch)
tree24bd9822341118e03c0723061e29b78258ddf3bd
parenta2ed51acfdff399a6ad6cd486eb22da9acf59280 (diff)
downloadcustodia-db42ea6f015d3d15728d1c26576531286c522ce7.tar.gz
custodia-db42ea6f015d3d15728d1c26576531286c522ce7.tar.xz
custodia-db42ea6f015d3d15728d1c26576531286c522ce7.zip
Basic custodia testing
Signed-off-by: Simo Sorce <simo@redhat.com>
-rw-r--r--tests/client.py21
-rw-r--r--tests/custodia.py33
-rw-r--r--tests/tests.py5
3 files changed, 58 insertions, 1 deletions
diff --git a/tests/client.py b/tests/client.py
new file mode 100644
index 0000000..39dad61
--- /dev/null
+++ b/tests/client.py
@@ -0,0 +1,21 @@
+# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
+
+try:
+ # pylint: disable=import-error
+ from httplib import HTTPConnection
+except ImportError:
+ # pylint: disable=import-error,no-name-in-module
+ from http.client import HTTPConnection
+import socket
+
+
+class LocalConnection(HTTPConnection):
+
+ def __init__(self, path):
+ HTTPConnection.__init__(self, 'localhost', 0)
+ self.unix_socket = path
+
+ def connect(self):
+ s = socket.socket(family=socket.AF_UNIX)
+ s.connect(self.unix_socket)
+ self.sock = s
diff --git a/tests/custodia.py b/tests/custodia.py
new file mode 100644
index 0000000..e5d6e35
--- /dev/null
+++ b/tests/custodia.py
@@ -0,0 +1,33 @@
+# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
+
+from __future__ import absolute_import
+from tests.client import LocalConnection
+import os
+import subprocess
+import time
+import unittest
+
+
+class CustodiaTests(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ env = os.environ.copy()
+ env['PYTHONPATH'] = './'
+ pexec = env.get('CUSTODIAPYTHON', 'python')
+ devnull = open(os.devnull, "w")
+ p = subprocess.Popen([pexec, 'custodia/custodia'], env=env,
+ stdout=devnull, stderr=devnull)
+ cls.custodia_process = p
+ time.sleep(1)
+
+ @classmethod
+ def AtearDownClass(self):
+ os.killpg(self.custodia_process.pid, signal.SIGTERM)
+
+ def test_connect(self):
+ conn = LocalConnection('./server_socket')
+ conn.connect()
+ conn.request('GET', '/', headers={'REMOTE_USER':'tests'})
+ r = conn.getresponse()
+ self.assertEqual(r.status, 200)
diff --git a/tests/tests.py b/tests/tests.py
index 8a1091d..5a2837e 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -1,6 +1,8 @@
+from __future__ import absolute_import
from custodia.secrets import SecretsTests
from custodia.store.sqlite import SqliteStoreTests
from custodia.message.kem import KEMTests
+from tests.custodia import CustodiaTests
import unittest
if __name__ == '__main__':
@@ -8,7 +10,8 @@ if __name__ == '__main__':
allUnitTests = [testLoad.loadTestsFromTestCase(SecretsTests),
testLoad.loadTestsFromTestCase(SqliteStoreTests),
- testLoad.loadTestsFromTestCase(KEMTests)]
+ testLoad.loadTestsFromTestCase(KEMTests),
+ testLoad.loadTestsFromTestCase(CustodiaTests)]
allTestsSuite = unittest.TestSuite(allUnitTests)