# Path: tests/whitebox/integration/_keyutils.py
# class RandomKeyTmpFile:
#     """
#     Generate a random passphrase and put it in a temporary file.
#     """
# 
#     # pylint: disable=consider-using-with
#     def __init__(self, key_bytes=32):
#         """
#         Initializer
# 
#         :param int key_bytes: the desired length of the key in bytes
#         """
#         self._tmpfile = NamedTemporaryFile("wb")
#         with open("/dev/urandom", "rb") as random:
#             random_bytes = random.read(key_bytes)
#             self._tmpfile.write(random_bytes)
#             self._tmpfile.flush()
# 
#     def tmpfile_name(self):
#         """
#         Get the name of the temporary file.
#         """
#         return self._tmpfile.name
# 
#     def close(self):
#         """
#         Close and delete the temporary file.
#         """
#         self._tmpfile.close()
# 
#     def __enter__(self):
#         """
#         For use with the "with" keyword.
# 
#         :return str: the path of the file with the random key
#         """
#         return self._tmpfile.name
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         try:
#             self._tmpfile.close()
#         except Exception as error:
#             if exc_value is None:
#                 raise error
# 
#             raise error from exc_value


from stratis_cli import StratisCliErrorCodes
from stratis_cli._errors import (
    StratisCliEngineError,
    StratisCliNoChangeError,
    StratisCliResourceNotFoundError,
)
from .._keyutils import RandomKeyTmpFile
from .._misc import RUNNER, TEST_RUNNER, SimTestCase
        with RandomKeyTmpFile() as fname:
            command_line = self._MENU + [self._KEYNAME, "--keyfile-path", fname]
            TEST_RUNNER(command_line)

    def test_reset_no_change(self):
        """
        Resetting to the same passphrase should fail.
        """
        command_line = self._MENU + [
            self._KEYNAME,
            "--keyfile-path",
            self._key_file.tmpfile_name(),
        ]
        self.check_error(StratisCliNoChangeError, command_line, _ERROR)

    def test_reset_does_not_exist(self):
        """
        Resetting a key that does not exist should fail.
        """
        command_line = self._MENU + [
            "notakey",
            "--keyfile-path",
            self._key_file.tmpfile_name(),
        ]
        self.check_error(StratisCliResourceNotFoundError, command_line, _ERROR)

    def test_reset_key_too_long(self):
        """
        Resetting should fail due to the length of the key.
        """

# Path: tests/whitebox/integration/_keyutils.py
# class RandomKeyTmpFile:
#     """
#     Generate a random passphrase and put it in a temporary file.
#     """
# 
#     # pylint: disable=consider-using-with
#     def __init__(self, key_bytes=32):
#         """
#         Initializer
# 
#         :param int key_bytes: the desired length of the key in bytes
#         """
#         self._tmpfile = NamedTemporaryFile("wb")
#         with open("/dev/urandom", "rb") as random:
#             random_bytes = random.read(key_bytes)
#             self._tmpfile.write(random_bytes)
#             self._tmpfile.flush()
# 
#     def tmpfile_name(self):
#         """
#         Get the name of the temporary file.
#         """
#         return self._tmpfile.name
# 
#     def close(self):
#         """
#         Close and delete the temporary file.
#         """
#         self._tmpfile.close()
# 
#     def __enter__(self):
#         """
#         For use with the "with" keyword.
# 
#         :return str: the path of the file with the random key
#         """
#         return self._tmpfile.name
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         try:
#             self._tmpfile.close()
#         except Exception as error:
#             if exc_value is None:
#                 raise error
# 
#             raise error from exc_value


# Path: tests/whitebox/integration/key/test_reset.py
from stratis_cli import StratisCliErrorCodes
from stratis_cli._errors import (
    StratisCliEngineError,
    StratisCliNoChangeError,
    StratisCliResourceNotFoundError,
)
from .._keyutils import RandomKeyTmpFile
from .._misc import RUNNER, TEST_RUNNER, SimTestCase

        with RandomKeyTmpFile() as fname:
            command_line = self._MENU + [self._KEYNAME, "--keyfile-path", fname]
            TEST_RUNNER(command_line)

    def test_reset_no_change(self):
        """
        Resetting to the same passphrase should fail.
        """
        command_line = self._MENU + [
            self._KEYNAME,
            "--keyfile-path",
            self._key_file.tmpfile_name(),
        ]
        self.check_error(StratisCliNoChangeError, command_line, _ERROR)

    def test_reset_does_not_exist(self):
        """
        Resetting a key that does not exist should fail.
        """
        command_line = self._MENU + [
            "notakey",
            "--keyfile-path",
            self._key_file.tmpfile_name(),
        ]
        self.check_error(StratisCliResourceNotFoundError, command_line, _ERROR)

    def test_reset_key_too_long(self):
        """
        Resetting should fail due to the length of the key.
        """

        with RandomKeyTmpFile(128) as fname: