Skip to content

Add 2 basic unit tests#137

Closed
bnavigator wants to merge 2 commits intocertifi:masterfrom
bnavigator:unittests
Closed

Add 2 basic unit tests#137
bnavigator wants to merge 2 commits intocertifi:masterfrom
bnavigator:unittests

Conversation

@bnavigator
Copy link
Copy Markdown
Contributor

Closes #136

These tests are very basic. They just check that the returned string is really a file and contains the PEM certificate header.

The workflow runs with pytest, but you could also use native python -m unittest.

Further work could use openssl or the Python module Cryptography to check for valid CA certificates.

@bnavigator
Copy link
Copy Markdown
Contributor Author

See https://github.com/bnavigator/python-certifi/runs/991003207 how this will look like in Github Actions

@mcepl
Copy link
Copy Markdown

mcepl commented Nov 25, 2020

Would you be able to make those tests a little bit more robust, so they would work even with the modified OpenSUSE package? https://build.opensuse.org/package/show/home:mcepl:branches:devel:languages:python/python-certifi

@bnavigator
Copy link
Copy Markdown
Contributor Author

The test fail is legit. If there is no -----BEGIN CERTIFICATE----- in /etc/ssl/ca-bundle.pem, something is wrong:

greiner@greinerT450s:~/src/osc/home:mcepl:branches:devel:languages:python/python-certifi/ > osc shell
abuild@greinerT450s:~> cat /etc/ssl/ca-bundle.pem
#
# automatically created by /usr/lib/ca-certificates/update.d/99certbundle.run. Do not edit!
#
# Use of this file is deprecated and should only be used as last
# resort by applications that do not support p11-kit or reading /etc/ssl/certs.
# You should avoid hardcoding any paths in applications anyways though. Use
# functions that know the operating system defaults instead:
#
# - openssl: SSL_CTX_set_default_verify_paths()
# - gnutls: gnutls_certificate_set_x509_system_trust(cred)
#
abuild@greinerT450s:~> rpm -qf /etc/ssl/ca-bundle.pem
ca-certificates-2+git20201002.34daf7f-1.1.noarch
abuild@greinerT450s:~> logout
greiner@greinerT450s:~/src/osc/home:mcepl:branches:devel:languages:python/python-certifi/ > head -n 15 /etc/ssl/ca-bundle.pem
#
# automatically created by /usr/lib/ca-certificates/update.d/99certbundle.run. Do not edit!
#
# Use of this file is deprecated and should only be used as last
# resort by applications that do not support p11-kit or reading /etc/ssl/certs.
# You should avoid hardcoding any paths in applications anyways though. Use
# functions that know the operating system defaults instead:
#
# - openssl: SSL_CTX_set_default_verify_paths()
# - gnutls: gnutls_certificate_set_x509_system_trust(cred)
#
-----BEGIN CERTIFICATE-----
MIIH0zCCBbugAwIBAgIIXsO3pkN/pOAwDQYJKoZIhvcNAQEFBQAwQjESMBAGA1UE
AwwJQUNDVlJBSVoxMRAwDgYDVQQLDAdQS0lBQ0NWMQ0wCwYDVQQKDARBQ0NWMQsw
CQYDVQQGEwJFUzAeFw0xMTA1MDUwOTM3MzdaFw0zMDEyMzEwOTM3MzdaMEIxEjAQ
greiner@greinerT450s:~/src/osc/home:mcepl:branches:devel:languages:python/python-certifi/ > rpm -qf /etc/ssl/ca-bundle.pem
ca-certificates-2+git20201002.34daf7f-1.1.noarch

@bnavigator
Copy link
Copy Markdown
Contributor Author

Note also the empty /etc/ssl/certs/ in the obs environment.

@bnavigator
Copy link
Copy Markdown
Contributor Author

https://build.opensuse.org/request/show/850705

It's highly openSUSE specific

@mcepl
Copy link
Copy Markdown

mcepl commented Nov 25, 2020

I have slightly improved version of the test script.

test_certifi.py

@alex
Copy link
Copy Markdown
Member

alex commented Nov 25, 2020

@bnavigator Thanks for taking the time to work on this, and sorry we've been slow to review. I'm going to make a branch off your branch and try to get this merged today! Thanks again.

@mcepl
Copy link
Copy Markdown

mcepl commented Nov 25, 2020

@bnavigator Thanks for taking the time to work on this, and sorry we've been slow to review. I'm going to make a branch off your branch and try to get this merged today! Thanks again.

See my version of the test script (don’t bother with the authorship of the patch, I release it to public domain).

@alex alex mentioned this pull request Nov 25, 2020
@alex alex closed this in #140 Nov 25, 2020
@bnavigator
Copy link
Copy Markdown
Contributor Author

Sure, no problem.

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Nov 29, 2020
https://build.opensuse.org/request/show/850940
by user dirkmueller + dimstar_suse
- update to 2020.11.8:
  * Python 3.8+ support

- Add two-basic-unit-tests.patch which includes two at least simple test
  patches (gh#certifi/python-certifi#137).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests

3 participants