From 336cb9e677fb9d654b72c97774e40390ed6f0e39 Mon Sep 17 00:00:00 2001 From: Sam Stavinoha Date: Wed, 16 Jul 2014 01:00:49 +0000 Subject: [PATCH 1/2] verify rsa.Key object to prevent segfault --- chef/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chef/api.py b/chef/api.py index 944cf32..4d8bc75 100644 --- a/chef/api.py +++ b/chef/api.py @@ -75,6 +75,8 @@ def __init__(self, url, key, client, version='0.10.8', headers={}): self.parsed_url = urlparse.urlparse(self.url) if not isinstance(key, Key): key = Key(key) + if not key.key: + raise ValueError("ChefAPI attribute 'key' was invalid.") self.key = key self.client = client self.version = version From de0c65f2b486c7f243015c6887e6b2bf9c3fc1b7 Mon Sep 17 00:00:00 2001 From: Sam Stavinoha Date: Wed, 16 Jul 2014 01:43:32 +0000 Subject: [PATCH 2/2] test rsa.Key verification --- chef/tests/test_api.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/chef/tests/test_api.py b/chef/tests/test_api.py index ffcb81a..53ed9c4 100644 --- a/chef/tests/test_api.py +++ b/chef/tests/test_api.py @@ -26,3 +26,9 @@ def test_env_variables(self): self.assertEqual(api.client, 'foobar') finally: del os.environ['_PYCHEF_TEST_'] + + def test_bad_key_raises(self): + invalids = [None, ''] + for item in invalids: + self.assertRaises( + ValueError, ChefAPI, 'foobar', item, 'user')