Commit 4e2a4c7e by Scott Duckworth

provide key_id template in SSHKEY_AUTHORIZED_KEYS_OPTIONS

parent dad8a403
...@@ -362,39 +362,39 @@ class UserKeyLookupTestCase(BaseTestCase): ...@@ -362,39 +362,39 @@ class UserKeyLookupTestCase(BaseTestCase):
def setUpClass(cls): def setUpClass(cls):
super(UserKeyLookupTestCase, cls).setUpClass() super(UserKeyLookupTestCase, cls).setUpClass()
cls.original_options = settings.SSHKEY_AUTHORIZED_KEYS_OPTIONS cls.original_options = settings.SSHKEY_AUTHORIZED_KEYS_OPTIONS
settings.SSHKEY_AUTHORIZED_KEYS_OPTIONS = 'command="{username}"' settings.SSHKEY_AUTHORIZED_KEYS_OPTIONS = 'command="{username} {key_id}"'
cls.user1 = User.objects.create(username='user1') cls.user1 = User.objects.create(username='user1')
cls.user2 = User.objects.create(username='user2') cls.user2 = User.objects.create(username='user2')
cls.key1_path = os.path.join(cls.key_dir, 'key1') cls.key1_path = os.path.join(cls.key_dir, 'key1')
ssh_keygen(file=cls.key1_path) ssh_keygen(file=cls.key1_path)
key1 = UserKey( cls.key1 = UserKey(
user = cls.user1, user = cls.user1,
name = 'key1', name = 'key1',
key = open(cls.key1_path+'.pub').read(), key = open(cls.key1_path+'.pub').read(),
) )
key1.full_clean() cls.key1.full_clean()
key1.save() cls.key1.save()
cls.key2_path = os.path.join(cls.key_dir, 'key2') cls.key2_path = os.path.join(cls.key_dir, 'key2')
ssh_keygen(file=cls.key2_path) ssh_keygen(file=cls.key2_path)
key2 = UserKey( cls.key2 = UserKey(
user = cls.user1, user = cls.user1,
name = 'key2', name = 'key2',
key = open(cls.key2_path+'.pub').read(), key = open(cls.key2_path+'.pub').read(),
) )
key2.full_clean() cls.key2.full_clean()
key2.save() cls.key2.save()
cls.key3_path = os.path.join(cls.key_dir, 'key3') cls.key3_path = os.path.join(cls.key_dir, 'key3')
ssh_keygen(file=cls.key3_path) ssh_keygen(file=cls.key3_path)
key3 = UserKey( cls.key3 = UserKey(
user = cls.user2, user = cls.user2,
name = 'key3', name = 'key3',
key = open(cls.key3_path+'.pub').read(), key = open(cls.key3_path+'.pub').read(),
) )
key3.full_clean() cls.key3.full_clean()
key3.save() cls.key3.save()
cls.key4_path = os.path.join(cls.key_dir, 'key4') cls.key4_path = os.path.join(cls.key_dir, 'key4')
ssh_keygen(file=cls.key4_path) ssh_keygen(file=cls.key4_path)
...@@ -414,9 +414,9 @@ class UserKeyLookupTestCase(BaseTestCase): ...@@ -414,9 +414,9 @@ class UserKeyLookupTestCase(BaseTestCase):
self.assertEqual(response['Content-Type'], 'text/plain') self.assertEqual(response['Content-Type'], 'text/plain')
actual_content = set(response.content.strip().split('\n')) actual_content = set(response.content.strip().split('\n'))
correct_content = set(( correct_content = set((
'command="user1" ' + open(self.key1_path + '.pub').read().strip(), 'command="user1 %s" %s' % (self.key1.id, open(self.key1_path + '.pub').read().strip()),
'command="user1" ' + open(self.key2_path + '.pub').read().strip(), 'command="user1 %s" %s' % (self.key2.id, open(self.key2_path + '.pub').read().strip()),
'command="user2" ' + open(self.key3_path + '.pub').read().strip(), 'command="user2 %s" %s' % (self.key3.id, open(self.key3_path + '.pub').read().strip()),
)) ))
self.assertEqual(actual_content, correct_content) self.assertEqual(actual_content, correct_content)
...@@ -431,7 +431,7 @@ class UserKeyLookupTestCase(BaseTestCase): ...@@ -431,7 +431,7 @@ class UserKeyLookupTestCase(BaseTestCase):
username = self.user1.username username = self.user1.username
actual_content = set(response.content.strip().split('\n')) actual_content = set(response.content.strip().split('\n'))
correct_content = set(( correct_content = set((
'command="user1" ' + open(self.key1_path + '.pub').read().strip(), 'command="user1 %s" %s' % (self.key1.id, open(self.key1_path + '.pub').read().strip()),
)) ))
self.assertEqual(actual_content, correct_content) self.assertEqual(actual_content, correct_content)
...@@ -446,7 +446,7 @@ class UserKeyLookupTestCase(BaseTestCase): ...@@ -446,7 +446,7 @@ class UserKeyLookupTestCase(BaseTestCase):
body = open(self.key1_path + '.pub').read().strip() body = open(self.key1_path + '.pub').read().strip()
actual_content = set(response.content.strip().split('\n')) actual_content = set(response.content.strip().split('\n'))
correct_content = set(( correct_content = set((
'command="user2" ' + open(self.key3_path + '.pub').read().strip(), 'command="user2 %s" %s' % (self.key3.id, open(self.key3_path + '.pub').read().strip()),
)) ))
self.assertEqual(actual_content, correct_content) self.assertEqual(actual_content, correct_content)
...@@ -461,8 +461,8 @@ class UserKeyLookupTestCase(BaseTestCase): ...@@ -461,8 +461,8 @@ class UserKeyLookupTestCase(BaseTestCase):
body = open(self.key1_path + '.pub').read().strip() body = open(self.key1_path + '.pub').read().strip()
actual_content = set(response.content.strip().split('\n')) actual_content = set(response.content.strip().split('\n'))
correct_content = set(( correct_content = set((
'command="user1" ' + open(self.key1_path + '.pub').read().strip(), 'command="user1 %s" %s' % (self.key1.id, open(self.key1_path + '.pub').read().strip()),
'command="user1" ' + open(self.key2_path + '.pub').read().strip(), 'command="user1 %s" %s' % (self.key2.id, open(self.key2_path + '.pub').read().strip()),
)) ))
self.assertEqual(actual_content, correct_content) self.assertEqual(actual_content, correct_content)
......
...@@ -54,7 +54,9 @@ def lookup(request): ...@@ -54,7 +54,9 @@ def lookup(request):
for key in keys: for key in keys:
if settings.SSHKEY_AUTHORIZED_KEYS_OPTIONS: if settings.SSHKEY_AUTHORIZED_KEYS_OPTIONS:
options = settings.SSHKEY_AUTHORIZED_KEYS_OPTIONS.format( options = settings.SSHKEY_AUTHORIZED_KEYS_OPTIONS.format(
username=key.user.username) + ' ' username=key.user.username,
key_id=key.id,
) + ' '
else: else:
options = '' options = ''
response += options + key.key + '\n' response += options + key.key + '\n'
......
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 sign in to comment