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

WIP: add tests that operate at the API level #1097

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

bhearsum
Copy link
Contributor

@bhearsum bhearsum commented Dec 3, 2024

This is inspired by recent frustrations of surprise behaviour by signingscript, and feeling like the current test-every-tiny-little-function-independently tests wouldn't allow for any sort of confident refactoring. These new tests that I'm adding use the same entry point that scriptworker calls into: async_main, and they mock out as little as they possible can. Currently, this is calls to Autograph, and verify_mar_signature, but there will probably be other things mocked out (eg: anything that depends on a signature from a real certificate will need to be mocked).

Running just these new tests alone already achieves 35% coverage overall, and 27% coverage of sign.py:

tests/test_script.py::test_gpg_signing[autograph_gpg] PASSED                                                                                                                                [ 25%]
tests/test_script.py::test_gpg_signing[stage_autograph_gpg] PASSED                                                                                                                          [ 50%]
tests/test_script.py::test_mar_signing[autograph_hash_only_mar384] cPASSED                                                                                                                   [ 75%]
tests/test_script.py::test_mar_signing[stage_autograph_hash_only_mar384] PASSED                                                                                                             [100%]

---------- coverage: platform linux, python 3.11.6-final-0 -----------
Name                              Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------------------------------
src/signingscript/__init__.py         0      0      0      0   100%
src/signingscript/exceptions.py      11      3      0      0    73%   17, 30, 43
src/signingscript/rcodesign.py       71     58     28      0    13%   25-51, 62-69, 82-90, 99-112, 121-132, 143-152
src/signingscript/script.py          72     29     34      7    55%   32, 34, 37-38, 41-43, 55, 57, 71-74, 112-130, 135-137
src/signingscript/sign.py           863    594    222     14    27%   159-161, 182-184, 202-207, 225-235, 255-269, 294-316, 341-373, 393-407, 430-444, 465-488, 495-500, 508-524, 530-539, 545-562, 568-577, 583-596, 602, 623-630, 637-655, 661-663, 669-687, 693-703, 708-712, 718-721, 727-741, 747-751, 756-763, 769-783, 823-857, 867, 919, 934, 936, 938, 946-948, 952->956, 958-963, 966-969, 975-988, 1014, 1027, 1029, 1054-1063, 1135-1145, 1164-1176, 1192-1200, 1245, 1285-1301, 1324-1332, 1354-1367, 1373-1374, 1393-1468, 1493-1515, 1526-1551, 1558-1559, 1564-1582, 1593-1606, 1611-1619, 1628-1650, 1661-1668, 1677-1681, 1690-1768
src/signingscript/task.py            82     11     36     10    82%   83, 131->130, 134, 157-158, 171, 177, 239, 243, 247, 250, 253
src/signingscript/utils.py           95     33     18      3    59%   63-67, 80-81, 101-104, 132, 143-148, 174-177, 192-203, 229, 243
-----------------------------------------------------------------------------
TOTAL                              1194    728    338     34    35%

This number will obviously go up as I add tests for other signing types.

We need this to easily allow dev and fake-prod scriptworkers to opt into testing against Autograph stage. Rather than duplicating all of the formats, we add some simple fallback to the non-stage_ version when selecting signing function. (Note that we must pass through the original format to allow `get_autograph_config` to find the correct server configuration deeper down the stack.)
These variants don't necessarily use the same certs as the autograph prod versions, but they are similar enough that they allow us to verify that Autograph works from a functional point of view.
Copy link
Contributor

@ahal ahal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this stack looks great to me!

return True
if fmt.startswith("autograph_xpi"):
if fmt.startswith(("autograph_xpi", "stage_autograph_xpi")):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, how did I not know that startswith could take a tuple?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither did I until a few days ago 😆

@bhearsum
Copy link
Contributor Author

bhearsum commented Dec 3, 2024

augh, sorry, I just realized this has a whole bunch of stuff from #1085. I'm going to rebase.

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.

2 participants