def __init__(self, url, key, client, version='0.9.12'): self.url = url.rstrip('/') self.parsed_url = urlparse.urlparse(self.url) if not isinstance(key, Key): key = Key(key) self.key = key self.client = client self.version = version self.platform = self.parsed_url.hostname == 'api.opscode.com' if not api_stack_value(): self.set_default()
def __init__(self, url, key, client, version='0.10.8', headers={}): self.url = url.rstrip('/') self.parsed_url = urlparse.urlparse(self.url) if not isinstance(key, Key): key = Key(key) self.key = key self.client = client self.version = version self.headers = dict((k.lower(), v) for k, v in headers.iteritems()) self.version_parsed = pkg_resources.parse_version(self.version) self.platform = self.parsed_url.hostname == 'api.opscode.com' if not api_stack_value(): self.set_default()
def __init__(self, url, key, client, version='0.10.8', headers={}): self.url = url.rstrip('/') self.parsed_url = six.moves.urllib.parse.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 self.headers = dict((k.lower(), v) for k, v in six.iteritems(headers)) self.version_parsed = pkg_resources.parse_version(self.version) self.platform = self.parsed_url.hostname == 'api.opscode.com' if not api_stack_value(): self.set_default()
def generate_key(self): key = Key.generate(2048) update(self, key_pem=key.public_export()) self._key_cache = key return key
def test_list_fail(self): api = TestChefAPI(self.client, Key.generate(2048), self._client.name) self.assertRaises(chef.ChefError, chef.Client.list, api=api)
def test_no_sig2(self): path = "/clients" headers = self.sign_request(path, key=Key.generate(2048)) response = self.client.get("/api" + path, **headers) self.assertEqual(response.status_code, 401)
def test_generate_load(self): key = Key.generate() key2 = Key(key.private_export()) self.assertFalse(key2.public) key3 = Key(key.public_export()) self.assertTrue(key3.public)
def test_generate(self): key = Key.generate() msg = 'Test string!' self.assertEqual(key.public_decrypt(key.private_encrypt(msg)), msg)
def test_encrypt_decrypt_pubkey(self): key = Key(os.path.join(TEST_ROOT, 'client.pem')) pubkey = Key(os.path.join(TEST_ROOT, 'client_pub.pem')) msg = 'Test string!' self.assertEqual(pubkey.public_decrypt(key.private_encrypt(msg)), msg)
def test_public_export_pubkey(self): key = Key(os.path.join(TEST_ROOT, 'client_pub.pem')) raw = open(os.path.join(TEST_ROOT, 'client_pub.pem'), 'rb').read() self.assertTrue(key.public_export().strip(), raw.strip())
def test_private_export_pubkey(self): key = Key(os.path.join(TEST_ROOT, 'client_pub.pem')) with self.assertRaises(SSLError): key.private_export()