斯芬克斯Build,带blinkcheck和自定义CA

2024-04-25 12:30:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我们有自己的公司范围的证书颁发机构,我们用它来签署SSL证书。大多数情况下,只要您的操作系统(在我们的例子中是CentOS 7)注册了该权限,这就可以正常工作。它存储在这里:

/etc/pki/ca-trust/source/anchors/company_ca.pem

这允许Firefox/chrome信任通过它签名的SSL证书。你知道吗

我正在使用sphinx-build -W -blinkcheck […]检查Python项目中的链接是否仍然有效,因为文档中的链接腐烂。这对于所有外部链接都很好。你知道吗

然而,当链接到我们自己的SSL版本mantis(bug跟踪器)时,我得到了一个

SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)'),)))

错误。在我们的设置中,Mantis只在https上运行。你知道吗

我该如何告诉斯芬克斯增加公司范围的权力?

我一般是通过毒物来检测的:

运行这个的毒物碎片:

[testenv:docs]
basepython=python2.7
deps=-r{toxinidir}/requirements/requirements.txt
commands=./check_docs.bash

bash脚本:

#!/bin/bash
set -eux
sphinx-apidoc --force --separate --private --module-first -o docs src/ '*/*test*'
cd docs
pytest --maxfail=1 \
    --tb=line \
    -v \
    --junitxml=junit_sphinx.xml \
    --exitfirst \
    --failed-first \
    --full-trace \
    -ra \
    --capture=no \
    check_sphinx.py

还有Python的剧本:

import subprocess


def test_linkcheck(tmpdir):
    doctrees = tmpdir.join("doctrees")
    htmldir = tmpdir.join("html")
    subprocess.check_call([
        "sphinx-build", "-W", "-blinkcheck", "-d",
        str(doctrees), ".",
        str(htmldir)
    ])


def test_build_docs(tmpdir):
    doctrees = tmpdir.join("doctrees")
    htmldir = tmpdir.join("html")
    subprocess.check_call([
        "sphinx-build", "-W", "-bhtml", "-d",
        str(doctrees), ".",
        str(htmldir)
    ])

Tags: testbuildbashssldocs链接checksphinx
1条回答
网友
1楼 · 发布于 2024-04-25 12:30:28

斯芬克斯使用了requests,它使用了certifi,多亏了sraw他在评论中善意地指出了这一点。您可以修改certifi.where()以包含您自己的证书颁发机构。你知道吗

因为您可能会运行tox或重新构建您的虚拟环境,所以手动执行此操作既繁琐又容易出错。固定装置使这更容易处理。你知道吗

Python脚本更改如下。你知道吗

# -*- coding: utf-8 -*-
import subprocess
import certifi
import requests
import pytest

CA = '/etc/pki/ca-trust/source/anchors/company_ca.pem'


@pytest.fixture
def certificate_authority(scope="module"):
    try:
        # Checking connection to Mantis…
        requests.get('https://mantisbt.example.com')
        # Connection to Mantis OK, thus CA should work fine.
    except requests.exceptions.SSLError:
        # SSL Error. Adding custom certs to Certifi store…
        cafile = certifi.where()
        with open(CA, 'rb') as infile:
            customca = infile.read()
        with open(cafile, 'ab') as outfile:
            outfile.write(customca)
        # That might have worked.


def test_linkcheck(certificate_authority, tmpdir):
    doctrees = tmpdir.join("doctrees")
    htmldir = tmpdir.join("html")
    subprocess.check_call([
        "sphinx-build", "-W", "-blinkcheck", "-d",
        str(doctrees), ".",
        str(htmldir)
    ])


def test_build_docs(certificate_authority, tmpdir):
    doctrees = tmpdir.join("doctrees")
    htmldir = tmpdir.join("html")
    subprocess.check_call([
        "sphinx-build", "-W", "-bhtml", "-d",
        str(doctrees), ".",
        str(htmldir)
    ])

相关问题 更多 >