Repository navigation
refactor(crl): use typed exception for CRL lock in progress - #9102
Conversation
Replace the RuntimeException message match in CrlRevocationChecker with a CrlGenerationInProgressException, and assert the exception class in tests instead of its message. Refs LibreSign#8117 Signed-off-by: Matheus Andrade <2002matheus@gmail.com>
|
Thanks for opening your first pull request in this repository! ✌️ |
Signed-off-by: Matheus Andrade <2002matheus@gmail.com>
YvesCesar
left a comment
There was a problem hiding this comment.
Many thanks, @matheusa1 !
@vitormattos looks okay to me.
I don't think the errors in the pipelines are related to the PR.
|
Hi @matheusa1, your first pull request to LibreSign has been merged. 🎉 Your work is part of LibreSign now, and everyone who signs a document with it benefits from the time and knowledge you shared. Thank you. You are very welcome to contribute again. The good first issue list is a good place to look next, and you no longer have to wonder how the process works. If you have a few minutes and feel like it, we would love to hear how this went for you: https://ls.librecode.coop/index.php/645932?lang=en&source=github-first-merged-pr&repository=libresign. It is entirely optional; nothing is expected of you in return for contributing. Come say hello in the LibreSign community: https://t.me/LibreSign |
Resolves: part of #8117
📝 Summary
When another process holds the generated-CRL lock,
CrlServicethrew a plain\RuntimeException("CRL %s is already in progress ..."). Both the tests and production code identified that case by its message:CrlRevocationCheckerusedstr_contains($e->getMessage(), 'already in progress')to downgrade it to a debug log.This PR follows the convention agreed in #8117 (prefer typed exceptions, new public exceptions extend
LibresignException):OCA\Libresign\Exception\CrlGenerationInProgressException(extendsLibresignException).CrlServicethrows it instead of\RuntimeException, keeping the same message, so logs are unchanged.CrlRevocationCheckerusesinstanceof CrlGenerationInProgressExceptioninstead of matching the message.CrlServiceTestasserts the exception class instead ofexpectExceptionMessage().CrlRevocationCheckerTestthrows the typed exception, plus a new negative test: an untyped\RuntimeExceptionwhose message mentions "already in progress" is now logged as a warning, not treated as a held lock.All callers of
generateCrlDer()/refreshGeneratedCrlDer()catch\Exception/\Throwable, so moving away from\RuntimeExceptiondoes not change their behavior.🧪 How to test
composer test:unit -- --filter 'CrlServiceTest|CrlRevocationCheckerTest'Validation evidence
CrlServiceTestcases failed before the change and pass after it.php-cs-fixer --dry-runclean on the changed files,php -lOK. Psalm was not run locally (local PHP 8.3.6, Psalm requires >= 8.3.16), so it is left to CI.--filter Crlran 243 tests and all pass exceptCommand\Crl\CleanupTest::testRejectsInvalidPeriodFormat("negative-period"), which fails the same way onmainwithout this change.⚙️ API / Back-end changes
✅ Checklist
🤖 AI (if applicable)