def setUp(self):
        from letsencrypt.revoker import Cert
        self.cert0 = Cert(test_util.vector_path("cert.pem"))
        self.cert1 = Cert(test_util.vector_path("cert-san.pem"))

        self.certs = [self.cert0, self.cert1]

        zope.component.provideUtility(display_util.FileDisplay(sys.stdout))
示例#2
0
 def _make_test_renewal_conf(self, testfile):
     with open(test_util.vector_path(testfile)) as src:
         # put the correct path for cert.pem, chain.pem etc in the renewal conf
         renewal_conf = src.read().replace("MAGICDIR", test_util.vector_path())
     rd = os.path.join(self.config_dir, "renewal")
     if not os.path.exists(rd):
         os.makedirs(rd)
     rc = os.path.join(rd, "sample-renewal.conf")
     with open(rc, "w") as dest:
         dest.write(renewal_conf)
     return rc
示例#3
0
def create_revoker_certs():
    """Create a few revoker.Cert objects."""
    cert0_path = test_util.vector_path("cert.pem")
    cert1_path = test_util.vector_path("cert-san.pem")
    key_path = test_util.vector_path("rsa512_key.pem")

    from letsencrypt.revoker import Cert
    cert0 = Cert(cert0_path)
    cert1 = Cert(cert1_path)

    return [cert0_path, cert1_path], [cert0, cert1], key_path
示例#4
0
 def _make_test_renewal_conf(self, testfile):
     with open(test_util.vector_path(testfile)) as src:
         # put the correct path for cert.pem, chain.pem etc in the renewal conf
         renewal_conf = src.read().replace("MAGICDIR", test_util.vector_path())
     rd = os.path.join(self.config_dir, "renewal")
     if not os.path.exists(rd):
         os.makedirs(rd)
     rc = os.path.join(rd, "sample-renewal.conf")
     with open(rc, "w") as dest:
         dest.write(renewal_conf)
     return rc
示例#5
0
 def test_renew_verb(self):
     with open(test_util.vector_path('sample-renewal.conf')) as src:
         # put the correct path for cert.pem, chain.pem etc in the renewal conf
         renewal_conf = src.read().replace("MAGICDIR", test_util.vector_path())
     rd = os.path.join(self.config_dir, "renewal")
     if not os.path.exists(rd):
         os.makedirs(rd)
     rc = os.path.join(rd, "sample-renewal.conf")
     with open(rc, "w") as dest:
         dest.write(renewal_conf)
     args = ["renew", "--dry-run", "-tvv"]
     self._test_renewal_common(True, [], args=args, renew=True)
示例#6
0
 def test_renewal_verb(self):
     with open(test_util.vector_path('sample-renewal.conf')) as src:
         # put the correct path for cert.pem, chain.pem etc in the renewal conf
         renewal_conf = src.read().replace("MAGICDIR",
                                           test_util.vector_path())
     rd = os.path.join(self.config_dir, "renewal")
     os.makedirs(rd)
     rc = os.path.join(rd, "sample-renewal.conf")
     with open(rc, "w") as dest:
         dest.write(renewal_conf)
     args = ["renew", "--dry-run", "-tvv"]
     self._test_renewal_common(True, [], args=args, renew=True)
示例#7
0
    def test_revoke_by_wrong_key(self, mock_display, mock_acme):
        mock_display().confirm_revocation.return_value = True

        key_path = test_util.vector_path("rsa256_key.pem")

        wrong_key = le_util.Key(key_path, open(key_path).read())
        self.revoker.revoke_from_key(wrong_key)

        # Nothing was removed
        self.assertEqual(len(self._get_rows()), 2)
        # No revocation went through
        self.assertEqual(mock_acme.call_count, 0)
