Skip to content

Commit

Permalink
Merge PR #3128 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Dec 12, 2024
2 parents 6e7e03d + e135e52 commit ff5f5b9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
8 changes: 8 additions & 0 deletions letsencrypt/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px
:target: https://github.com/hbrunn
:alt: hbrunn

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-hbrunn|

This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/16.0/letsencrypt>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions letsencrypt/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"category": "Tools",
"summary": "Request SSL certificates from letsencrypt.org",
"depends": ["base"],
"maintainers": ["hbrunn"],
"data": [
"data/ir_config_parameter.xml",
"data/ir_cron.xml",
Expand Down
13 changes: 6 additions & 7 deletions letsencrypt/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +274,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -535,12 +534,12 @@ <h2><a class="toc-backref" href="#toc-entry-11">Icon</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-12">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/hbrunn"><img alt="hbrunn" src="https://github.com/hbrunn.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/16.0/letsencrypt">OCA/server-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion letsencrypt/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import test_http

# from . import test_letsencrypt # Commented due to hammering exception
from . import test_letsencrypt
52 changes: 48 additions & 4 deletions letsencrypt/tests/test_letsencrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
from odoo.tests.common import Form
from odoo.tools.misc import mute_logger

from ..models.letsencrypt import _get_challenge_dir, _get_data_dir
from ..models.letsencrypt import (
TYPE_CHALLENGE_DNS,
TYPE_CHALLENGE_HTTP,
_get_challenge_dir,
_get_data_dir,
)

CERT_DIR = path.join(path.dirname(__file__), "certs")

Expand All @@ -25,6 +30,34 @@ def _poll(order, deadline):
return order_resource


def _new_order_dns(csr_pem):
challenge = mock.Mock()
challenge.chall.typ = TYPE_CHALLENGE_DNS
challenge.validation = mock.Mock(return_value="")

authorizations = mock.Mock()
authorizations.body.challenges = [challenge]
authorizations.body.identifier.value = "example.ltd"

order_resource = mock.Mock()
order_resource.authorizations = [authorizations]
return order_resource


def _new_order_http(csr_pem):
challenge = mock.Mock()
challenge.chall.typ = TYPE_CHALLENGE_HTTP
challenge.token = b"token"
challenge.validation = mock.Mock(return_value="")

authorizations = mock.Mock()
authorizations.body.challenges = [challenge]

order_resource = mock.Mock()
order_resource.authorizations = [authorizations]
return order_resource


class TestLetsencrypt(SingleTransactionCase):
def setUp(self):
super().setUp()
Expand Down Expand Up @@ -54,8 +87,10 @@ def test_config_settings(self):
).set_values()

@mock.patch("acme.client.ClientV2.answer_challenge")
@mock.patch("acme.client.ClientV2.new_account")
@mock.patch("acme.client.ClientV2.new_order", side_effect=_new_order_http)
@mock.patch("acme.client.ClientV2.poll_and_finalize", side_effect=_poll)
def test_http_challenge(self, poll, _answer_challenge):
def test_http_challenge(self, poll, new_order, new_account, _answer_challenge):
letsencrypt = self.env["letsencrypt"]
self.env["res.config.settings"].create(
{"letsencrypt_altnames": ""}
Expand All @@ -71,8 +106,12 @@ def test_http_challenge(self, poll, _answer_challenge):
@mock.patch("dns.resolver.query")
@mock.patch("time.sleep")
@mock.patch("acme.client.ClientV2.answer_challenge")
@mock.patch("acme.client.ClientV2.new_account")
@mock.patch("acme.client.ClientV2.new_order", side_effect=_new_order_dns)
@mock.patch("acme.client.ClientV2.poll_and_finalize", side_effect=_poll)
def test_dns_challenge(self, poll, answer_challenge, sleep, query, dnsupd):
def test_dns_challenge(
self, poll, new_order, new_account, answer_challenge, sleep, query, dnsupd
):

record = None

Expand Down Expand Up @@ -113,7 +152,12 @@ def query_effect(domain, rectype):
self.assertTrue(path.isfile("/tmp/.letsencrypt_test"))
self.assertTrue(path.isfile(path.join(_get_data_dir(), "www.example.ltd.crt")))

def test_dns_challenge_error_on_missing_provider(self):
@mock.patch("acme.client.ClientV2.new_account")
@mock.patch("acme.client.ClientV2.new_order", side_effect=_new_order_dns)
@mock.patch("acme.client.ClientV2.poll_and_finalize", side_effect=_poll)
def test_dns_challenge_error_on_missing_provider(
self, poll, new_order, new_account
):
self.env["res.config.settings"].create(
{
"letsencrypt_altnames": "*.example.ltd",
Expand Down

0 comments on commit ff5f5b9

Please sign in to comment.