Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.toolbox
Commits
d2205bdd
Commit
d2205bdd
authored
Jun 19, 2019
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
6fa398cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
+26
-15
slapos/promise/plugin/check_url_available.py
slapos/promise/plugin/check_url_available.py
+2
-2
slapos/test/promise/plugin/test_check_url_available.py
slapos/test/promise/plugin/test_check_url_available.py
+24
-13
No files found.
slapos/promise/plugin/check_url_available.py
View file @
d2205bdd
...
...
@@ -45,7 +45,7 @@ class RunPromise(GenericPromise):
result
=
requests
.
get
(
url
,
verify
=
verify
,
allow_redirects
=
True
,
timeout
=
timeout
,
cert
=
cert
)
except
requests
.
exceptions
.
SSLError
as
e
:
if
'certificate verify failed'
in
str
(
e
.
message
):
if
'certificate verify failed'
in
str
(
e
):
self
.
logger
.
error
(
"ERROR SSL verify failed while accessing %r"
%
(
url
,))
else
:
...
...
@@ -56,7 +56,7 @@ class RunPromise(GenericPromise):
self
.
logger
.
error
(
"ERROR connection not possible while accessing %r"
%
(
url
,
))
return
except
Exception
,
e
:
except
Exception
as
e
:
self
.
logger
.
error
(
"ERROR: %s"
%
(
e
,))
return
...
...
slapos/test/promise/plugin/test_check_url_available.py
View file @
d2205bdd
...
...
@@ -27,6 +27,7 @@
from
slapos.grid.promise
import
PromiseError
from
slapos.test.promise.plugin
import
TestPromisePluginMixin
from
slapos.util
import
str2bytes
from
cryptography
import
x509
from
cryptography.hazmat.backends
import
default_backend
...
...
@@ -34,12 +35,13 @@ from cryptography.hazmat.primitives import hashes
from
cryptography.hazmat.primitives
import
serialization
from
cryptography.hazmat.primitives.asymmetric
import
rsa
from
cryptography.x509.oid
import
NameOID
import
BaseHTTPServer
from
six.moves
import
BaseHTTPServer
import
datetime
import
ipaddress
import
json
import
multiprocessing
import
os
import
six
import
ssl
import
tempfile
import
time
...
...
@@ -66,10 +68,10 @@ def createCSR(common_name, ip=None):
subject_alternative_name_list
=
[]
if
ip
is
not
None
:
subject_alternative_name_list
.
append
(
x509
.
IPAddress
(
ipaddress
.
ip_address
(
unicode
(
ip
)
))
x509
.
IPAddress
(
ipaddress
.
ip_address
(
ip
))
)
csr
=
x509
.
CertificateSigningRequestBuilder
().
subject_name
(
x509
.
Name
([
x509
.
NameAttribute
(
NameOID
.
COMMON_NAME
,
unicode
(
common_name
)
),
x509
.
NameAttribute
(
NameOID
.
COMMON_NAME
,
common_name
),
]))
if
len
(
subject_alternative_name_list
):
...
...
@@ -89,10 +91,10 @@ class CertificateAuthority(object):
public_key
=
self
.
key
.
public_key
()
builder
=
x509
.
CertificateBuilder
()
builder
=
builder
.
subject_name
(
x509
.
Name
([
x509
.
NameAttribute
(
NameOID
.
COMMON_NAME
,
unicode
(
common_name
)
),
x509
.
NameAttribute
(
NameOID
.
COMMON_NAME
,
common_name
),
]))
builder
=
builder
.
issuer_name
(
x509
.
Name
([
x509
.
NameAttribute
(
NameOID
.
COMMON_NAME
,
unicode
(
common_name
)
),
x509
.
NameAttribute
(
NameOID
.
COMMON_NAME
,
common_name
),
]))
builder
=
builder
.
not_valid_before
(
datetime
.
datetime
.
utcnow
()
-
datetime
.
timedelta
(
days
=
2
))
...
...
@@ -147,16 +149,19 @@ class TestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
response
=
{
'Path'
:
self
.
path
,
}
self
.
wfile
.
write
(
json
.
dumps
(
response
,
indent
=
2
))
self
.
wfile
.
write
(
str2bytes
(
json
.
dumps
(
response
,
indent
=
2
)
))
class
CheckUrlAvailableMixin
(
TestPromisePluginMixin
):
@
classmethod
def
setUpClass
(
cls
):
cls
.
another_server_ca
=
CertificateAuthority
(
"Another Server Root CA"
)
cls
.
test_server_ca
=
CertificateAuthority
(
"Test Server Root CA"
)
cls
.
another_server_ca
=
CertificateAuthority
(
u"Another Server Root CA"
)
cls
.
test_server_ca
=
CertificateAuthority
(
u"Test Server Root CA"
)
ip
=
SLAPOS_TEST_IPV4
.
decode
(
'utf-8'
)
\
if
isinstance
(
SLAPOS_TEST_IPV4
,
bytes
)
\
else
SLAPOS_TEST_IPV4
key
,
key_pem
,
csr
,
csr_pem
=
createCSR
(
"testserver.example.com"
,
SLAPOS_TEST_IPV4
)
u"testserver.example.com"
,
ip
)
_
,
cls
.
test_server_certificate_pem
=
cls
.
test_server_ca
.
signCSR
(
csr
)
cls
.
test_server_certificate_file
=
tempfile
.
NamedTemporaryFile
(
...
...
@@ -267,10 +272,16 @@ class TestCheckUrlAvailable(CheckUrlAvailableMixin):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR: Invalid URL u'https://': No host supplied"
)
if
six
.
PY3
:
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR: Invalid URL 'https://': No host supplied"
)
else
:
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR: Invalid URL u'https://': No host supplied"
)
def
test_check_url_malformed
(
self
):
content
=
self
.
base_content
%
{
...
...
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