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 | |
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>
-rw-r--r-- | custodia/secrets.py | 4 | ||||
-rw-r--r-- | tests/custodia.py | 30 |
2 files changed, 30 insertions, 4 deletions
diff --git a/custodia/secrets.py b/custodia/secrets.py index dd7a76a..735d0ed 100644 --- a/custodia/secrets.py +++ b/custodia/secrets.py @@ -183,7 +183,9 @@ class Secrets(HTTPConsumer): def _get_key(self, trail, request, response): # default to simple - query = request.get('query', {'type': 'simple', 'value': ''}) + query = request.get('query', '') + if len(query) == 0: + query = {'type': 'simple', 'value': ''} try: msg = self._parse(request, query) except Exception as e: 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) + |