Skip to content

Commit 25d7acc

Browse files
committed
Add extensive coverage
1 parent 4655675 commit 25d7acc

File tree

15 files changed

+360
-26
lines changed

15 files changed

+360
-26
lines changed

.coveragerc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ source = cert_chain_resolver
55
[paths]
66
source =
77
cert_chain_resolver
8-
*/cert_chain_resolver
8+
*/cert_chain_resolver
9+
10+
[report]
11+
include = cert_chain_resolver/*

.github/workflows/ci-cd.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
python -m pip install -r requirements_dev.txt
2222
- name: Test with pytest and coverage
2323
run: |
24-
pytest --cov=./cert_chain_resolver --cov-report term-missing -n auto
24+
pytest --rootdir=. --cov=./cert_chain_resolver --cov-report term-missing -n auto tests/
2525
- name: Upload coverage artifact
2626
if: success()
2727
uses: actions/upload-artifact@v4
@@ -46,7 +46,7 @@ jobs:
4646
python -m pip install -r requirements_dev.txt
4747
- name: Test with pytest and coverage
4848
run: |
49-
pytest --cov=./cert_chain_resolver --cov-report term-missing -n auto
49+
pytest --rootdir=. --cov=./cert_chain_resolver --cov-report term-missing -n auto tests/
5050
- name: Upload coverage artifact
5151
if: success()
5252
uses: actions/upload-artifact@v4
@@ -74,17 +74,16 @@ jobs:
7474
pattern: coverage-*
7575
- name: Combine coverage reports
7676
run: |
77-
ls -lashR .
7877
set -x
7978
coverage combine coverage-*/.coverage
8079
coverage report
81-
coverage xml -o combined_coverage.xml
80+
coverage xml -o ./coverage.xml
8281
8382
coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
8483
- name: Upload coverage to Codecov
8584
uses: codecov/codecov-action@v4
8685
with:
87-
file: ./combined_coverage.xml
86+
file: ./coverage.xml
8887
token: ${{ secrets.CODECOV_TOKEN }}
8988
mypy:
9089
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.3.1
4+
5+
* is_issued_by now raises MissingCertProperty if no hash algorithm found. Before it would silently return False
6+
37
## 1.3.0
48

59
New feature and sane defaults. for the CLI the root is now by default excluded, at first it would include it if it found one, but not all certificate authorities provide a link to their root in their certs. This resulted in sometimes a root to be included and othertimes not.

cert_chain_resolver/castore/base_store.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
try:
66
from typing import TYPE_CHECKING
77

8-
if TYPE_CHECKING:
8+
if TYPE_CHECKING: # pragma: no cover
99
from cert_chain_resolver.models import Cert
10-
except ImportError:
10+
except ImportError: # pragma: no cover
11+
1112
pass
1213

1314

cert_chain_resolver/castore/file_system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
try:
1414
from typing import TYPE_CHECKING
1515

16-
if TYPE_CHECKING:
16+
if TYPE_CHECKING: # pragma: no cover
1717
from cert_chain_resolver.models import Cert
18-
except ImportError:
18+
except ImportError: # pragma: no cover
1919
pass
2020

2121

cert_chain_resolver/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
try:
1010
from typing import Optional
1111
from cert_chain_resolver.castore.base_store import CAStore
12-
except ImportError:
12+
except ImportError: # pragma: no cover
1313
pass
1414

1515

@@ -133,5 +133,5 @@ def main():
133133
cli(**cli_args)
134134

135135

136-
if __name__ == "__main__":
136+
if __name__ == "__main__": # pragma: no cover
137137
main()

cert_chain_resolver/models.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
88
from cryptography.hazmat.primitives.asymmetric.ec import ECDSA, EllipticCurvePublicKey
99
from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15
10+
from cryptography.exceptions import InvalidSignature
1011

1112

1213
import binascii
@@ -15,9 +16,9 @@
1516
try:
1617
from typing import List, Union, Optional, Type, Iterator, TYPE_CHECKING
1718

18-
if TYPE_CHECKING:
19+
if TYPE_CHECKING: # pragma: no cover
1920
import datetime
20-
except ImportError:
21+
except ImportError: # pragma: no cover
2122
pass
2223

2324
try:
@@ -44,13 +45,8 @@ def __init__(self, x509_obj):
4445

4546
def __repr__(self):
4647
# type: () -> str
47-
try:
48-
common_name = self.common_name
49-
except MissingCertProperty:
50-
common_name = None
51-
5248
return '<Cert common_name="{0}" subject="{1}" issuer="{2}">'.format(
53-
common_name, self.subject, self.issuer
49+
self.common_name, self.subject, self.issuer
5450
)
5551

5652
def __eq__(self, other):
@@ -209,7 +205,7 @@ def is_issued_by(self, other):
209205
ECDSA(hash_algorithm),
210206
)
211207
return True
212-
except Exception:
208+
except InvalidSignature as e:
213209
pass
214210

215211
return False

cert_chain_resolver/resolver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
try:
1616
from typing import Any, Optional
1717
from cert_chain_resolver.castore.base_store import CAStore
18-
except ImportError:
18+
except ImportError: # pragma: no cover
1919
pass
2020

2121

cert_chain_resolver/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
try:
66
from typing import TYPE_CHECKING
77

8-
if TYPE_CHECKING:
8+
if TYPE_CHECKING: # pragma: no cover
99
from cert_chain_resolver.models import Cert
1010

11-
except ImportError:
11+
except ImportError: # pragma: no cover
1212
pass
1313

1414

tests/test_api.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from cert_chain_resolver import api
2+
import pytest
3+
from cert_chain_resolver.resolver import resolve
4+
from cert_chain_resolver.models import CertificateChain, Cert
5+
from cert_chain_resolver.castore.file_system import FileSystemStore
6+
7+
8+
@pytest.mark.parametrize(
9+
"exported,obj",
10+
[
11+
("resolve", resolve),
12+
("CertificateChain", CertificateChain),
13+
("Cert", Cert),
14+
("FileSystemStore", FileSystemStore),
15+
],
16+
)
17+
def test_api_exports_right_objects(exported, obj):
18+
assert getattr(api, exported) == obj

0 commit comments

Comments
 (0)