bug: reject non-positive amounts in deposit/withdraw/transfer - #299
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
bug: reject non-positive amounts in deposit/withdraw/transfer#299devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
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.
Summary
AccountService.withdrawonly guarded against insufficient funds, never against a negative amount.balance.compareTo(-1000000) < 0is false for any non-negative balance, so the guard passed andbalance.subtract(negative)increased the balance — an authenticated user could mint unlimited funds viaPOST /withdraw?amount=-1000000(and then spend them through legitimate transfers).depositandtransferAmounthad the same missing validation; a negative transfer would pull money out of the recipient's account.Fix: a single
validateAmountguard runs before any balance mutation in all three service methods.RuntimeExceptionmatches the existing convention in this service/controller pair.BankController.deposithad notry/catch(unlike withdraw/transfer), so a rejected amount would have surfaced as a 500 — it now renders the dashboard with theerrorattribute like the other two endpoints.New
AccountServiceTestis a plain Mockito unit test (no Spring context — the existingBankappApplicationTestsrequires a real MySQL) covering negative/zero/null rejection with balance unchanged and no repository interaction, plus the happy paths.Note: this environment has no cached Maven artifacts and Maven Central is unreachable from it, so
./mvnw compile/testcould not be run locally; CI is authoritative.Written by Devin
Devin-Org: engineering