Repository navigation
test(utils): add extension-fallback UT for isMimeTypeSupport (PMS-383607) - #765
Conversation
…607) Add 3 GTest cases covering the extension-based MIME fallback branch introduced in commit 0a0fdfe: - IsMimeTypeSupport_PatchFile_ExtensionFallback_ReturnsTrue: git format-patch .patch file content-detected as application/mbox falls back to extension (text/x-patch) and is accepted - IsMimeTypeSupport_BinaryUnknownExt_ExtensionDefaultGuarded_ReturnsFalse: binary file with unknown extension (.zzz) rejected by isDefault() guard - IsMimeTypeSupport_PngFile_NonTextExtension_ReturnsFalse: .png file with PNG content rejected — extension MIME is non-default but non-text and not in whitelist PMS: BUG-383607 Log: 补充 isMimeTypeSupport 扩展名回退分支的单元测试 Influence: 仅新增测试用例,不改业务逻辑
|
Skipping CI for Draft Pull Request. |
Reviewer's GuideTestsAdd three tests for extension-based MIME fallback outcomes and update the test inventory to reflect the eight covered scenarios.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/common/test_utils.cpp" line_range="708" />
<code_context>
+ const bool result = Utils::isMimeTypeSupport(path);
+
+ // Assert:扩展名回退 → text/x-patch(text/ 前缀)→ 放行
+ EXPECT_TRUE(result);
+}
+
</code_context>
<issue_to_address>
**Fallback regression goes unnoticed**
When the Qt MIME database classifies the patch fixture's content as a supported MIME type, `Utils::isMimeTypeSupport` returns true at the content-MIME check before reaching the extension fallback, so `EXPECT_TRUE(result)` passes even when that fallback is broken and the test reports the behavior as covered.
Use a fixture whose content MIME is unsupported so the assertion can pass only through the extension fallback.
</issue_to_address>
### Comment 2
<location path="tests/common/test_utils.cpp" line_range="708" />
<code_context>
+ const bool result = Utils::isMimeTypeSupport(path);
+
+ // Assert:扩展名回退 → text/x-patch(text/ 前缀)→ 放行
+ EXPECT_TRUE(result);
+}
+
</code_context>
<issue_to_address>
**Whitelist fallback remains untested**
When an extension resolves to a whitelisted MIME type that does not start with `text/`, a regression that removes the `SupportedTextMimeTypes` alternative still passes all eight MIME tests, leaving fallback for whitelisted non-`text/` extension MIME types broken.
Add a fallback test for an unsupported content MIME paired with a whitelisted, non-`text/` extension MIME type.
</issue_to_address>| const bool result = Utils::isMimeTypeSupport(path); | ||
|
|
||
| // Assert:扩展名回退 → text/x-patch(text/ 前缀)→ 放行 | ||
| EXPECT_TRUE(result); |
There was a problem hiding this comment.
🟡 Medium · Fallback regression goes unnoticed
When the Qt MIME database classifies the patch fixture's content as a supported MIME type, Utils::isMimeTypeSupport returns true at the content-MIME check before reaching the extension fallback, so EXPECT_TRUE(result) passes even when that fallback is broken and the test reports the behavior as covered.
Use a fixture whose content MIME is unsupported so the assertion can pass only through the extension fallback.
Prompt for AI agents
In `tests/common/test_utils.cpp` at line 708:
**Fallback regression goes unnoticed**
When the Qt MIME database classifies the patch fixture's content as a supported MIME type, `Utils::isMimeTypeSupport` returns true at the content-MIME check before reaching the extension fallback, so `EXPECT_TRUE(result)` passes even when that fallback is broken and the test reports the behavior as covered.
Use a fixture whose content MIME is unsupported so the assertion can pass only through the extension fallback.| const bool result = Utils::isMimeTypeSupport(path); | ||
|
|
||
| // Assert:扩展名回退 → text/x-patch(text/ 前缀)→ 放行 | ||
| EXPECT_TRUE(result); |
There was a problem hiding this comment.
🟡 Medium · Whitelist fallback remains untested
When an extension resolves to a whitelisted MIME type that does not start with text/, a regression that removes the SupportedTextMimeTypes alternative still passes all eight MIME tests, leaving fallback for whitelisted non-text/ extension MIME types broken.
Add a fallback test for an unsupported content MIME paired with a whitelisted, non-text/ extension MIME type.
Prompt for AI agents
In `tests/common/test_utils.cpp` at line 708:
**Whitelist fallback remains untested**
When an extension resolves to a whitelisted MIME type that does not start with `text/`, a regression that removes the `SupportedTextMimeTypes` alternative still passes all eight MIME tests, leaving fallback for whitelisted non-`text/` extension MIME types broken.
Add a fallback test for an unsupported content MIME paired with a whitelisted, non-`text/` extension MIME type.
Add 3 GTest cases for the extension-based MIME fallback branch (commit 0a0fdfe, PMS BUG-383607).
New tests:
All 8 isMimeTypeSupport tests pass (5 existing + 3 new), no regression.
PMS: BUG-383607
Summary by Sourcery
Tests: