Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2 basic unit tests #137

Closed
wants to merge 2 commits into from
Closed

Conversation

bnavigator
Copy link
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
Contributor Author

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

@mcepl
Copy link

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
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
Contributor Author

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

@bnavigator
Copy link
Contributor Author

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

It's highly openSUSE specific

@mcepl
Copy link

mcepl commented Nov 25, 2020

I have slightly improved version of the test script.

test_certifi.py

@alex
Copy link
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

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
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