Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Roque
slapos.core
Commits
b17809ef
Commit
b17809ef
authored
Jul 07, 2017
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos slap_tool: fix test on certificate
parent
3a82479d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
134 additions
and
23 deletions
+134
-23
master/bt5/slapos_slap_tool/TestTemplateItem/portal_components/test.erp5.testSlapOSSlapTool.py
...ateItem/portal_components/test.erp5.testSlapOSSlapTool.py
+116
-6
master/bt5/slapos_slap_tool/TestTemplateItem/portal_components/test.erp5.testSlapOSSlapTool.xml
...teItem/portal_components/test.erp5.testSlapOSSlapTool.xml
+18
-17
No files found.
master/bt5/slapos_slap_tool/TestTemplateItem/portal_components/test.erp5.testSlapOSSlapTool.py
View file @
b17809ef
...
@@ -34,6 +34,25 @@ class Simulator:
...
@@ -34,6 +34,25 @@ class Simulator:
'reckwargs'
:
kwargs
})
'reckwargs'
:
kwargs
})
open
(
self
.
outfile
,
'w'
).
write
(
repr
(
l
))
open
(
self
.
outfile
,
'w'
).
write
(
repr
(
l
))
def
generateCertificateRequest
():
return
"""-----BEGIN CERTIFICATE REQUEST-----
MIIClDCCAXwCAQAwJjEkMCIGA1UEAwwbbmdpbnhAY2VydGlmaWNhdGUuYXV0aG9y
aXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx0KJXUK6dDNQ1R7C
t3p4HBtBZ3LWqW8SzAvQUDHIlDuxVAa1CRZVcDA79Z7wLosUDDk1ImB7ZADt2nhX
xBJY66cCLtNamboQX9Lz6aCymWOHntHLVXj65tF6z0U19H+5c7Js/J+xfuDtya2Y
zGN27jsx6xLSgf/RZ2e9YB1yI6CfvBb8U4OD521iK6UxPXW9dnQLcNdwzo378pfT
oAqcVsyV0F+6aSjHfasPljC72AmEh6/lpiT4hzNZ6A7Xz1lPbJ8TKTD1FMSDB/Nd
POqglfsQY62GWbHSvhwLm6sfyusO3zeUFdxLmVztGjRAMWV/c65BiaHUR/CrWSoA
J8aP/QIDAQABoCkwJwYJKoZIhvcNAQkOMRowGDAJBgNVHRMEAjAAMAsGA1UdDwQE
AwIF4DANBgkqhkiG9w0BAQsFAAOCAQEAiL2PQCFeUrshU2/G8W1YDlbcseicJZqF
wft2UOxTRA95CKgW5WMxTbpqUbVXtw7fccgud7GcT8jwxx2g1rq9vgh2SaIu0dCQ
MEUMHPih3eb0atze/+QZr/v0a/+9LuoWffZU7FGEAtEpBDXV1n4X3RmSQXdtrmUj
a3af5hwyhoXqX4wZ/sB6rA00CyyimPLLiRyDDqY/hYHvUEOLMzdmlpb7yAeMZSsO
b20ShhRHw0cPl+dQaU5ejXGmXOIywslIVn8ffy5K7rv6PQ2OSdRazbSehqFNXzG1
VqyqoMcNesjuW8qbVF4LrOyqLo7RR/6x8Owhu9+rOm2ukMgzF+PAow==
-----END CERTIFICATE REQUEST-----"""
class
TestSlapOSSlapToolMixin
(
testSlapOSMixin
):
class
TestSlapOSSlapToolMixin
(
testSlapOSMixin
):
def
afterSetUp
(
self
,
person
=
None
):
def
afterSetUp
(
self
,
person
=
None
):
testSlapOSMixin
.
afterSetUp
(
self
)
testSlapOSMixin
.
afterSetUp
(
self
)
...
@@ -891,8 +910,9 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
...
@@ -891,8 +910,9 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
partition_id
=
self
.
start_requested_software_instance
.
getAggregateValue
(
partition_id
=
self
.
start_requested_software_instance
.
getAggregateValue
(
portal_type
=
'Computer Partition'
).
getReference
()
portal_type
=
'Computer Partition'
).
getReference
()
self
.
login
(
self
.
start_requested_software_instance
.
getReference
())
self
.
login
(
self
.
start_requested_software_instance
.
getReference
())
csr_string
=
generateCertificateRequest
()
response
=
self
.
portal_slap
.
getComputerPartitionCertificate
(
self
.
computer_id
,
response
=
self
.
portal_slap
.
getComputerPartitionCertificate
(
self
.
computer_id
,
partition_id
)
partition_id
,
certificate_request
=
csr_string
)
self
.
assertEqual
(
200
,
response
.
status
)
self
.
assertEqual
(
200
,
response
.
status
)
self
.
assertEqual
(
'public, max-age=0, must-revalidate'
,
self
.
assertEqual
(
'public, max-age=0, must-revalidate'
,
response
.
headers
.
get
(
'cache-control'
))
response
.
headers
.
get
(
'cache-control'
))
...
@@ -901,6 +921,14 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
...
@@ -901,6 +921,14 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
self
.
assertTrue
(
'last-modified'
in
response
.
headers
)
self
.
assertTrue
(
'last-modified'
in
response
.
headers
)
self
.
assertEqual
(
'text/xml; charset=utf-8'
,
self
.
assertEqual
(
'text/xml; charset=utf-8'
,
response
.
headers
.
get
(
'content-type'
))
response
.
headers
.
get
(
'content-type'
))
# Get assigned certificate
certificate_login_list
=
[
x
for
x
in
self
.
start_requested_software_instance
.
contentValues
(
portal_type
=
"Certificate Login"
)
if
x
.
getValidationState
()
==
'validated'
]
self
.
assertEqual
(
len
(
certificate_login_list
),
1
)
certificate
=
self
.
start_requested_software_instance
.
getCertificate
()
# check returned XML
# check returned XML
xml_fp
=
StringIO
.
StringIO
()
xml_fp
=
StringIO
.
StringIO
()
...
@@ -919,8 +947,69 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
...
@@ -919,8 +947,69 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
</dictionary>
</dictionary>
</marshal>
</marshal>
"""
%
dict
(
"""
%
dict
(
instance_certificate
=
self
.
start_requested_software_instance
.
getSslCertificate
(),
instance_certificate
=
certificate
,
instance_key
=
self
.
start_requested_software_instance
.
getSslKey
()
instance_key
=
""
)
self
.
assertEqual
(
expected_xml
,
got_xml
,
'
\
n
'
.
join
([
q
for
q
in
difflib
.
unified_diff
(
expected_xml
.
split
(
'
\
n
'
),
got_xml
.
split
(
'
\
n
'
))]))
def
test_getComputerPartitionCertificate_when_exists
(
self
):
self
.
_makeComplexComputer
()
partition_id
=
self
.
start_requested_software_instance
.
getAggregateValue
(
portal_type
=
'Computer Partition'
).
getReference
()
self
.
login
(
self
.
start_requested_software_instance
.
getReference
())
csr_string
=
generateCertificateRequest
()
response
=
self
.
portal_slap
.
getComputerPartitionCertificate
(
self
.
computer_id
,
partition_id
,
certificate_request
=
csr_string
)
self
.
assertEqual
(
200
,
response
.
status
)
self
.
assertEqual
(
'public, max-age=0, must-revalidate'
,
response
.
headers
.
get
(
'cache-control'
))
self
.
assertEqual
(
'REMOTE_USER'
,
response
.
headers
.
get
(
'vary'
))
self
.
assertTrue
(
'last-modified'
in
response
.
headers
)
self
.
assertEqual
(
'text/xml; charset=utf-8'
,
response
.
headers
.
get
(
'content-type'
))
# Get assigned certificate
certificate
=
self
.
start_requested_software_instance
.
getCertificate
()
# get assigned certificate
response
=
self
.
portal_slap
.
getComputerPartitionCertificate
(
self
.
computer_id
,
partition_id
,
certificate_request
=
None
)
self
.
assertEqual
(
200
,
response
.
status
)
self
.
assertEqual
(
'public, max-age=0, must-revalidate'
,
response
.
headers
.
get
(
'cache-control'
))
self
.
assertEqual
(
'REMOTE_USER'
,
response
.
headers
.
get
(
'vary'
))
self
.
assertTrue
(
'last-modified'
in
response
.
headers
)
self
.
assertEqual
(
'text/xml; charset=utf-8'
,
response
.
headers
.
get
(
'content-type'
))
certificate_login_list
=
[
x
for
x
in
self
.
start_requested_software_instance
.
contentValues
(
portal_type
=
"Certificate Login"
)
if
x
.
getValidationState
()
==
'validated'
]
self
.
assertEqual
(
len
(
certificate_login_list
),
1
)
# check returned XML
xml_fp
=
StringIO
.
StringIO
()
xml
.
dom
.
ext
.
PrettyPrint
(
xml
.
dom
.
ext
.
reader
.
Sax
.
FromXml
(
response
.
body
),
stream
=
xml_fp
)
xml_fp
.
seek
(
0
)
got_xml
=
xml_fp
.
read
()
expected_xml
=
"""
\
<?xml version='1.0' encoding='UTF-8'?>
<marshal>
<dictionary id='i2'>
<string>certificate</string>
<string>%(instance_certificate)s</string>
<string>key</string>
<string>%(instance_key)s</string>
</dictionary>
</marshal>
"""
%
dict
(
instance_certificate
=
certificate
,
instance_key
=
""
)
)
self
.
assertEqual
(
expected_xml
,
got_xml
,
self
.
assertEqual
(
expected_xml
,
got_xml
,
'
\
n
'
.
join
([
q
for
q
in
difflib
.
unified_diff
(
expected_xml
.
split
(
'
\
n
'
),
got_xml
.
split
(
'
\
n
'
))]))
'
\
n
'
.
join
([
q
for
q
in
difflib
.
unified_diff
(
expected_xml
.
split
(
'
\
n
'
),
got_xml
.
split
(
'
\
n
'
))]))
...
@@ -1596,6 +1685,16 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
...
@@ -1596,6 +1685,16 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
partition_id
=
self
.
destroy_requested_software_instance
.
getAggregateValue
(
partition_id
=
self
.
destroy_requested_software_instance
.
getAggregateValue
(
portal_type
=
'Computer Partition'
).
getReference
()
portal_type
=
'Computer Partition'
).
getReference
()
self
.
login
(
self
.
destroy_requested_software_instance
.
getReference
())
self
.
login
(
self
.
destroy_requested_software_instance
.
getReference
())
csr_string
=
generateCertificateRequest
()
response
=
self
.
portal_slap
.
getComputerPartitionCertificate
(
self
.
computer_id
,
partition_id
,
certificate_request
=
csr_string
)
self
.
assertEqual
(
200
,
response
.
status
)
# Get assigned certificate
certificate
=
self
.
destroy_requested_software_instance
.
getCertificate
()
for
cert
in
self
.
destroy_requested_software_instance
.
contentValues
(
portal_type
=
"Certificate Login"
):
self
.
assertTrue
(
cert
.
getValidationState
()
==
"validated"
)
response
=
self
.
portal_slap
.
destroyedComputerPartition
(
self
.
computer_id
,
response
=
self
.
portal_slap
.
destroyedComputerPartition
(
self
.
computer_id
,
partition_id
)
partition_id
)
self
.
assertEqual
(
'None'
,
response
)
self
.
assertEqual
(
'None'
,
response
)
...
@@ -1604,6 +1703,9 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
...
@@ -1604,6 +1703,9 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSSlapToolMixin):
self
.
assertEqual
(
None
,
self
.
destroy_requested_software_instance
.
getSslKey
())
self
.
assertEqual
(
None
,
self
.
destroy_requested_software_instance
.
getSslKey
())
self
.
assertEqual
(
None
,
self
.
destroy_requested_software_instance
.
getSslCertificate
())
self
.
assertEqual
(
None
,
self
.
destroy_requested_software_instance
.
getSslCertificate
())
for
cert
in
self
.
destroy_requested_software_instance
.
contentValues
(
portal_type
=
"Certificate Login"
):
self
.
assertTrue
(
cert
.
getValidationState
()
==
"invalidated"
)
def
assertInstanceRequestSimulator
(
self
,
args
,
kwargs
):
def
assertInstanceRequestSimulator
(
self
,
args
,
kwargs
):
stored
=
eval
(
open
(
self
.
instance_request_simulator
).
read
())
stored
=
eval
(
open
(
self
.
instance_request_simulator
).
read
())
# do the same translation magic as in workflow
# do the same translation magic as in workflow
...
@@ -2938,10 +3040,14 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
...
@@ -2938,10 +3040,14 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
'generateComputerCertificate'
)
'generateComputerCertificate'
)
computer_certificate
=
'live_
\
n
certificate_%s'
%
self
.
generateNewId
()
computer_certificate
=
'live_
\
n
certificate_%s'
%
self
.
generateNewId
()
computer_key
=
'live_
\
n
key_%s'
%
self
.
generateNewId
()
computer_key
=
""
url
=
'http://ca.certificate/%s'
%
self
.
generateNewId
()
certificate_request
=
'live_
\
n
key_%s'
%
self
.
generateNewId
()
self
.
portal
.
REQUEST
.
set
(
'computer_certificate'
,
computer_certificate
)
self
.
portal
.
REQUEST
.
set
(
'computer_certificate'
,
computer_certificate
)
self
.
portal
.
REQUEST
.
set
(
'computer_key'
,
computer_key
)
self
.
portal
.
REQUEST
.
set
(
'computer_key'
,
computer_key
)
response
=
self
.
portal_slap
.
generateComputerCertificate
(
self
.
computer_id
)
self
.
portal
.
REQUEST
.
set
(
'computer_certificate_url'
,
url
)
response
=
self
.
portal_slap
.
generateComputerCertificate
(
self
.
computer_id
,
certificate_request
)
# check returned XML
# check returned XML
xml_fp
=
StringIO
.
StringIO
()
xml_fp
=
StringIO
.
StringIO
()
...
@@ -2958,9 +3064,13 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
...
@@ -2958,9 +3064,13 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSSlapToolMixin):
<unicode>%(computer_certificate)s</unicode>
<unicode>%(computer_certificate)s</unicode>
<string>key</string>
<string>key</string>
<unicode>%(computer_key)s</unicode>
<unicode>%(computer_key)s</unicode>
<string>url</string>
<unicode>%(url)s</unicode>
</dictionary>
</dictionary>
</marshal>
</marshal>
"""
%
{
'computer_key'
:
computer_key
,
'computer_certificate'
:
computer_certificate
}
"""
%
{
'computer_key'
:
computer_key
,
'computer_certificate'
:
computer_certificate
,
'url'
:
url
}
self
.
assertEqual
(
expected_xml
,
got_xml
,
self
.
assertEqual
(
expected_xml
,
got_xml
,
'
\
n
'
.
join
([
q
for
q
in
difflib
.
unified_diff
(
expected_xml
.
split
(
'
\
n
'
),
got_xml
.
split
(
'
\
n
'
))]))
'
\
n
'
.
join
([
q
for
q
in
difflib
.
unified_diff
(
expected_xml
.
split
(
'
\
n
'
),
got_xml
.
split
(
'
\
n
'
))]))
...
...
master/bt5/slapos_slap_tool/TestTemplateItem/portal_components/test.erp5.testSlapOSSlapTool.xml
View file @
b17809ef
...
@@ -47,23 +47,24 @@
...
@@ -47,23 +47,24 @@
<value>
<value>
<tuple>
<tuple>
<string>
W: 29, 10: Use of eval (eval-used)
</string>
<string>
W: 29, 10: Use of eval (eval-used)
</string>
<string>
W: 38, 2: Arguments number differs from overridden \'afterSetUp\' method (arguments-differ)
</string>
<string>
W: 57, 2: Arguments number differs from overridden \'afterSetUp\' method (arguments-differ)
</string>
<string>
W:517, 13: Use of eval (eval-used)
</string>
<string>
W:536, 13: Use of eval (eval-used)
</string>
<string>
W:568, 13: Use of eval (eval-used)
</string>
<string>
W:587, 13: Use of eval (eval-used)
</string>
<string>
W:793, 13: Use of eval (eval-used)
</string>
<string>
W:812, 13: Use of eval (eval-used)
</string>
<string>
W:1401, 13: Use of eval (eval-used)
</string>
<string>
W:1490, 13: Use of eval (eval-used)
</string>
<string>
W:1514, 13: Use of eval (eval-used)
</string>
<string>
W:1603, 13: Use of eval (eval-used)
</string>
<string>
W:1568, 13: Use of eval (eval-used)
</string>
<string>
W:1657, 13: Use of eval (eval-used)
</string>
<string>
W:1608, 13: Use of eval (eval-used)
</string>
<string>
W:1694, 4: Unused variable \'certificate\' (unused-variable)
</string>
<string>
W:2015, 2: Arguments number differs from overridden \'afterSetUp\' method (arguments-differ)
</string>
<string>
W:1710, 13: Use of eval (eval-used)
</string>
<string>
W:2111, 13: Use of eval (eval-used)
</string>
<string>
W:2234, 2: Arguments number differs from overridden \'afterSetUp\' method (arguments-differ)
</string>
<string>
W:2496, 13: Use of eval (eval-used)
</string>
<string>
W:2330, 13: Use of eval (eval-used)
</string>
<string>
W:2550, 13: Use of eval (eval-used)
</string>
<string>
W:2715, 13: Use of eval (eval-used)
</string>
<string>
W:2577, 13: Use of eval (eval-used)
</string>
<string>
W:2769, 13: Use of eval (eval-used)
</string>
<string>
W:2732, 13: Use of eval (eval-used)
</string>
<string>
W:2796, 13: Use of eval (eval-used)
</string>
<string>
W:2760, 13: Use of eval (eval-used)
</string>
<string>
W:2951, 13: Use of eval (eval-used)
</string>
<string>
W:2809, 13: Use of eval (eval-used)
</string>
<string>
W:2979, 13: Use of eval (eval-used)
</string>
<string>
W:2856, 13: Use of eval (eval-used)
</string>
<string>
W:3028, 13: Use of eval (eval-used)
</string>
<string>
W:3083, 13: Use of eval (eval-used)
</string>
</tuple>
</tuple>
</value>
</value>
</item>
</item>
...
...
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