Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
78ac0909
Commit
78ac0909
authored
Jul 02, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test parsing of known hosts
parent
e068b1db
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
9 deletions
+72
-9
trans/admin_views.py
trans/admin_views.py
+9
-9
trans/tests/admin.py
trans/tests/admin.py
+12
-0
trans/tests/data/known_hosts
trans/tests/data/known_hosts
+51
-0
No files found.
trans/admin_views.py
View file @
78ac0909
...
...
@@ -39,6 +39,9 @@ import os
# List of default domain names on which warn user
DEFAULT_DOMAINS
=
(
'example.net'
,
'example.com'
)
# SSH key files
KNOWN_HOSTS_FILE
=
os
.
path
.
expanduser
(
'~/.ssh/known_hosts'
)
RSA_KEY_FILE
=
os
.
path
.
expanduser
(
'~/.ssh/id_rsa.pub'
)
@
staff_member_required
def
report
(
request
):
...
...
@@ -165,7 +168,7 @@ def get_host_keys():
'''
try
:
result
=
[]
with
open
(
os
.
path
.
expanduser
(
'~/.ssh/known_hosts'
)
,
'r'
)
as
handle
:
with
open
(
KNOWN_HOSTS_FILE
,
'r'
)
as
handle
:
for
line
in
handle
:
if
' ssh-rsa '
not
in
line
:
continue
...
...
@@ -181,13 +184,10 @@ def ssh(request):
'''
Show information and manipulate with SSH key.
'''
# Path to key, we default to RSA keys
key_path
=
os
.
path
.
expanduser
(
'~/.ssh/id_rsa.pub'
)
# Check whether we can generate SSH key
try
:
ret
=
subprocess
.
check_call
([
'which'
,
'ssh-keygen'
])
can_generate
=
(
ret
==
0
and
not
os
.
path
.
exists
(
key_path
))
can_generate
=
(
ret
==
0
and
not
os
.
path
.
exists
(
RSA_KEY_FILE
))
except
:
can_generate
=
False
...
...
@@ -197,7 +197,7 @@ def ssh(request):
# Generate key if it does not exist yet
if
can_generate
and
action
==
'generate'
:
# Create directory if it does not exist
key_dir
=
os
.
path
.
dirname
(
key_path
)
key_dir
=
os
.
path
.
dirname
(
RSA_KEY_FILE
)
if
not
os
.
path
.
exists
(
key_dir
):
os
.
makedirs
(
key_dir
)
...
...
@@ -209,7 +209,7 @@ def ssh(request):
'-N'
,
''
,
'-C'
,
'Weblate'
,
'-t'
,
'rsa'
,
'-f'
,
key_path
[:
-
4
]
'-f'
,
RSA_KEY_FILE
[:
-
4
]
],
stderr
=
subprocess
.
STDOUT
,
)
...
...
@@ -221,8 +221,8 @@ def ssh(request):
)
# Read key data if it exists
if
os
.
path
.
exists
(
key_path
):
key_data
=
file
(
key_path
).
read
()
if
os
.
path
.
exists
(
RSA_KEY_FILE
):
key_data
=
file
(
RSA_KEY_FILE
).
read
()
key_type
,
key_fingerprint
,
key_id
=
key_data
.
strip
().
split
(
None
,
2
)
key
=
{
'key'
:
key_data
,
...
...
trans/tests/admin.py
View file @
78ac0909
...
...
@@ -19,7 +19,12 @@
#
from
trans.tests.views
import
ViewTestCase
import
trans.admin_views
from
django.test
import
TestCase
from
django.core.urlresolvers
import
reverse
from
trans.tests.util
import
get_test_file
TEST_HOSTS
=
get_test_file
(
'known_hosts'
)
class
AdminTest
(
ViewTestCase
):
...
...
@@ -47,3 +52,10 @@ class AdminTest(ViewTestCase):
def
test_report
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'admin-report'
))
self
.
assertContains
(
response
,
'On branch master'
)
class
SSHKeysTest
(
TestCase
):
def
test_parse
(
self
):
trans
.
admin_views
.
KNOWN_HOSTS_FILE
=
TEST_HOSTS
hosts
=
trans
.
admin_views
.
get_host_keys
()
self
.
assertEquals
(
len
(
hosts
),
50
)
trans/tests/data/known_hosts
0 → 100644
View file @
78ac0909
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment