Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_configure_duo_access(self, test_label, mount_point, requests_mocker):
expected_status_code = 204
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/duo/access'.format(
mount_point=mount_point,
)
requests_mocker.register_uri(
method='POST',
url=mock_url,
status_code=expected_status_code,
)
mfa = Mfa(adapter=Request())
response = mfa.configure_duo_access(
mount_point=mount_point,
host='someapisubdomain.python-hvac.org',
integration_key='ikey',
secret_key='supersecret',
)
self.assertEqual(
first=expected_status_code,
second=response.status_code,
)
mock_response = {
"auth": {
"client_token": "f33f8c72-924e-11f8-cb43-ac59d697597c",
"accessor": "0e9e354a-520f-df04-6867-ee81cae3d42d",
"policies": test_policies,
"lease_duration": 2764800,
"renewable": True,
},
}
requests_mocker.register_uri(
method='POST',
url=mock_url,
status_code=expected_status_code,
json=mock_response,
)
azure = Azure(adapter=Request())
if raises is not None:
with self.assertRaises(raises):
azure.login(
role=role_name,
jwt='my-jwt',
mount_point=self.TEST_MOUNT_POINT,
**test_params
)
else:
login_response = azure.login(
role=role_name,
jwt='my-jwt',
mount_point=self.TEST_MOUNT_POINT,
**test_params
)
logging.debug('login_response: %s' % login_response)
'request_id': '0c34cc02-2f75-7deb-a531-33cf7434a729',
'data': {
'keys': ['somedude']
},
'renewable': False
}
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/users'.format(
mount_point=mount_point,
)
requests_mocker.register_uri(
method='LIST',
url=mock_url,
status_code=expected_status_code,
json=mock_response,
)
ldap = Ldap(adapter=Request())
response = ldap.list_users(
mount_point=mount_point,
)
self.assertEqual(
first=mock_response,
second=response,
)
def test_delete_group(self, test_label, mount_point, requests_mocker):
expected_status_code = 204
group_name = 'hvac'
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/groups/{name}'.format(
mount_point=mount_point,
name=group_name,
)
requests_mocker.register_uri(
method='DELETE',
url=mock_url,
status_code=expected_status_code,
)
ldap = Ldap(adapter=Request())
response = ldap.delete_group(
name=group_name,
mount_point=mount_point,
)
self.assertEqual(
first=expected_status_code,
second=response.status_code,
)
:ptype url: str
:param token: One shot Token to use
:ptype token: str
:returns: secret_id to use for Vault Access
:rtype: str"""
import hvac
try:
# hvac 0.10.1 changed default adapter to JSONAdapter
client = hvac.Client(url=url, token=token, adapter=hvac.adapters.Request)
except AttributeError:
# hvac < 0.6.2 doesn't have adapter but uses the same response interface
client = hvac.Client(url=url, token=token)
else:
# hvac < 0.9.2 assumes adapter is an instance, so doesn't instantiate
if not isinstance(client.adapter, hvac.adapters.Request):
client.adapter = hvac.adapters.Request(base_uri=url, token=token)
response = client._post('/v1/sys/wrapping/unwrap')
if response.status_code == 200:
data = response.json()
return data['data']['secret_id']
def retrieve_secret_id(url, token):
"""Retrieve a response-wrapped secret_id from Vault
:param url: URL to Vault Server
:ptype url: str
:param token: One shot Token to use
:ptype token: str
:returns: secret_id to use for Vault Access
:rtype: str"""
import hvac
try:
# hvac 0.10.1 changed default adapter to JSONAdapter
client = hvac.Client(url=url, token=token, adapter=hvac.adapters.Request)
except AttributeError:
# hvac < 0.6.2 doesn't have adapter but uses the same response interface
client = hvac.Client(url=url, token=token)
else:
# hvac < 0.9.2 assumes adapter is an instance, so doesn't instantiate
if not isinstance(client.adapter, hvac.adapters.Request):
client.adapter = hvac.adapters.Request(base_uri=url, token=token)
response = client._post('/v1/sys/wrapping/unwrap')
if response.status_code == 200:
data = response.json()
return data['data']['secret_id']
def urljoin(*args):
return adapters.Request.urljoin(*args)