Exemplo n.º 1
0
 def test_non_string_username_object_fails(self):
     with self.assertRaises(TypeError) as error:
         not_a_string = object()
         requests_chef.ChefAuth(not_a_string, TEST_PEM)
     expected_message = ("'user_id' must be a 'str' "
                         "object, not {0!r}".format(not_a_string))
     self.assertEqual(expected_message, str(error.exception))
Exemplo n.º 2
0
 def test_from_string(self):
     serialized_key = self.private_key.private_bytes(
         encoding=serialization.Encoding.PEM,
         format=serialization.PrivateFormat.PKCS8,
         encryption_algorithm=serialization.NoEncryption())
     handler = requests_chef.ChefAuth(self.user, serialized_key)
     request = handler(self.request)
     self.assert_xops_headers(request)
Exemplo n.º 3
0
 def test_from_requests_chef_rsakey_from_path(self):
     serialized_key = self.private_key.private_bytes(
         encoding=serialization.Encoding.PEM,
         format=serialization.PrivateFormat.PKCS8,
         encryption_algorithm=serialization.NoEncryption())
     sfx = 'requests-chef-tests.pem'
     with tempfile.NamedTemporaryFile(suffix=sfx, mode='wb') as pem:
         pem.write(serialized_key)
         pem.flush()
         rsakey = requests_chef.RSAKey.load_pem(pem.name)
     handler = requests_chef.ChefAuth(self.user, rsakey)
     request = handler(self.request)
     self.assert_xops_headers(request)
Exemplo n.º 4
0
 def authenticate(self, user_id, private_key):
     auth = requests_chef.ChefAuth(user_id, private_key)
     self.session.auth = auth
     self.user_id = user_id
     return auth
Exemplo n.º 5
0
 def test_bogus_keyvalue_fails(self):
     with self.assertRaises(ValueError) as error:
         requests_chef.ChefAuth('user', 'not-a-key-or-path-to-one')
     expected_message = 'Could not unserialize key data.'
     self.assertEqual(expected_message, six.text_type(error.exception))
Exemplo n.º 6
0
 def test_missing_values_fail(self):
     with self.assertRaises(ValueError):
         requests_chef.ChefAuth(None, None)
Exemplo n.º 7
0
 def test_missing_pem_fails(self):
     with self.assertRaises(ValueError):
         requests_chef.ChefAuth('.', None)
Exemplo n.º 8
0
 def test_missing_username_fails(self):
     with self.assertRaises(ValueError):
         requests_chef.ChefAuth(None, '.')
Exemplo n.º 9
0
 def test_from_requests_chef_rsakey_direct(self):
     rsakey = requests_chef.RSAKey(self.private_key)
     handler = requests_chef.ChefAuth(self.user, rsakey)
     request = handler(self.request)
     self.assert_xops_headers(request)
Exemplo n.º 10
0
 def test_from_cryptography_rsaprivatekey(self):
     handler = requests_chef.ChefAuth(self.user, self.private_key)
     request = handler(self.request)
     self.assert_xops_headers(request)
Exemplo n.º 11
0
 def test_repr(self):
     handler = requests_chef.ChefAuth(self.user, self.private_key)
     expected = 'ChefAuth(patsy)'
     self.assertEqual(expected, repr(handler))
Exemplo n.º 12
0
 def authenticate(self, user_id, private_key):
     """Authenticate this session with the chef server."""
     auth = requests_chef.ChefAuth(user_id, private_key)
     self.session.auth = auth
     self.user_id = user_id
     return auth