Skip to content

fix:code check(remove redundant log)#311

Merged
chilingling merged 1 commit intoopentiny:developfrom
msslulu:fix/codecheck
Apr 30, 2026
Merged

fix:code check(remove redundant log)#311
chilingling merged 1 commit intoopentiny:developfrom
msslulu:fix/codecheck

Conversation

@msslulu
Copy link
Copy Markdown
Contributor

@msslulu msslulu commented Apr 30, 2026

[English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

](fix:code check)

Summary by CodeRabbit

Tests

  • Enhanced test robustness by implementing locale-independent assertions for password utility validation.
  • Removed unnecessary console logging and cleaned up unused code from encryption utility tests.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Walkthrough

Test utility refactoring: removes debug console logging from an encryption test and updates another test to use locale-independent lowercase conversion while removing unused imports and commented-out code.

Changes

Cohort / File(s) Summary
Test Utility Cleanup
base/src/test/java/com/tinyengine/it/login/utils/SM2EncryptionUtilTest.java
Removes debug System.out.println statements for plaintext and ciphertext output while preserving core encryption/decryption assertions.
Test Locale Hardening
base/src/test/java/com/tinyengine/it/login/utils/SM3PasswordUtilTest.java
Updates toLowerCase() to toLowerCase(Locale.ROOT) for deterministic behavior; removes unused KeyPair import and deletes commented-out fixed-vector assertion.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Console logs fade like morning dew,
Locale.ROOT makes tests ring true—
Unused imports bid adieu,
Comments vanish, clean as new!
🌟

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title partially addresses the changeset: it mentions 'remove redundant log' which matches the primary change (removing console.out.println statements), but the prefix 'fix:code check' is vague and does not clearly convey the specific modification. Consider revising to: 'fix: Remove redundant console logging from SM2 and SM3 test utilities' or 'fix: Clean up test logging and improve locale-aware assertions' for clarity.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
base/src/test/java/com/tinyengine/it/login/utils/SM3PasswordUtilTest.java (3)

401-430: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Concurrency test won’t reliably fail: worker thread assertions throw AssertionError (not caught).

In concurrentCreateAndVerify, the thread catches Exception, but assertion failures are AssertionError (extends Error), so they won’t be captured into exceptions[0]. That can make the test “pass” even when assertions fail inside threads.

Catch Throwable (or at least AssertionError), and store it for the main thread to assert on.