示例#8
0
    def test_parse_webroot(self):
        parse = self._get_argument_parser()
        webroot_args = [
            '--webroot', '-w', '/var/www/example', '-d',
            'example.com,www.example.com', '-w', '/var/www/superfluous', '-d',
            'superfluo.us', '-d', 'www.superfluo.us'
        ]
        namespace = parse(webroot_args)
        self.assertEqual(
            namespace.webroot_map, {
                'example.com': '/var/www/example',
                'www.example.com': '/var/www/example',
                'www.superfluo.us': '/var/www/superfluous',
                'superfluo.us': '/var/www/superfluous'
            })

        webroot_args = ['-d', 'stray.example.com'] + webroot_args
        self.assertRaises(errors.Error, parse, webroot_args)

        simple_map = '{"eg.com" : "/tmp"}'
        expected_map = {"eg.com": "/tmp"}
        self._webroot_map_test(simple_map, None, None, expected_map,
                               ["eg.com"])

        # test merging webroot maps from the cli and a webroot map
        expected_map["eg2.com"] = "/tmp2"
        domains = ["eg.com", "eg2.com"]
        self._webroot_map_test(simple_map, "/tmp2", "eg2.com,eg.com",
                               expected_map, domains)

        # test inclusion of interactively specified domains in the webroot map
        with mock.patch(
                'letsencrypt.cli.display_ops.choose_names') as mock_choose:
            mock_choose.return_value = domains
            expected_map["eg2.com"] = "/tmp"
            self._webroot_map_test(None, "/tmp", None, expected_map, domains)

        extra_args = ['-c', test_util.vector_path('webrootconftest.ini')]
        self._webroot_map_test(None, None, None, expected_map, domains,
                               extra_args)

        webroot_map_args = [
            '--webroot-map',
            '{"eg.com.,www.eg.com": "/tmp", "eg.is.": "/tmp2"}'
        ]
        namespace = parse(webroot_map_args)
        self.assertEqual(namespace.webroot_map, {
            "eg.com": "/tmp",
            "www.eg.com": "/tmp",
            "eg.is": "/tmp2"
        })
示例#9
0
    def test_parse_webroot(self):
        parse = self._get_argument_parser()
        webroot_args = [
            "--webroot",
            "-w",
            "/var/www/example",
            "-d",
            "example.com,www.example.com",
            "-w",
            "/var/www/superfluous",
            "-d",
            "superfluo.us",
            "-d",
            "www.superfluo.us",
        ]
        namespace = parse(webroot_args)
        self.assertEqual(
            namespace.webroot_map,
            {
                "example.com": "/var/www/example",
                "www.example.com": "/var/www/example",
                "www.superfluo.us": "/var/www/superfluous",
                "superfluo.us": "/var/www/superfluous",
            },
        )

        webroot_args = ["-d", "stray.example.com"] + webroot_args
        self.assertRaises(errors.Error, parse, webroot_args)

        simple_map = '{"eg.com" : "/tmp"}'
        expected_map = {"eg.com": "/tmp"}
        self._webroot_map_test(simple_map, None, None, expected_map, ["eg.com"])

        # test merging webroot maps from the cli and a webroot map
        expected_map["eg2.com"] = "/tmp2"
        domains = ["eg.com", "eg2.com"]
        self._webroot_map_test(simple_map, "/tmp2", "eg2.com,eg.com", expected_map, domains)

        # test inclusion of interactively specified domains in the webroot map
        with mock.patch("letsencrypt.cli.display_ops.choose_names") as mock_choose:
            mock_choose.return_value = domains
            expected_map["eg2.com"] = "/tmp"
            self._webroot_map_test(None, "/tmp", None, expected_map, domains)

        extra_args = ["-c", test_util.vector_path("webrootconftest.ini")]
        self._webroot_map_test(None, None, None, expected_map, domains, extra_args)

        webroot_map_args = ["--webroot-map", '{"eg.com.,www.eg.com": "/tmp", "eg.is.": "/tmp2"}']
        namespace = parse(webroot_map_args)
        self.assertEqual(namespace.webroot_map, {"eg.com": "/tmp", "www.eg.com": "/tmp", "eg.is": "/tmp2"})
