def setUp(self): from certbot.plugins.script import Authenticator self.auth_return_value = "return from auth\n" self.script_nonexec = create_script(b'# empty') self.script_exec = create_script_exec(b'echo "return from auth\n"') self.config = mock.MagicMock( script_auth=self.script_exec, script_cleanup=self.script_exec, pref_challs=[ challenges.Challenge.TYPES["http-01"], challenges.Challenge.TYPES["dns-01"], challenges.Challenge.TYPES["tls-sni-01"] ]) self.tlssni_config = mock.MagicMock( script_auth=self.script_exec, script_cleanup=self.script_exec, pref_challs=[challenges.Challenge.TYPES["tls-sni-01"]]) self.nochall_config = mock.MagicMock( script_auth=self.script_exec, script_cleanup=self.script_exec, ) self.default = Authenticator(config=self.config, name="script") self.onlytlssni = Authenticator(config=self.tlssni_config, name="script") self.nochall = Authenticator(config=self.nochall_config, name="script") self.http01 = achallenges.KeyAuthorizationAnnotatedChallenge( challb=acme_util.HTTP01_P, domain="foo.com", account_key=KEY) self.dns01 = achallenges.KeyAuthorizationAnnotatedChallenge( challb=acme_util.DNS01_P, domain="foo.com", account_key=KEY) self.achalls = [self.http01, self.dns01]
def test_prepare_normal(self): """Test prepare with typical configuration""" from certbot.plugins.script import Authenticator # Erroring combinations in from of (auth_script, cleanup_script, error) for v in [("/NONEXISTENT/script.sh", "/NONEXISTENT/script.sh", errors.HookCommandNotFound), (self.script_nonexec, "/NONEXISTENT/script.sh", errors.HookCommandNotFound), (self.script_exec, "/NONEXISTENT/script.sh", errors.HookCommandNotFound), ("/NONEXISTENT/script.sh", self.script_nonexec, errors.HookCommandNotFound), ("/NONEXISTENT/script.sh", self.script_exec, errors.HookCommandNotFound), (None, self.script_exec, errors.PluginError)]: testconf = mock.MagicMock( script_auth=v[0], script_cleanup=v[1], pref_challs=[challenges.Challenge.TYPES["http-01"]]) testauth = Authenticator(config=testconf, name="script") self.assertRaises(v[2], testauth.prepare) # This should not error self.default.prepare() self.assertEqual(len(self.default.challenges), 2)