diff options
| author | Simo Sorce <simo@redhat.com> | 2015-04-25 15:40:03 -0400 |
|---|---|---|
| committer | Simo Sorce <simo@redhat.com> | 2015-04-27 15:06:32 -0400 |
| commit | f85ee3c9ef9839b06c1af654a54e3e32175f7d2e (patch) | |
| tree | 39bdecf2b92f0a6a18e6723685214d0fbd3dc1ec /tests | |
| parent | db42ea6f015d3d15728d1c26576531286c522ce7 (diff) | |
| download | custodia-f85ee3c9ef9839b06c1af654a54e3e32175f7d2e.tar.gz custodia-f85ee3c9ef9839b06c1af654a54e3e32175f7d2e.tar.xz custodia-f85ee3c9ef9839b06c1af654a54e3e32175f7d2e.zip | |
Add tests and fixes for 'simple' keys
A missing query would not lead to the default 'simple' type being selected.
Add tests for PUT/GET/DELETE of a simple key.
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/custodia.py | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/tests/custodia.py b/tests/custodia.py index e5d6e35..4243047 100644 --- a/tests/custodia.py +++ b/tests/custodia.py @@ -2,6 +2,7 @@ from __future__ import absolute_import from tests.client import LocalConnection +import json import os import subprocess import time @@ -20,14 +21,37 @@ class CustodiaTests(unittest.TestCase): stdout=devnull, stderr=devnull) cls.custodia_process = p time.sleep(1) + cls.dfl_headers = {'REMOTE_USER': 'test', + 'Content-Type': 'application/json'} @classmethod def AtearDownClass(self): os.killpg(self.custodia_process.pid, signal.SIGTERM) - def test_connect(self): + def _make_request(self, cmd, path, headers=None, body=None): conn = LocalConnection('./server_socket') conn.connect() - conn.request('GET', '/', headers={'REMOTE_USER':'tests'}) - r = conn.getresponse() + conn.request(cmd, path, body=body, headers=self.dfl_headers) + return conn.getresponse() + + def test_connect(self): + r = self._make_request('GET', '/', {'REMOTE_USER': 'tests'}) + self.assertEqual(r.status, 200) + + def test_simple_0_set_key(self): + data = {'type': 'simple', 'value': 'VmVycnlTZWNyZXQK'} + r = self._make_request('PUT', '/secrets/test/key', + self.dfl_headers, json.dumps(data)) + self.assertEqual(r.status, 201) + + def test_simple_1_get_key(self): + r = self._make_request('GET', '/secrets/test/key', self.dfl_headers) self.assertEqual(r.status, 200) + body = r.read() + data = {'type': 'simple', 'value': 'VmVycnlTZWNyZXQK'} + self.assertEqual(json.loads(body), data) + + def test_simple_2_del_key(self): + r = self._make_request('DELETE', '/secrets/test/key', self.dfl_headers) + self.assertEqual(r.status, 204) + |