示例#10
0
    def test_parse_webroot(self):
        plugins = disco.PluginsRegistry.find_all()
        webroot_args = ['--webroot', '-w', '/var/www/example',
            '-d', 'example.com,www.example.com', '-w', '/var/www/superfluous',
            '-d', 'superfluo.us', '-d', 'www.superfluo.us.']
        namespace = cli.prepare_and_parse_args(plugins, webroot_args)
        self.assertEqual(namespace.webroot_map, {
            'example.com': '/var/www/example',
            'www.example.com': '/var/www/example',
            'www.superfluo.us': '/var/www/superfluous',
            'superfluo.us': '/var/www/superfluous'})

        webroot_args = ['-d', 'stray.example.com'] + webroot_args
        self.assertRaises(errors.Error, cli.prepare_and_parse_args, plugins, webroot_args)

        simple_map = '{"eg.com" : "/tmp"}'
        expected_map = {"eg.com": "/tmp"}
        self._webroot_map_test(simple_map, None, None, expected_map, ["eg.com"])

        # test merging webroot maps from the cli and a webroot map
        expected_map["eg2.com"] = "/tmp2"
        domains = ["eg.com", "eg2.com"]
        self._webroot_map_test(simple_map, "/tmp2", "eg2.com,eg.com", expected_map, domains)

        # test inclusion of interactively specified domains in the webroot map
        with mock.patch('letsencrypt.cli.display_ops.choose_names') as mock_choose:
            mock_choose.return_value = domains
            expected_map["eg2.com"] = "/tmp"
            self._webroot_map_test(None, "/tmp", None, expected_map, domains)

        extra_args = ['-c', test_util.vector_path('webrootconftest.ini')]
        self._webroot_map_test(None, None, None, expected_map, domains, extra_args)

        webroot_map_args = ['--webroot-map',
                            '{"eg.com.,www.eg.com": "/tmp", "eg.is.": "/tmp2"}']
        namespace = cli.prepare_and_parse_args(plugins, webroot_map_args)
        self.assertEqual(namespace.webroot_map,
                         {"eg.com": "/tmp", "www.eg.com": "/tmp", "eg.is": "/tmp2"})
示例#11
0
import StringIO
import traceback
import tempfile
import unittest

import mock

from letsencrypt import account
from letsencrypt import configuration
from letsencrypt import errors

from letsencrypt.tests import renewer_test
from letsencrypt.tests import test_util


CSR = test_util.vector_path('csr.der')


class CLITest(unittest.TestCase):
    """Tests for different commands."""

    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        self.config_dir = os.path.join(self.tmp_dir, 'config')
        self.work_dir = os.path.join(self.tmp_dir, 'work')
        self.logs_dir = os.path.join(self.tmp_dir, 'logs')

    def tearDown(self):
        shutil.rmtree(self.tmp_dir)

    def _call(self, args):
示例#12
0
import traceback
import tempfile
import unittest

import mock

from letsencrypt import account
from letsencrypt import configuration
from letsencrypt import errors

from letsencrypt.plugins import disco

from letsencrypt.tests import renewer_test
from letsencrypt.tests import test_util

CSR = test_util.vector_path('csr.der')


class CLITest(unittest.TestCase):
    """Tests for different commands."""
    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        self.config_dir = os.path.join(self.tmp_dir, 'config')
        self.work_dir = os.path.join(self.tmp_dir, 'work')
        self.logs_dir = os.path.join(self.tmp_dir, 'logs')

    def tearDown(self):
        shutil.rmtree(self.tmp_dir)

    def _call(self, args):
        from letsencrypt import cli
示例#13
0
import tempfile
import unittest

import mock

from letsencrypt import account
from letsencrypt import configuration
from letsencrypt import errors

from letsencrypt.plugins import disco

from letsencrypt.tests import renewer_test
from letsencrypt.tests import test_util


CSR = test_util.vector_path("csr.der")


class CLITest(unittest.TestCase):
    """Tests for different commands."""

    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        self.config_dir = os.path.join(self.tmp_dir, "config")
        self.work_dir = os.path.join(self.tmp_dir, "work")
        self.logs_dir = os.path.join(self.tmp_dir, "logs")

    def tearDown(self):
        shutil.rmtree(self.tmp_dir)

    def _call(self, args):
示例#14
0
from letsencrypt import account
from letsencrypt import cli
from letsencrypt import configuration
from letsencrypt import constants
from letsencrypt import crypto_util
from letsencrypt import errors
from letsencrypt import le_util

from letsencrypt.plugins import disco
from letsencrypt.plugins import manual

from letsencrypt.tests import renewer_test
from letsencrypt.tests import test_util


