Commit 582f79c1 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

User: non admin SSH key management

For User instances that already have a token, it is now
possible to manage SSH keys even if the root password is
unknown to the tests.

--HG--
branch : stable
parent ef0f9ec9f942
......@@ -123,10 +123,21 @@ class User(object):
assert resp.status_code == 201, "Failed to activate %r" % self
def ensure_ssh_pub_key(self, pubkey, title='heptapod-tests'):
"""Upload the SSH public key if needed.
Does not require any special privilege if a token for the user
is already known
"""
hepta = self.heptapod
keys_api_url = '/'.join((
hepta.api_url, 'users', str(self.id), 'keys'))
headers = hepta.root_token_headers
if self.token:
keys_api_url = '/'.join((
hepta.api_url, 'user', 'keys'))
headers = self.token_headers()
else:
keys_api_url = '/'.join((
hepta.api_url, 'users', str(self.id), 'keys'))
headers = hepta.root_token_headers
ls_resp = requests.get(keys_api_url, headers=headers)
assert ls_resp.status_code == 200
......@@ -145,6 +156,31 @@ class User(object):
assert create_resp.status_code == 201
assert create_resp.json()['title'] == title
def delete_ssh_keys(self):
"""Delete all SSH keys of current user.
Does not require any special privilege.
"""
hepta = self.heptapod
if self.token:
keys_api_url = '/'.join((
hepta.api_url, 'user', 'keys'))
headers = self.token_headers()
else:
keys_api_url = '/'.join((
hepta.api_url, 'users', str(self.id), 'keys'))
headers = hepta.root_token_headers
ls_resp = requests.get(keys_api_url, headers=headers)
assert ls_resp.status_code == 200
# check existence based on title. This is quite lame (we should
# check fingerprint), but that's good enough for these first tests.
for key_info in ls_resp.json():
resp = requests.delete('%s/%d' % (keys_api_url, key_info['id']),
headers=headers)
assert resp.status_code == 204
@property
def ssh_command(self):
"""Return a SSH command to perform operations as the given user.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment