Skip to content
This repository was archived by the owner on May 9, 2020. It is now read-only.

Commit 5ee4cea

Browse files
committed
Merge pull request #32 from samstav/validatekeyobject
verify rsa.Key object to prevent segfault
2 parents bf23399 + de0c65f commit 5ee4cea

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

chef/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def __init__(self, url, key, client, version='0.10.8', headers={}):
7575
self.parsed_url = urlparse.urlparse(self.url)
7676
if not isinstance(key, Key):
7777
key = Key(key)
78+
if not key.key:
79+
raise ValueError("ChefAPI attribute 'key' was invalid.")
7880
self.key = key
7981
self.client = client
8082
self.version = version

chef/tests/test_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ def test_env_variables(self):
2626
self.assertEqual(api.client, 'foobar')
2727
finally:
2828
del os.environ['_PYCHEF_TEST_']
29+
30+
def test_bad_key_raises(self):
31+
invalids = [None, '']
32+
for item in invalids:
33+
self.assertRaises(
34+
ValueError, ChefAPI, 'foobar', item, 'user')

0 commit comments

Comments
 (0)