Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-sshkey
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cffe528a
authored
Jul 02, 2014
by
Scott Duckworth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for exporting keys
parent
a9c91bba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
6 deletions
+41
-6
django_sshkey/tests.py
+41
-6
No files found.
django_sshkey/tests.py
View file @
cffe528a
...
...
@@ -50,9 +50,14 @@ def ssh_keygen(type=None, passphrase='', comment=None, file=None):
cmd
+=
[
'-f'
,
file
]
subprocess
.
check_call
(
cmd
)
def
ssh_key_export
(
input_file
,
output_file
,
format
=
'RFC4716'
):
cmd
=
[
'ssh-keygen'
,
'-e'
,
'-m'
,
format
,
'-f'
,
input_file
]
with
open
(
output_file
,
'wb'
)
as
f
:
def
ssh_key_export
(
input_path
,
output_path
,
format
=
'RFC4716'
):
cmd
=
[
'ssh-keygen'
,
'-e'
,
'-m'
,
format
,
'-f'
,
input_path
]
with
open
(
output_path
,
'wb'
)
as
f
:
subprocess
.
check_call
(
cmd
,
stdout
=
f
)
def
ssh_key_import
(
input_path
,
output_path
,
format
=
'RFC4716'
):
cmd
=
[
'ssh-keygen'
,
'-i'
,
'-m'
,
format
,
'-f'
,
input_path
]
with
open
(
output_path
,
'wb'
)
as
f
:
subprocess
.
check_call
(
cmd
,
stdout
=
f
)
def
ssh_fingerprint
(
pubkey_path
):
...
...
@@ -274,7 +279,7 @@ class RFC4716TestCase(BaseTestCase):
def
tearDown
(
self
):
UserKey
.
objects
.
all
()
.
delete
()
def
test_with_comment
(
self
):
def
test_
import_
with_comment
(
self
):
key
=
UserKey
(
user
=
self
.
user1
,
name
=
'name'
,
...
...
@@ -284,7 +289,7 @@ class RFC4716TestCase(BaseTestCase):
key
.
save
()
self
.
assertEqual
(
key
.
key
.
split
()[:
2
],
open
(
self
.
key1_path
+
'.pub'
)
.
read
()
.
split
()[:
2
])
def
test_without_comment
(
self
):
def
test_
import_
without_comment
(
self
):
key
=
UserKey
(
user
=
self
.
user1
,
name
=
'name'
,
...
...
@@ -294,6 +299,21 @@ class RFC4716TestCase(BaseTestCase):
key
.
save
()
self
.
assertEqual
(
key
.
key
.
split
()[:
2
],
open
(
self
.
key2_path
+
'.pub'
)
.
read
()
.
split
()[:
2
])
def
test_export
(
self
):
key
=
UserKey
(
user
=
self
.
user1
,
name
=
'name'
,
key
=
open
(
self
.
key1_path
+
'.pub'
)
.
read
(),
)
key
.
full_clean
()
key
.
save
()
export_path
=
os
.
path
.
join
(
self
.
key_dir
,
'export'
)
import_path
=
os
.
path
.
join
(
self
.
key_dir
,
'import'
)
with
open
(
export_path
,
'w'
)
as
f
:
f
.
write
(
key
.
export
(
'RFC4716'
))
ssh_key_import
(
export_path
,
import_path
,
'RFC4716'
)
self
.
assertEqual
(
open
(
import_path
)
.
read
()
.
split
()[:
2
],
open
(
self
.
key1_path
+
'.pub'
)
.
read
()
.
split
()[:
2
])
class
PemTestCase
(
BaseTestCase
):
@classmethod
def
setUpClass
(
cls
):
...
...
@@ -312,7 +332,7 @@ class PemTestCase(BaseTestCase):
def
tearDown
(
self
):
UserKey
.
objects
.
all
()
.
delete
()
def
test
(
self
):
def
test
_import
(
self
):
key
=
UserKey
(
user
=
self
.
user1
,
name
=
'name'
,
...
...
@@ -322,6 +342,21 @@ class PemTestCase(BaseTestCase):
key
.
save
()
self
.
assertEqual
(
key
.
key
.
split
()[:
2
],
open
(
self
.
key1_path
+
'.pub'
)
.
read
()
.
split
()[:
2
])
def
test_export
(
self
):
key
=
UserKey
(
user
=
self
.
user1
,
name
=
'name'
,
key
=
open
(
self
.
key1_path
+
'.pub'
)
.
read
(),
)
key
.
full_clean
()
key
.
save
()
export_path
=
os
.
path
.
join
(
self
.
key_dir
,
'export'
)
import_path
=
os
.
path
.
join
(
self
.
key_dir
,
'import'
)
with
open
(
export_path
,
'w'
)
as
f
:
f
.
write
(
key
.
export
(
'PEM'
))
ssh_key_import
(
export_path
,
import_path
,
'PEM'
)
self
.
assertEqual
(
open
(
import_path
)
.
read
()
.
split
()[:
2
],
open
(
self
.
key1_path
+
'.pub'
)
.
read
()
.
split
()[:
2
])
class
UserKeyLookupTestCase
(
BaseTestCase
):
@classmethod
def
setUpClass
(
cls
):
...
...
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