Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.libnetworkcache
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
Łukasz Nowak
slapos.libnetworkcache
Commits
b0bd708b
Commit
b0bd708b
authored
Sep 02, 2011
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Follow changes in test.
parent
6e0205fc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
66 deletions
+18
-66
slapos/libnetworkcachetests.py
slapos/libnetworkcachetests.py
+18
-66
No files found.
slapos/libnetworkcachetests.py
View file @
b0bd708b
...
...
@@ -9,6 +9,7 @@ import random
import
shutil
import
socket
import
ssl
import
subprocess
import
tempfile
import
threading
import
time
...
...
@@ -767,71 +768,22 @@ class OnlineTestWrongChecksum(OnlineMixin, unittest.TestCase):
self
.
test_data
)
class
LibNetworkCacheMixin
(
unittest
.
TestCase
):
def
setUp
(
self
):
''' Setup the test. '''
self
.
pub_file_descriptor
=
tempfile
.
NamedTemporaryFile
()
self
.
priv_file_descritor
=
tempfile
.
NamedTemporaryFile
()
self
.
signature_certificate_file
=
self
.
pub_file_descriptor
.
name
self
.
signature_private_key_file
=
self
.
priv_file_descritor
.
name
self
.
signature_creation_argument_list
=
\
(
'--signature-certificate-file'
,
self
.
signature_certificate_file
,
'--signature-private-key-file'
,
self
.
signature_private_key_file
,
'--country'
,
'BR'
,
'--state-name'
,
'Campos'
,
'--locality-name'
,
'Rio de Janeiro'
,
'--organization-name'
,
'Nexedi'
,
'--organization-unit-name'
,
'Dev'
,
'--common-name'
,
'R500.com'
,
'--email'
,
'test@example.com'
)
self
.
option_dict
=
slapos
.
signature
.
parseArgument
(
*
self
.
signature_creation_argument_list
)
self
.
cert_as_text
=
slapos
.
signature
.
createPrivateKeyAndCertificateFile
(
**
self
.
option_dict
)
def
tearDown
(
self
):
''' Remove the files which have been created during the test. '''
self
.
priv_file_descritor
.
close
()
self
.
pub_file_descriptor
.
close
()
class
GenerateSignatureScriptTest
(
LibNetworkCacheMixin
):
class
GenerateSignatureScriptTest
(
unittest
.
TestCase
):
''' Class which must test the signature.py script. '''
def
test_generate_certificate
(
self
):
key
=
os
.
path
.
join
(
tempfile
.
gettempdir
(),
tempfile
.
gettempprefix
()
+
str
(
random
.
random
()))
certificate
=
os
.
path
.
join
(
tempfile
.
gettempdir
(),
tempfile
.
gettempprefix
()
+
str
(
random
.
random
()))
common_name
=
str
(
random
.
random
())
def
test_parse_argument_with_empty_list
(
self
):
'''
If the argument list is empty, then the parseArgument method should
return a dictionary with default argument values.
'''
default_dict
=
{
'organization_name'
:
'Default Company Ltd'
,
'state_name'
:
'Default Province'
,
'organization_unit_name'
:
''
,
'common_name'
:
''
,
'country'
:
'XX'
,
'locality_name'
:
'Default City'
,
'signature_private_key_file'
:
'private.pem'
,
'signature_certificate_file'
:
'public.pem'
,
'email'
:
''
}
self
.
assertEquals
(
default_dict
,
slapos
.
signature
.
parseArgument
())
def
test_parse_argument
(
self
):
'''
Check if the argument is properly set.
'''
size_argument_list
=
len
(
self
.
signature_creation_argument_list
)
/
2
size_option_dict
=
len
(
self
.
option_dict
)
self
.
assertEquals
(
size_argument_list
,
size_option_dict
,
"Argument list should have the same size of option dict."
)
# Assert if the values are equals.
for
value
in
self
.
option_dict
.
values
():
self
.
assertTrue
(
value
in
self
.
signature_creation_argument_list
,
\
'%s is not in %s.'
%
(
value
,
self
.
signature_creation_argument_list
))
def
test_key_and_certificate_file_creation
(
self
):
'''
Check if key file and the certificate file are being created correctly.
'''
self
.
assertTrue
(
os
.
path
.
exists
(
self
.
signature_certificate_file
))
self
.
assertTrue
(
os
.
path
.
exists
(
self
.
signature_private_key_file
))
try
:
slapos
.
signature
.
generateCertificate
(
certificate
,
key
,
common_name
)
result
=
subprocess
.
check_output
([
'openssl'
,
'x509'
,
'-noout'
,
'-subject'
,
'-in'
,
certificate
])
self
.
assertEqual
(
'subject= /CN=%s'
%
common_name
,
result
.
strip
())
finally
:
if
os
.
path
.
exists
(
key
):
os
.
unlink
(
key
)
if
os
.
path
.
exists
(
certificate
):
os
.
unlink
(
certificate
)
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