Example #1
0
class CleanupTest(unittest.TestCase):
    """Tests for cleanup() method."""
    def setUp(self):
        from letsencrypt.client.standalone_authenticator import \
            StandaloneAuthenticator
        self.authenticator = StandaloneAuthenticator()
        self.achall = achallenges.DVSNI(
            chall=challenges.DVSNI(r="whee", nonce="foononce"),
            domain="foo.example.com", key="key")
        self.authenticator.tasks = {self.achall.nonce_domain: "stuff"}
        self.authenticator.child_pid = 12345

    @mock.patch("letsencrypt.client.standalone_authenticator.os.kill")
    @mock.patch("letsencrypt.client.standalone_authenticator.time.sleep")
    def test_cleanup(self, mock_sleep, mock_kill):
        mock_sleep.return_value = None
        mock_kill.return_value = None

        self.authenticator.cleanup([self.achall])

        mock_kill.assert_called_once_with(12345, signal.SIGINT)
        mock_sleep.assert_called_once_with(1)

    def test_bad_cleanup(self):
        self.assertRaises(
            ValueError, self.authenticator.cleanup, [achallenges.DVSNI(
                chall=challenges.DVSNI(r="whee", nonce="badnonce"),
                domain="bad.example.com", key="key")])
class CleanupTest(unittest.TestCase):
    """Tests for cleanup() method."""
    def setUp(self):
        from letsencrypt.client.standalone_authenticator import \
            StandaloneAuthenticator
        self.authenticator = StandaloneAuthenticator()
        self.authenticator.tasks = {"foononce.acme.invalid": "stuff"}
        self.authenticator.child_pid = 12345

    @mock.patch("letsencrypt.client.standalone_authenticator.os.kill")
    @mock.patch("letsencrypt.client.standalone_authenticator.time.sleep")
    def test_cleanup(self, mock_sleep, mock_kill):
        mock_sleep.return_value = None
        mock_kill.return_value = None
        chall = challenge_util.DvsniChall("foo.example.com", "whee",
                                          "foononce", "key")
        self.authenticator.cleanup([chall])
        mock_kill.assert_called_once_with(12345, signal.SIGINT)
        mock_sleep.assert_called_once_with(1)

    def test_bad_cleanup(self):
        chall = challenge_util.DvsniChall("bad.example.com", "whee",
                                          "badnonce", "key")
        self.assertRaises(ValueError, self.authenticator.cleanup, [chall])