Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'request_id': '89144def-b675-4c8a-590c-4f2ad4f1fae7',
'data': {
'keys': ['cats']
},
'renewable': False
}
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/groups'.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_groups(
mount_point=mount_point,
)
self.assertEqual(
first=mock_response,
second=response,
)
'groupattr': '',
'upndomain': '',
'discoverdn': False
},
'renewable': False
}
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/config'.format(
mount_point=mount_point,
)
requests_mocker.register_uri(
method='GET',
url=mock_url,
status_code=expected_status_code,
json=mock_response,
)
ldap = Ldap(adapter=Request())
response = ldap.read_configuration(
mount_point=mount_point,
)
self.assertEqual(
first=mock_response,
second=response,
)
'data': {
'policies': []
},
'renewable': False
}
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/groups/{name}'.format(
mount_point=mount_point,
name=group_name,
)
requests_mocker.register_uri(
method='GET',
url=mock_url,
status_code=expected_status_code,
json=mock_response,
)
ldap = Ldap(adapter=Request())
response = ldap.read_group(
name=group_name,
mount_point=mount_point,
)
self.assertEqual(
first=mock_response,
second=response,
)
'lease_duration': 0,
'request_id': 'c7a85e6c-fb1f-1d97-83a1-63746cb65551',
'data': {},
'renewable': False
}
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/login/{username}'.format(
mount_point=mount_point,
username=username,
)
requests_mocker.register_uri(
method='POST',
url=mock_url,
status_code=expected_status_code,
json=mock_response,
)
ldap = Ldap(adapter=Request())
response = ldap.login(
mount_point=mount_point,
username=username,
password='averynicepassword'
)
self.assertEqual(
first=mock_response,
second=response,
)
def test_delete_user(self, test_label, mount_point, requests_mocker):
expected_status_code = 204
username = 'somedude'
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/users/{username}'.format(
mount_point=mount_point,
username=username,
)
requests_mocker.register_uri(
method='DELETE',
url=mock_url,
status_code=expected_status_code,
)
ldap = Ldap(adapter=Request())
response = ldap.delete_user(
username=username,
mount_point=mount_point,
)
self.assertEqual(
first=expected_status_code,
second=response.status_code,
)
def test_create_or_update_user(self, test_label, mount_point, requests_mocker):
expected_status_code = 204
username = 'somedude'
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/users/{name}'.format(
mount_point=mount_point,
name=username,
)
requests_mocker.register_uri(
method='POST',
url=mock_url,
status_code=expected_status_code,
)
ldap = Ldap(adapter=Request())
response = ldap.create_or_update_user(
username=username,
mount_point=mount_point,
)
self.assertEqual(
first=expected_status_code,
second=response.status_code,
)
'policies': [],
'groups': ''
},
'renewable': False
}
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/users/{username}'.format(
mount_point=mount_point,
username=username,
)
requests_mocker.register_uri(
method='GET',
url=mock_url,
status_code=expected_status_code,
json=mock_response,
)
ldap = Ldap(adapter=Request())
response = ldap.read_user(
mount_point=mount_point,
username=username,
)
self.assertEqual(
first=mock_response,
second=response,
)
def test_configure(self, test_label, mount_point, requests_mocker):
expected_status_code = 204
mock_url = 'http://localhost:8200/v1/auth/{mount_point}/config'.format(
mount_point=mount_point,
)
requests_mocker.register_uri(
method='POST',
url=mock_url,
status_code=expected_status_code,
)
ldap = Ldap(adapter=Request())
response = ldap.configure(
user_dn='dc=users,cn=hvac,cn=network',
group_dn='ou=groups,cn=hvac,cn=network',
url='ldaps://ldap.python-hvac.org',
mount_point=mount_point,
)
self.assertEqual(
first=expected_status_code,
second=response.status_code,
)
def test_create_or_update_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/{group_name}'.format(
mount_point=mount_point,
group_name=group_name,
)
requests_mocker.register_uri(
method='POST',
url=mock_url,
status_code=expected_status_code,
)
ldap = Ldap(adapter=Request())
response = ldap.create_or_update_group(
name=group_name,
mount_point=mount_point,
)
self.assertEqual(
first=expected_status_code,
second=response.status_code,
)
new_method=api.auth_methods.Ldap.login,
)
def auth_ldap(self, *args, **kwargs):
return self.auth.ldap.login(*args, **kwargs)