IDE-31: Add unit tests for suspicious brick security warning#5176
Open
harshsomankar123-tech wants to merge 4 commits intoCatrobat:developfrom
Open
Conversation
Member
Author
|
@wslany could you please review this when you have time? |
catroid/src/test/java/org/catrobat/catroid/test/ui/SuspiciousBricksDetectionTest.kt
Fixed
Show fixed
Hide fixed
Contributor
There was a problem hiding this comment.
Pull request overview
Adds new unit tests to prevent regressions in “suspicious bricks” security warning detection (CATROID-681 / IDE-31), focusing on Sprite.getListAllBricks() traversal and the private suspicious-brick detection helpers in ProjectUtils.kt.
Changes:
- Adds
GetListAllBricksTestcoverage for flattening across the currently-handled composite brick types. - Adds
SuspiciousBricksDetectionTestcoverage for suspicious combinations and project-wide aggregation across scripts/sprites/scenes (via reflection on private helpers).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
catroid/src/test/java/org/catrobat/catroid/test/ui/SuspiciousBricksDetectionTest.kt |
Adds unit/integration-style tests for suspicious-bricks detection and project-level warning decision (via reflection). |
catroid/src/test/java/org/catrobat/catroid/test/ui/GetListAllBricksTest.kt |
Adds tests validating getListAllBricks() behavior across supported composite bricks and some nesting scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
catroid/src/test/java/org/catrobat/catroid/test/ui/GetListAllBricksTest.kt
Outdated
Show resolved
Hide resolved
catroid/src/test/java/org/catrobat/catroid/test/ui/GetListAllBricksTest.kt
Outdated
Show resolved
Hide resolved
catroid/src/test/java/org/catrobat/catroid/test/ui/SuspiciousBricksDetectionTest.kt
Outdated
Show resolved
Hide resolved
catroid/src/test/java/org/catrobat/catroid/test/ui/SuspiciousBricksDetectionTest.kt
Show resolved
Hide resolved
catroid/src/test/java/org/catrobat/catroid/test/ui/SuspiciousBricksDetectionTest.kt
Fixed
Show fixed
Hide fixed
|
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.



Description
JIRA: https://catrobat.atlassian.net/browse/IDE-31
This PR introduces comprehensive automated test coverage for the "suspicious bricks" security warning feature (CATROID-681), which alerts users when a downloaded project contains potentially dangerous combinations of voice-listening (
StartListeningBrick) and web-access bricks (WebRequestBrick,BackgroundRequestBrick, orLookRequestBrick).Context & Problem: The existing detection logic in
ProjectUtils.kt(getListAllBricks()) relies on a manualwhenblock to traverse composite bricks. This architectural fragility previously caused regressions where suspicious bricks nested inside control structures went undetected, compromising the privacy warning.Solution & Implementation:
Added 36 unit tests following standard JUnit/Kotlin assertion patterns to prevent future regressions:
GetListAllBricksTest.kt(13 tests): Verifies thatgetListAllBricks()correctly flattens and traverses all 9 composite brick types (e.g.,ForeverBrick,IfLogicBeginBrick,RepeatBrick), including deep nesting scenarios like loops within if-statements.SuspiciousBricksDetectionTest.kt(23 tests): * Unit Level: Verifies all suspicious combinations and ensures no false positives occur (e.g., voice listening without web access).Note: The tests utilize Java reflection to verify private core detection functions (
containsSuspiciousBricksandshouldDisplaySuspiciousBricksWarning) without compromising production encapsulation.StaticSingletonInitializeris used for correct environment setup.Checklist for this pull request
Please review the contributing guidelines and wiki pages of this repository.