certbot.tests.util module¶
Test utilities.
- class certbot.tests.util.DummyInstaller(*args: Any, **kwargs: Any)[source]¶
Bases:
Installer
Dummy installer plugin for test purpose.
- get_all_names() Iterable[str] [source]¶
Returns all names that may be authenticated.
- Return type:
collections.Iterable
ofstr
- deploy_cert(domain: str, cert_path: str, key_path: str, chain_path: str, fullchain_path: str) None [source]¶
Deploy certificate.
- Parameters:
domain (str) – domain to deploy certificate file
cert_path (str) – absolute path to the certificate file
key_path (str) – absolute path to the private key file
chain_path (str) – absolute path to the certificate chain file
fullchain_path (str) – absolute path to the certificate fullchain file (cert plus chain)
- Raises:
.PluginError – when cert cannot be deployed
- enhance(domain: str, enhancement: str, options: Optional[Union[List[str], str]] = None) None [source]¶
Perform a configuration enhancement.
- Parameters:
domain (str) – domain for which to provide enhancement
enhancement (str) – An enhancement as defined in
ENHANCEMENTS
options – Flexible options parameter for enhancement. Check documentation of
ENHANCEMENTS
for expected options for each enhancement.
- Raises:
.PluginError – If Enhancement is not supported, or if an error occurs during the enhancement.
- supported_enhancements() List[str] [source]¶
Returns a
collections.Iterable
of supported enhancements.- Returns:
supported enhancements which should be a subset of
ENHANCEMENTS
- Return type:
collections.Iterable
ofstr
- save(title: Optional[str] = None, temporary: bool = False) None [source]¶
Saves all changes to the configuration files.
Both title and temporary are needed because a save may be intended to be permanent, but the save is not ready to be a full checkpoint.
It is assumed that at most one checkpoint is finalized by this method. Additionally, if an exception is raised, it is assumed a new checkpoint was not finalized.
- Parameters:
title (str) – The title of the save. If a title is given, the configuration will be saved as a new checkpoint and put in a timestamped directory.
title
has no effect if temporary is true.temporary (bool) – Indicates whether the changes made will be quickly reversed in the future (challenges)
- Raises:
.PluginError – when save is unsuccessful
- config_test() None [source]¶
Make sure the configuration is valid.
- Raises:
.MisconfigurationError – when the config is not in a usable state
- restart() None [source]¶
Restart or refresh the server content.
- Raises:
.PluginError – when server cannot be restarted
- classmethod add_parser_arguments(add: Callable[[...], None]) None [source]¶
Add plugin arguments to the CLI argument parser.
- Parameters:
add (callable) – Function that proxies calls to
argparse.ArgumentParser.add_argument
prepending options with unique plugin name prefix.
- prepare() None [source]¶
Prepare the plugin.
Finish up any additional initialization.
- Raises:
.PluginError – when full initialization cannot be completed.
.MisconfigurationError – when full initialization cannot be completed. Plugin will be displayed on a list of available plugins.
.NoInstallationError – when the necessary programs/files cannot be located. Plugin will NOT be displayed on a list of available plugins.
.NotSupportedError – when the installation is recognized, but the version is not currently supported.
- certbot.tests.util.load_comparable_csr(*names: str) ComparableX509 [source]¶
Load ComparableX509 certificate request.
- certbot.tests.util.load_rsa_private_key(*names: str) ComparableRSAKey [source]¶
Load RSA private key.
- certbot.tests.util.load_pyopenssl_private_key(*names: str) PKey [source]¶
Load pyOpenSSL private key.
- certbot.tests.util.make_lineage(config_dir: str, testfile: str, ec: bool = True) str [source]¶
Creates a lineage defined by testfile.
This creates the archive, live, and renewal directories if necessary and creates a simple lineage.
- Parameters:
config_dir (str) – path to the configuration directory
testfile (str) – configuration file to base the lineage on
ec (bool) – True if we generate the lineage with an ECDSA key
- Returns:
path to the renewal conf file for the created lineage
- Return type:
str
- certbot.tests.util.patch_display_util() MagicMock [source]¶
Patch certbot.display.util to use a special mock display utility.
The mock display utility works like a regular mock object, except it also also asserts that methods are called with valid arguments.
The mock created by this patch mocks out Certbot internals. That is, the mock object will be called by the certbot.display.util functions and the mock returned by that call will be used as the display utility. This was done to simplify the transition from zope.component and mocking certbot.display.util functions directly in test code should be preferred over using this function in the future.
See https://github.com/certbot/certbot/issues/8948
- Returns:
patch on the function used internally by certbot.display.util to get a display utility instance
- Return type:
mock.MagicMock
- certbot.tests.util.patch_display_util_with_stdout(stdout: Optional[IO] = None) MagicMock [source]¶
Patch certbot.display.util to use a special mock display utility.
The mock display utility works like a regular mock object, except it also asserts that methods are called with valid arguments.
The mock created by this patch mocks out Certbot internals. That is, the mock object will be called by the certbot.display.util functions and the mock returned by that call will be used as the display utility. This was done to simplify the transition from zope.component and mocking certbot.display.util functions directly in test code should be preferred over using this function in the future.
See https://github.com/certbot/certbot/issues/8948
The
message
argument passed to the display utility methods is passed to stdout’s write method.- Parameters:
stdout (object) – object to write standard output to; it is expected to have a
write
method- Returns:
patch on the function used internally by certbot.display.util to get a display utility instance
- Return type:
mock.MagicMock
- class certbot.tests.util.FreezableMock(frozen: bool = False, func: Optional[Callable[[...], Any]] = None, return_value: Any = sentinel.DEFAULT)[source]¶
Bases:
object
Mock object with the ability to freeze attributes.
This class works like a regular mock.MagicMock object, except attributes and behavior set before the object is frozen cannot be changed during tests.
If a func argument is provided to the constructor, this function is called first when an instance of FreezableMock is called, followed by the usual behavior defined by MagicMock. The return value of func is ignored.
- class certbot.tests.util.TempDirTestCase(methodName='runTest')[source]¶
Bases:
TestCase
Base test class which sets up and tears down a temporary directory
- class certbot.tests.util.ConfigTestCase(methodName='runTest')[source]¶
Bases:
TempDirTestCase
Test class which sets up a NamespaceConfig object.
- certbot.tests.util.lock_and_call(callback: Callable[[], Any], path_to_lock: str) None [source]¶
Grab a lock on path_to_lock from a foreign process then execute the callback. :param callable callback: object to call after acquiring the lock :param str path_to_lock: path to file or directory to lock