Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Adrien Dorsaz
acme-dns-tiny
Commits
8646a506
Commit
8646a506
authored
May 24, 2020
by
Adrien Dorsaz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: adapt tests "deactivate" and "rollover" to linter
parent
da319857
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
30 deletions
+39
-30
tests/test_acme_account_deactivate.py
tests/test_acme_account_deactivate.py
+19
-14
tests/test_acme_account_rollover.py
tests/test_acme_account_rollover.py
+20
-16
No files found.
tests/test_acme_account_deactivate.py
View file @
8646a506
import
unittest
,
os
,
time
,
configparser
"""Test acme_account_deactivate script with real ACME server"""
import
unittest
import
os
import
configparser
import
acme_dns_tiny
from
tests.config_factory
import
generate_acme_account_deactivate_config
import
tools.acme_account_deactivate
ACMEDirectory
=
os
.
getenv
(
"GITLABCI_ACMEDIRECTORY_V2"
,
"https://acme-staging-v02.api.letsencrypt.org/directory"
)
ACME_DIRECTORY
=
os
.
getenv
(
"GITLABCI_ACMEDIRECTORY_V2"
,
"https://acme-staging-v02.api.letsencrypt.org/directory"
)
class
TestACMEAccountDeactivate
(
unittest
.
TestCase
):
"Tests for acme_account_deactivate"
@
classmethod
def
setUpClass
(
self
):
self
.
configs
=
generate_acme_account_deactivate_config
()
def
setUpClass
(
cls
):
cls
.
configs
=
generate_acme_account_deactivate_config
()
try
:
acme_dns_tiny
.
main
([
self
.
configs
[
'config'
]])
acme_dns_tiny
.
main
([
cls
.
configs
[
'config'
]])
except
ValueError
as
err
:
if
str
(
err
).
startswith
(
"Error register"
):
raise
ValueError
(
"Fail test as account has not been registered correctly: {0}"
.
format
(
err
))
raise
ValueError
(
"Fail test as account has not been registered correctly: {0}"
.
format
(
err
))
super
(
TestACMEAccountDeactivate
,
self
).
setUpClass
()
super
(
TestACMEAccountDeactivate
,
cls
).
setUpClass
()
# To clean ACME staging server and close correctly temporary files
@
classmethod
def
tearDownClass
(
self
):
def
tearDownClass
(
cls
):
# Remove temporary files
parser
=
configparser
.
ConfigParser
()
parser
.
read
(
self
.
configs
[
'config'
])
parser
.
read
(
cls
.
configs
[
'config'
])
try
:
os
.
remove
(
parser
[
"acmednstiny"
][
"AccountKeyFile"
])
os
.
remove
(
parser
[
"acmednstiny"
][
"CSRFile"
])
os
.
remove
(
self
.
configs
[
'config'
])
except
:
os
.
remove
(
cls
.
configs
[
'config'
])
except
:
#pylint: disable=bare-except
pass
super
(
TestACMEAccountDeactivate
,
self
).
tearDownClass
()
super
(
TestACMEAccountDeactivate
,
cls
).
tearDownClass
()
def
test_success_account_deactivate
(
self
):
""" Test success account key deactivate """
with
self
.
assertLogs
(
level
=
'INFO'
)
as
accountdeactivatelog
:
tools
.
acme_account_deactivate
.
main
([
"--account-key"
,
self
.
configs
[
'key'
],
"--acme-directory"
,
ACME
Directory
])
"--acme-directory"
,
ACME
_DIRECTORY
])
self
.
assertIn
(
"INFO:acme_account_deactivate:Account key deactivated !"
,
accountdeactivatelog
.
output
)
accountdeactivatelog
.
output
)
if
__name__
==
"__main__"
:
unittest
.
main
()
tests/test_acme_account_rollover.py
View file @
8646a506
import
unittest
,
os
,
time
,
configparser
"""Test acme_account_rollover script with real ACME server"""
import
unittest
import
os
import
configparser
import
acme_dns_tiny
from
tests.config_factory
import
generate_acme_account_rollover_config
from
tools.acme_account_deactivate
import
account_deactivate
import
tools.acme_account_rollover
ACMEDirectory
=
os
.
getenv
(
"GITLABCI_ACMEDIRECTORY_V2"
,
"https://acme-staging-v02.api.letsencrypt.org/directory"
)
ACME_DIRECTORY
=
os
.
getenv
(
"GITLABCI_ACMEDIRECTORY_V2"
,
"https://acme-staging-v02.api.letsencrypt.org/directory"
)
class
TestACMEAccountRollover
(
unittest
.
TestCase
):
"Tests for acme_account_rollover"
@
classmethod
def
setUpClass
(
self
):
self
.
configs
=
generate_acme_account_rollover_config
()
acme_dns_tiny
.
main
([
self
.
configs
[
'config'
]])
super
(
TestACMEAccountRollover
,
self
).
setUpClass
()
def
setUpClass
(
cls
):
cls
.
configs
=
generate_acme_account_rollover_config
()
acme_dns_tiny
.
main
([
cls
.
configs
[
'config'
]])
super
(
TestACMEAccountRollover
,
cls
).
setUpClass
()
# To clean ACME staging server and close correctly temporary files
@
classmethod
def
tearDownClass
(
self
):
def
tearDownClass
(
cls
):
# deactivate account key registration at end of tests
# (we assume the key has been roll oved)
account_deactivate
(
self
.
configs
[
"newaccountkey"
],
ACME
Directory
)
account_deactivate
(
cls
.
configs
[
"newaccountkey"
],
ACME
_DIRECTORY
)
# Remove temporary files
parser
=
configparser
.
ConfigParser
()
parser
.
read
(
self
.
configs
[
'config'
])
parser
.
read
(
cls
.
configs
[
'config'
])
try
:
os
.
remove
(
parser
[
"acmednstiny"
][
"AccountKeyFile"
])
os
.
remove
(
parser
[
"acmednstiny"
][
"CSRFile"
])
os
.
remove
(
self
.
configs
[
"newaccountkey"
])
os
.
remove
(
self
.
configs
[
'config'
])
except
:
os
.
remove
(
cls
.
configs
[
"newaccountkey"
])
os
.
remove
(
cls
.
configs
[
'config'
])
except
:
#pylint: disable=bare-except
pass
super
(
TestACMEAccountRollover
,
self
).
tearDownClass
()
super
(
TestACMEAccountRollover
,
cls
).
tearDownClass
()
def
test_success_account_rollover
(
self
):
""" Test success account key rollover """
with
self
.
assertLogs
(
level
=
'INFO'
)
as
accountrolloverlog
:
tools
.
acme_account_rollover
.
main
([
"--current"
,
self
.
configs
[
'oldaccountkey'
],
"--new"
,
self
.
configs
[
'newaccountkey'
],
"--acme-directory"
,
ACME
Directory
])
"--new"
,
self
.
configs
[
'newaccountkey'
],
"--acme-directory"
,
ACME
_DIRECTORY
])
self
.
assertIn
(
"INFO:acme_account_rollover:Account keys rolled over !"
,
accountrolloverlog
.
output
)
accountrolloverlog
.
output
)
if
__name__
==
"__main__"
:
unittest
.
main
()
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