Commit 4834ccd5 authored by Michal Čihař's avatar Michal Čihař

Test ssh key scanning with fake binary

This avoids need to have network access during the test.
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent fa354f0d
#!/bin/sh
# Fake key scan program to return SSH key
echo '# github.com SSH-2.0-libssh-0.7.0'
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='
echo '# github.com SSH-2.0-libssh-0.7.0'
echo 'no hostkey alg'
......@@ -20,10 +20,10 @@
from weblate.trans.tests.test_views import ViewTestCase
from django.core.urlresolvers import reverse
from unittest import SkipTest
from weblate.trans.util import add_configuration_error
from weblate import appsettings
from weblate.trans.tests import OverrideSettings
from weblate.trans.tests.utils import get_test_file
import os
......@@ -58,18 +58,23 @@ class AdminTest(ViewTestCase):
@OverrideSettings(DATA_DIR=OverrideSettings.TEMP_DIR)
def test_ssh_add(self):
# Verify there is button for adding
response = self.client.get(reverse('admin-ssh'))
self.assertContains(response, 'Add host key')
try:
oldpath = os.environ['PATH']
os.environ['PATH'] = ':'.join(
(get_test_file(''), os.environ['PATH'])
)
# Verify there is button for adding
response = self.client.get(reverse('admin-ssh'))
self.assertContains(response, 'Add host key')
# Add the key
response = self.client.post(
reverse('admin-ssh'),
{'action': 'add-host', 'host': 'github.com'}
)
if 'Name or service not known' in response.content:
raise SkipTest('Network error')
self.assertContains(response, 'Added host key for github.com')
# Add the key
response = self.client.post(
reverse('admin-ssh'),
{'action': 'add-host', 'host': 'github.com'}
)
self.assertContains(response, 'Added host key for github.com')
finally:
os.environ['PATH'] = oldpath
# Check the file contains it
hostsfile = os.path.join(appsettings.DATA_DIR, 'ssh', 'known_hosts')
......
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