test: cover EmailToken and TokenService signature method behaviors - #8092
Open
maia-andre wants to merge 1 commit into
Open
test: cover EmailToken and TokenService signature method behaviors#8092maia-andre wants to merge 1 commit into
maia-andre wants to merge 1 commit into
Conversation
Infection reported 1 escaped mutant in lib/Service/IdentifyMethod/SignatureMethod/TokenService.php: removing the twofactorGatewayService->ensureAvailable() call in sendCodeByGateway() went unnoticed because no scenario exercised an unavailable gateway. Besides that, sendCodeByEmail() had no direct test, and EmailToken's requestCode() and validateToSign() were untested (EmailTokenTest only covered toArray()). Add a scenario with the Two-Factor Gateway app disabled (killing the MethodCallRemoval mutant), a direct test for sendCodeByEmail(), tests for EmailToken::requestCode() covering both display-name branches, and validateToSign() scenarios (valid code, wrong code, and code sent without being requested). Also fix the testVaidateEmail typo. Covered Code MSI for these two files is now 100% (29/29 mutants detected). Ref LibreSign#8053 Assisted-by: Claude Code:claude-fable-5 Signed-off-by: André Maia <andrefnkmm@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ref: #8053
📝 Summary
Two closely related source/test pairs from #8053 (as claimed on the issue):
lib/Service/IdentifyMethod/SignatureMethod/TokenService.phplib/Service/IdentifyMethod/SignatureMethod/EmailToken.phpInfection baseline for the two files: 23 mutants generated, 1 escaped, Covered Code MSI 95%. The escaped mutant is the
MethodCallRemovalof$this->twofactorGatewayService->ensureAvailable($gatewayName)insendCodeByGateway()— no scenario exercised an unavailable gateway. One correction to my claim comment:sendCodeByEmail(),requestCode()andvalidateToSign()did have indirect coverage from elsewhere in the unit suite; what was missing were direct tests pinning their observable behavior, plus the escaped kill.This PR only adds tests — no production code changes:
testSendCodeByGatewayThrowsWhenGatewayAppIsNotEnabled: kills the escaped mutant. With the call in place,ensureAvailable()throwsLibresignException("App Two-Factor Gateway is not enabled."); with the call removed, execution reachesisGatewayComplete()and throwsOCSForbiddenExceptioninstead, so the expected exception class/message pins the guard.testSendCodeByEmailSendsCodeAndReturnsHashedCode: direct test asserting code generation (TOKEN_LENGTH, digits), delivery viaMailService::sendCodeToSign()and the hashed return value.EmailToken::requestCode(): both display-name branches (distinct name is forwarded; name equal to the identifier is sent as an empty string), asserting the hashed code is persisted viaIdentifyService::save().EmailToken::validateToSign(): valid code passes; wrong code throwsInvalid code.; a code sent without ever being requested also throws.testVaidateEmail→testValidateEmail(and its data provider); removed a dead mock assignment insetUp().After the change, Infection reports 29 mutants generated, 0 escaped, 0 uncovered — Covered Code MSI 100% for this scope (17 killed by tests, 12 detected via fatal errors).
🧪 How to test
Expected: tests green; 29 mutants generated, 0 escaped, Covered Code MSI 100%.
⚙️ API / Back‑end changes
Test-only change; no production code, capabilities, or API documentation affected.
✅ Checklist
php-cs-fixerpass for the changed files.🤖 AI (if applicable)