CERT = test_util.vector_path('cert.pem')
CSR = test_util.vector_path('csr.der')
KEY = test_util.vector_path('rsa256_key.pem')


class CLITest(unittest.TestCase):  # pylint: disable=too-many-public-methods
    """Tests for different commands."""

    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        self.config_dir = os.path.join(self.tmp_dir, 'config')
        self.work_dir = os.path.join(self.tmp_dir, 'work')
        self.logs_dir = os.path.join(self.tmp_dir, 'logs')
        self.standard_args = ['--config-dir', self.config_dir,
                              '--work-dir', self.work_dir,
                              '--logs-dir', self.logs_dir, '--text']
示例#15
0
from letsencrypt import account
from letsencrypt import cli
from letsencrypt import configuration
from letsencrypt import crypto_util
from letsencrypt import errors
from letsencrypt import le_util

from letsencrypt.plugins import disco
from letsencrypt.plugins import manual

from letsencrypt.tests import renewer_test
from letsencrypt.tests import test_util


CERT = test_util.vector_path("cert.pem")
CSR = test_util.vector_path("csr.der")
KEY = test_util.vector_path("rsa256_key.pem")


class CLITest(unittest.TestCase):  # pylint: disable=too-many-public-methods
    """Tests for different commands."""

    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        self.config_dir = os.path.join(self.tmp_dir, "config")
        self.work_dir = os.path.join(self.tmp_dir, "work")
        self.logs_dir = os.path.join(self.tmp_dir, "logs")
        self.standard_args = [
            "--text",
            "--config-dir",
示例#16
0
 def test_agree_dev_preview_config(self):
     with MockedVerb('run') as mocked_run:
         self._call(['-c', test_util.vector_path('cli.ini')])
     self.assertTrue(mocked_run.called)
示例#17
0
 def test_agree_dev_preview_config(self):
     with mock.patch('letsencrypt.main.run') as mocked_run:
         self._call(['-c', test_util.vector_path('cli.ini')])
     self.assertTrue(mocked_run.called)
示例#18
0
 def test_agree_dev_preview_config(self):
     with MockedVerb("run") as mocked_run:
         self._call(["-c", test_util.vector_path("cli.ini")])
     self.assertTrue(mocked_run.called)
import tempfile
import unittest

import mock

from acme import challenges
from acme import jose
from acme import messages

from letsencrypt import achallenges
from letsencrypt import proof_of_possession
from letsencrypt.display import util as display_util

from letsencrypt.tests import test_util

CERT0_PATH = test_util.vector_path("cert.der")
CERT2_PATH = test_util.vector_path("dsa_cert.pem")
CERT2_KEY_PATH = test_util.vector_path("dsa512_key.pem")
CERT3_PATH = test_util.vector_path("matching_cert.pem")
CERT3_KEY_PATH = test_util.vector_path("rsa512_key_2.pem")
CERT3_KEY = test_util.load_rsa_private_key("rsa512_key_2.pem").public_key()


class ProofOfPossessionTest(unittest.TestCase):
    def setUp(self):
        self.installer = mock.MagicMock()
        self.cert1_path = tempfile.mkstemp()[1]
        certs = [CERT0_PATH, self.cert1_path, CERT2_PATH, CERT3_PATH]
        keys = [None, None, CERT2_KEY_PATH, CERT3_KEY_PATH]
        self.installer.get_all_certs_keys.return_value = zip(
            certs, keys, 4 * [None])
示例#20
0
import logging
import shutil
import tempfile
import unittest

import OpenSSL
import mock
import zope.component

from letsencrypt import errors
from letsencrypt import interfaces
from letsencrypt.tests import test_util

RSA256_KEY = test_util.load_vector('rsa256_key.pem')
RSA512_KEY = test_util.load_vector('rsa512_key.pem')
CERT_PATH = test_util.vector_path('cert.pem')
CERT = test_util.load_vector('cert.pem')
SAN_CERT = test_util.load_vector('cert-san.pem')


class InitSaveKeyTest(unittest.TestCase):
    """Tests for letsencrypt.crypto_util.init_save_key."""
    def setUp(self):
        logging.disable(logging.CRITICAL)
        zope.component.provideUtility(mock.Mock(strict_permissions=True),
                                      interfaces.IConfig)
        self.key_dir = tempfile.mkdtemp('key_dir')

    def tearDown(self):
        logging.disable(logging.NOTSET)
        shutil.rmtree(self.key_dir)
 def setUp(self):
     from letsencrypt.revoker import Cert
     self.cert = Cert(test_util.vector_path("cert.pem"))
示例#22
0
from letsencrypt import account
from letsencrypt import cli
from letsencrypt import configuration
from letsencrypt import constants
from letsencrypt import crypto_util
from letsencrypt import errors
from letsencrypt import le_util

from letsencrypt.plugins import disco
from letsencrypt.plugins import manual

from letsencrypt.tests import renewer_test
from letsencrypt.tests import test_util

CERT = test_util.vector_path('cert.pem')
CSR = test_util.vector_path('csr.der')
KEY = test_util.vector_path('rsa256_key.pem')


class CLITest(unittest.TestCase):  # pylint: disable=too-many-public-methods
    """Tests for different commands."""
    def setUp(self):
        self.tmp_dir = tempfile.mkdtemp()
        self.config_dir = os.path.join(self.tmp_dir, 'config')
        self.work_dir = os.path.join(self.tmp_dir, 'work')
        self.logs_dir = os.path.join(self.tmp_dir, 'logs')
        self.standard_args = [
            '--config-dir', self.config_dir, '--work-dir', self.work_dir,
            '--logs-dir', self.logs_dir, '--text'
        ]
import shutil
import tempfile
import unittest

import OpenSSL
import mock
import zope.component

from letsencrypt import errors
from letsencrypt import interfaces
from letsencrypt.tests import test_util


RSA256_KEY = test_util.load_vector('rsa256_key.pem')
RSA512_KEY = test_util.load_vector('rsa512_key.pem')
CERT_PATH = test_util.vector_path('cert.pem')
CERT = test_util.load_vector('cert.pem')
SAN_CERT = test_util.load_vector('cert-san.pem')


class InitSaveKeyTest(unittest.TestCase):
    """Tests for letsencrypt.crypto_util.init_save_key."""
    def setUp(self):
        logging.disable(logging.CRITICAL)
        zope.component.provideUtility(
            mock.Mock(strict_permissions=True), interfaces.IConfig)
        self.key_dir = tempfile.mkdtemp('key_dir')

    def tearDown(self):
        logging.disable(logging.NOTSET)
        shutil.rmtree(self.key_dir)
import unittest

import mock

from acme import challenges
from acme import jose
from acme import messages

from letsencrypt import achallenges
from letsencrypt import proof_of_possession
from letsencrypt.display import util as display_util

from letsencrypt.tests import test_util


CERT0_PATH = test_util.vector_path("cert.der")
CERT2_PATH = test_util.vector_path("dsa_cert.pem")
CERT2_KEY_PATH = test_util.vector_path("dsa512_key.pem")
CERT3_PATH = test_util.vector_path("matching_cert.pem")
CERT3_KEY_PATH = test_util.vector_path("rsa512_key_2.pem")
CERT3_KEY = test_util.load_rsa_private_key("rsa512_key_2.pem").public_key()


class ProofOfPossessionTest(unittest.TestCase):
    def setUp(self):
        self.installer = mock.MagicMock()
        self.cert1_path = tempfile.mkstemp()[1]
        certs = [CERT0_PATH, self.cert1_path, CERT2_PATH, CERT3_PATH]
        keys = [None, None, CERT2_KEY_PATH, CERT3_KEY_PATH]
        self.installer.get_all_certs_keys.return_value = zip(
            certs, keys, 4 * [None])
示例#25
0
 def test_agree_dev_preview_config(self):
     with MockedVerb('run') as mocked_run:
         self._call(['-c', test_util.vector_path('cli.ini')])
     self.assertTrue(mocked_run.called)
示例#26
0
 def test_agree_dev_preview_config(self):
     with mock.patch('letsencrypt.main.run') as mocked_run:
         self._call(['-c', test_util.vector_path('cli.ini')])
     self.assertTrue(mocked_run.called)