Suggested change
 void concurrentCreateAndVerify() throws Exception {
   int threadCount = 10;
   int iterationsPerThread = 100;
-  Exception[] exceptions = new Exception[1];
+  Throwable[] failures = new Throwable[1];
 
   Runnable task = () -> {
     try {
       for (int i = 0; i < iterationsPerThread; i++) {
         String pwd = "pwd" + Thread.currentThread().getId() + "_" + i;
         PasswordResult result = SM3PasswordUtil.createPassword(pwd);
         assertTrue(SM3PasswordUtil.verifyPassword(pwd, result.getPasswordHash(), result.getSalt()));
       }
-    } catch (Exception e) {
-      synchronized (exceptions) {
-        exceptions[0] = e;
+    } catch (Throwable t) {
+      synchronized (failures) {
+        failures[0] = t;
       }
     }
   };
@@
   for (Thread t : threads) {
     t.join();
   }
-  assertNull(exceptions[0], "并发执行时不应抛出异常");
+  assertNull(failures[0], "并发执行时不应抛出异常");
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@base/src/test/java/com/tinyengine/it/login/utils/SM3PasswordUtilTest.java`
around lines 401 - 430, The concurrentCreateAndVerify test currently only
catches Exception in the worker Runnable so AssertionError (and other
Throwables) escape and aren’t reported; change the worker exception handling in
SM3PasswordUtilTest.concurrentCreateAndVerify to catch Throwable (or at minimum
AssertionError) and record it into the shared holder (replace Exception[]
exceptions with an AtomicReference<Throwable> or volatile Throwable) so the main
thread can assert that no throwable occurred after joining threads; ensure you
still synchronize/compare-and-set when writing the shared holder to avoid lost
updates.

150-155: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix misleading test naming: sm3HashWithNullData_ThrowsNullPointerException asserts IllegalArgumentException.

The @DisplayName says it should throw NullPointerException, but the assertion is assertThrows(IllegalArgumentException.class, ...). This is confusing for future maintenance and can hide contract drift.

Either update the display name/method name to match IllegalArgumentException, or adjust the expected exception type to what the implementation actually throws.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@base/src/test/java/com/tinyengine/it/login/utils/SM3PasswordUtilTest.java`
around lines 150 - 155, The test method
sm3HashWithNullData_ThrowsNullPointerException has a mismatched expectation: the
`@DisplayName` says NullPointerException but the assertion expects
IllegalArgumentException; update the test to be consistent by either renaming
the method/@DisplayName to reflect IllegalArgumentException or change the
assertThrows to expect NullPointerException depending on the
SM3PasswordUtil.sm3Hash contract — ensure SM3PasswordUtil.sm3Hash(null, "salt")
is asserted against the actual thrown exception and that method/display name and
message align.

16-19: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Close MockitoAnnotations.openMocks(this) to avoid resource leakage.

MockitoAnnotations.openMocks(this) returns an AutoCloseable that should be closed (typically in an @AfterEach). Otherwise you risk leaks / warnings and non-deterministic behavior across larger test suites.

Suggested change
 class SM3PasswordUtilTest {
+  private AutoCloseable mocks;
 
  `@BeforeEach`
  void setUp() throws Exception {
-   MockitoAnnotations.openMocks(this);
+   mocks = MockitoAnnotations.openMocks(this);
  }
+
+ `@AfterEach`
+ void tearDown() throws Exception {
+   if (mocks != null) {
+     mocks.close();
+   }
+ }
 
  ...
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@base/src/test/java/com/tinyengine/it/login/utils/SM3PasswordUtilTest.java`
around lines 16 - 19, The call to MockitoAnnotations.openMocks(this) in setUp()
returns an AutoCloseable that must be closed to avoid resource leaks; change the
test class to store the returned AutoCloseable (e.g., a private field) when
calling MockitoAnnotations.openMocks(this) in setUp(), and implement an
`@AfterEach` method (e.g., tearDown()) that calls close() on that field (handling
or declaring Exception as needed) to ensure the mocks are properly released;
reference the setUp() method and the new tearDown() method when applying the
change.
🧹 Nitpick comments (1)
base/src/test/java/com/tinyengine/it/login/utils/SM3PasswordUtilTest.java (1)

445-459: ⚡ Quick win

Strengthen sm3ConsistencyWithKnownVectors: add an actual standard expected-hash assertion.

Right now this test only verifies determinism (hash1 == hash2) for input="abc" and salt="". That won’t catch regressions where SM3 is implemented incorrectly but consistently.

Reintroduce the published SM3 known-vector assertion for "abc" (with whatever exact input semantics SM3PasswordUtil.sm3Hash(data, salt) uses when salt=""). If sm3Hash combines salt + data differently than “hash(data)”, the expected value must be adjusted accordingly.

Suggested change
 void sm3ConsistencyWithKnownVectors() throws Exception {
@@
  String input = "abc";
  String salt = "";
  String hash1 = SM3PasswordUtil.sm3Hash(input, salt);
- String hash2 = SM3PasswordUtil.sm3Hash(input, salt);
- assertEquals(hash1, hash2, "相同输入应得到相同哈希");
+ // SM3("abc") known vector (verify SM3PasswordUtil.sm3Hash(salt="", data) semantics match this).
+ String expected = "66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e";
+ assertEquals(expected, hash1, "SM3 known-vector mismatch");
+
+ String hash2 = SM3PasswordUtil.sm3Hash(input, salt);
+ assertEquals(hash1, hash2, "相同输入应得到相同哈希");
 
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@base/src/test/java/com/tinyengine/it/login/utils/SM3PasswordUtilTest.java`
around lines 445 - 459, The test sm3ConsistencyWithKnownVectors currently only
checks determinism; update it to assert against the official SM3 known-vector
for input "abc" by computing expected = "<standard SM3 hex for 'abc' given the
utility's salt semantics>" and replacing or adding assertEquals(expected, hash1)
(use SM3PasswordUtil.sm3Hash("abc", "") as produced); if SM3PasswordUtil.sm3Hash
treats salt as prefix/suffix or empty differently, compute the expected value
accordingly and assert that SM3PasswordUtil.sm3Hash(input, salt) equals that
expected constant to catch implementation regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@base/src/test/java/com/tinyengine/it/login/utils/SM3PasswordUtilTest.java`:
- Around line 401-430: The concurrentCreateAndVerify test currently only catches
Exception in the worker Runnable so AssertionError (and other Throwables) escape
and aren’t reported; change the worker exception handling in
SM3PasswordUtilTest.concurrentCreateAndVerify to catch Throwable (or at minimum
AssertionError) and record it into the shared holder (replace Exception[]
exceptions with an AtomicReference<Throwable> or volatile Throwable) so the main
thread can assert that no throwable occurred after joining threads; ensure you
still synchronize/compare-and-set when writing the shared holder to avoid lost
updates.
- Around line 150-155: The test method
sm3HashWithNullData_ThrowsNullPointerException has a mismatched expectation: the
`@DisplayName` says NullPointerException but the assertion expects
IllegalArgumentException; update the test to be consistent by either renaming
the method/@DisplayName to reflect IllegalArgumentException or change the
assertThrows to expect NullPointerException depending on the
SM3PasswordUtil.sm3Hash contract — ensure SM3PasswordUtil.sm3Hash(null, "salt")
is asserted against the actual thrown exception and that method/display name and
message align.
- Around line 16-19: The call to MockitoAnnotations.openMocks(this) in setUp()
returns an AutoCloseable that must be closed to avoid resource leaks; change the
test class to store the returned AutoCloseable (e.g., a private field) when
calling MockitoAnnotations.openMocks(this) in setUp(), and implement an
`@AfterEach` method (e.g., tearDown()) that calls close() on that field (handling
or declaring Exception as needed) to ensure the mocks are properly released;
reference the setUp() method and the new tearDown() method when applying the
change.

---

Nitpick comments:
In `@base/src/test/java/com/tinyengine/it/login/utils/SM3PasswordUtilTest.java`:
- Around line 445-459: The test sm3ConsistencyWithKnownVectors currently only
checks determinism; update it to assert against the official SM3 known-vector
for input "abc" by computing expected = "<standard SM3 hex for 'abc' given the
utility's salt semantics>" and replacing or adding assertEquals(expected, hash1)
(use SM3PasswordUtil.sm3Hash("abc", "") as produced); if SM3PasswordUtil.sm3Hash
treats salt as prefix/suffix or empty differently, compute the expected value
accordingly and assert that SM3PasswordUtil.sm3Hash(input, salt) equals that
expected constant to catch implementation regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ce5bd56-8ff4-43f0-a9bf-390271e74a5a

📥 Commits

Reviewing files that changed from the base of the PR and between ee9d024 and ae9fa5a.

📒 Files selected for processing (2)
  • base/src/test/java/com/tinyengine/it/login/utils/SM2EncryptionUtilTest.java
  • base/src/test/java/com/tinyengine/it/login/utils/SM3PasswordUtilTest.java
💤 Files with no reviewable changes (1)
  • base/src/test/java/com/tinyengine/it/login/utils/SM2EncryptionUtilTest.java

@chilingling chilingling changed the title fix:code check fix:code check(remove redundant log) Apr 30, 2026
@chilingling chilingling merged commit b7bf798 into opentiny:develop Apr 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants