Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
envsetup
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mediaserver
envsetup
Commits
b2013e79
Commit
b2013e79
authored
6 years ago
by
Nicolas KAROLAK
Browse files
Options
Downloads
Patches
Plain Diff
test_ssl: reorganize to continue test on error/warning
parent
63790f57
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_ssl.py
+28
-20
28 additions, 20 deletions
tests/test_ssl.py
with
28 additions
and
20 deletions
tests/test_ssl.py
+
28
−
20
View file @
b2013e79
...
@@ -36,6 +36,9 @@ conf_servers = (
...
@@ -36,6 +36,9 @@ conf_servers = (
(
'
CM_SERVER_NAME
'
,
'
campusmanager
'
),
(
'
CM_SERVER_NAME
'
,
'
campusmanager
'
),
)
)
all_ok
=
True
failure
=
False
with
open
(
'
/etc/hosts
'
,
'
r
'
)
as
fo
:
with
open
(
'
/etc/hosts
'
,
'
r
'
)
as
fo
:
hosts
=
fo
.
read
()
hosts
=
fo
.
read
()
...
@@ -47,34 +50,39 @@ for s, d in conf_servers:
...
@@ -47,34 +50,39 @@ for s, d in conf_servers:
if
v
not
in
hosts
:
if
v
not
in
hosts
:
# the domain is not in the hosts file, the service is surely not installed
# the domain is not in the hosts file, the service is surely not installed
continue
continue
try
:
# further tests
conn
=
ssl
.
create_connection
((
v
,
443
))
context
=
ssl
.
SSLContext
(
ssl
.
PROTOCOL_SSLv23
)
sock
=
context
.
wrap_socket
(
conn
,
server_hostname
=
v
)
cert
=
ssl
.
DER_cert_to_PEM_cert
(
sock
.
getpeercert
(
True
))
x509
=
OpenSSL
.
crypto
.
load_certificate
(
OpenSSL
.
crypto
.
FILETYPE_PEM
,
cert
)
not_after
=
x509
.
get_notAfter
().
decode
(
'
ascii
'
)
expires
=
datetime
.
datetime
.
strptime
(
not_after
,
'
%Y%m%d%H%M%SZ
'
)
conn
=
ssl
.
create_connection
((
v
,
443
))
print
(
'
TLS cert for {} expires at {}
'
.
format
(
v
,
expires
.
isoformat
()))
context
=
ssl
.
SSLContext
(
ssl
.
PROTOCOL_SSLv23
)
sock
=
context
.
wrap_socket
(
conn
,
server_hostname
=
v
)
cert
=
ssl
.
DER_cert_to_PEM_cert
(
sock
.
getpeercert
(
True
))
x509
=
OpenSSL
.
crypto
.
load_certificate
(
OpenSSL
.
crypto
.
FILETYPE_PEM
,
cert
)
not_after
=
x509
.
get_notAfter
().
decode
(
'
ascii
'
)
expires
=
datetime
.
datetime
.
strptime
(
not_after
,
'
%Y%m%d%H%M%SZ
'
)
print
(
'
TLS cert for {} expires at {}
'
.
format
(
v
,
expires
.
isoformat
()))
remaining
=
expires
-
datetime
.
datetime
.
utcnow
()
remaining
=
expires
-
datetime
.
datetime
.
utcnow
()
if
remaining
<
datetime
.
timedelta
(
days
=
0
):
if
remaining
<
datetime
.
timedelta
(
days
=
0
):
print
(
'
Error, already expired…
'
)
print
(
'
Error, already expired…
'
)
sys
.
exit
(
1
)
failure
=
True
elif
remaining
<
datetime
.
timedelta
(
days
=
14
):
elif
remaining
<
datetime
.
timedelta
(
days
=
14
):
print
(
'
Warning, will expire soon!
'
)
print
(
'
Warning, will expire soon!
'
)
sys
.
exit
(
3
)
all_ok
=
False
else
:
else
:
print
(
'
Good, enough time before expiration.
'
)
print
(
'
Good, enough time before expiration.
'
)
try
:
url
=
'
https://%s
'
%
v
url
=
'
https://%s
'
%
v
print
(
'
Checking TLS certificate of %s
'
%
url
)
print
(
'
Checking TLS certificate of %s
'
%
url
)
requests
.
get
(
url
)
requests
.
get
(
url
)
except
requests
.
exceptions
.
SSLError
:
except
requests
.
exceptions
.
SSLError
:
print
(
'
%sTLS certificate for %s is not valid%s
'
%
(
YELLOW
,
url
,
DEF
))
print
(
'
%sTLS certificate for %s is not valid%s
'
%
(
YELLOW
,
url
,
DEF
))
sys
.
exit
(
3
)
all_ok
=
False
if
failure
:
sys
.
exit
(
1
)
if
not
all_ok
:
sys
.
exit
(
3
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment