Esempio n. 1
0
def _q_index(request):
    errors = []
    key_lines = ''
    user = request.user
    sshkeys = user.sshkeys
    if request.method == "POST":
        key_lines = request.get_form_var('ssh')
        newsshkeys = []
        errorkeys = []
        for index, line in enumerate(key_lines.splitlines()):
            valid = SSHKey.validate(user.name, line)
            if not valid:
                errorkeys.append((index, line))
                continue
            duplicated = SSHKey.is_duplicated(user.name, line)
            if duplicated:
                errorkeys.append((index, line))
                continue
            newsshkeys.append(line)

        if not errorkeys:
            for key in newsshkeys:
                SSHKey.add(user.name, key)
            return request.redirect('/settings/ssh')

        error_prefix = 'Please check your SSH Key, Line: '
        for no, key in errorkeys:
            error = error_prefix + '%s ' % no
            errors.append(error)
    return st('/settings/ssh.html', **locals())
Esempio n. 2
0
 def test_get(self):
     newkey = SSHKey.add('test', KEY1)
     key = SSHKey.get(newkey.id)
     assert isinstance(key, SSHKey)
     assert key.fingerprint == KEY1_FINGERPRINT
     assert key.finger == KEY1_FINGERPRINT
     assert key.title == KEY1_TITLE
     assert key.key == KEY1
Esempio n. 3
0
 def test_get(self):
     newkey = SSHKey.add('test', KEY1)
     key = SSHKey.get(newkey.id)
     assert isinstance(key, SSHKey)
     assert key.fingerprint == KEY1_FINGERPRINT
     assert key.finger == KEY1_FINGERPRINT
     assert key.title == KEY1_TITLE
     assert key.key == KEY1
Esempio n. 4
0
 def test_validate(self):
     r = SSHKey.validate('test', KEY1)
     assert r is True
     r = SSHKey.validate('test', KEY2)
     assert r is None
     r = SSHKey.validate('test', KEY3)
     assert r is None
     r = SSHKey.validate('test', KEY4)
     assert r is True
Esempio n. 5
0
 def test_validate(self):
     r = SSHKey.validate('test', KEY1)
     assert r is True
     r = SSHKey.validate('test', KEY2)
     assert r is None
     r = SSHKey.validate('test', KEY3)
     assert r is None
     r = SSHKey.validate('test', KEY4)
     assert r is True
Esempio n. 6
0
def _q_lookup(request, sshkey_id):
    if request.get_form_var('_method') == 'delete':
        user = request.user
        sshkey = SSHKey.check_own_by_user(user.name, sshkey_id)
        if sshkey:
            sshkey.delete()
        return request.redirect('/settings/ssh')
Esempio n. 7
0
def get_user_handler(username, key):
    # ssh username
    if username != "git":
        return None

    # ssh key
    if not key:
        return None
    fingerprint = hexlify(key.get_fingerprint())
    fingerprint = ":".join([fingerprint[i : 2 + i] for i in range(0, len(fingerprint), 2)])
    sshkey = SSHKey.get_by_fingerprint(fingerprint)
    if not sshkey:
        return "guest"
    return sshkey.user_id
Esempio n. 8
0
def get_user_handler(username, key):
    # ssh username
    if username != 'git':
        return None

    # ssh key
    if not key:
        return None
    fingerprint = hexlify(key.get_fingerprint())
    fingerprint = ":".join(
        [fingerprint[i:2 + i] for i in range(0, len(fingerprint), 2)])
    sshkey = SSHKey.get_by_fingerprint(fingerprint)
    if not sshkey:
        return 'guest'
    return sshkey.user_id
Esempio n. 9
0
 def test_duplicate(self):
     SSHKey.add('test', KEY1)
     r = SSHKey.is_duplicated('test', KEY1)
     assert r is True
     r = SSHKey.is_duplicated('test', KEY5)
     assert r is None
Esempio n. 10
0
 def test_delete(self):
     newkey = SSHKey.add('test', KEY1)
     newkey.delete()
     key = SSHKey.get(newkey.id)
     assert key is None
Esempio n. 11
0
 def sshkeys(self):
     return SSHKey.gets_by_user_id(self.name)
Esempio n. 12
0
 def sshkeys(self):
     return SSHKey.gets_by_user_id(self.name)
Esempio n. 13
0
 def test_duplicate(self):
     SSHKey.add('test', KEY1)
     r = SSHKey.is_duplicated('test', KEY1)
     assert r is True
     r = SSHKey.is_duplicated('test', KEY5)
     assert r is None
Esempio n. 14
0
 def test_delete(self):
     newkey = SSHKey.add('test', KEY1)
     newkey.delete()
     key = SSHKey.get(newkey.id)
     assert key is None