fix: resolve MAJOR Sonar bugs in HttpClientAdapter and OasImportConverter#420
fix: resolve MAJOR Sonar bugs in HttpClientAdapter and OasImportConverter#420
Conversation
…rter Phase 1 of the Sonar bug remediation blueprint: resolve all 4 MAJOR bugs reported by the SonarQube quality gate (run #1516, main @ dcfd01c). Fixes: - S2116 (HttpClientAdapter.java:103, 115): Basic and Digest auth read the password as a char[] from the spec, then called .toString() on the array which produced the JVM array identity (e.g. "[C@5a3b7c") instead of the password contents. Every authenticated outbound request was therefore sending a garbage secret. Replace with new String(getPassword()). - S2259 (OasImportConverter.deriveResourceName): the method dereferenced path.replaceAll(...) without a null guard and called slug.startsWith(...) on a slug that could be null. Both inputs are now guarded; the method falls back to "root" instead of throwing NullPointerException. - S5850 (OasImportConverter.toKebabCase): the regex "^-|-$" parses correctly under Java but reads ambiguously to humans. Replace with the explicitly-grouped "(^-)|(-$)" — same behavior, unambiguous intent. Tests: - HttpClientAdapterTest: the existing basic/digest auth tests only asserted assertNotNull(getSecret()), which let the [C@... garbage secret pass review. They now compare the actual secret content against the expected value, with a comment explaining why this assertion strengthening is itself the non-regression test for S2116. - OasImportConverterTest: added deriveResourceNameShouldFallBackToRootWhenPathIsNull (NPE guard) and toKebabCaseShouldTrimLeadingAndTrailingHyphens (regex behavior). Closes #417, #418, #419.
There was a problem hiding this comment.
Pull request overview
This PR addresses MAJOR SonarQube-reported bugs in the HTTP client adapter and OpenAPI import converter, including one runtime-impacting authentication defect where Basic/Digest passwords were incorrectly serialized.
Changes:
- Fix Basic/Digest authentication secret handling by converting
char[]passwords to their actual string contents before Mustache resolution. - Make
OasImportConverter.deriveResourceNamenull-safe with a"root"fallback. - Clarify the hyphen-trimming regex in
toKebabCaseand add regression tests for the above behaviors.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/main/java/io/naftiko/engine/consumes/http/HttpClientAdapter.java | Fixes Basic/Digest password conversion so the resolved secret is the real password content. |
| src/main/java/io/naftiko/spec/openapi/OasImportConverter.java | Adds null fallback in deriveResourceName and clarifies regex grouping in toKebabCase. |
| src/test/java/io/naftiko/engine/consumes/http/HttpClientAdapterTest.java | Strengthens auth assertions to validate secret contents (non-regression for S2116). |
| src/test/java/io/naftiko/spec/openapi/OasImportConverterTest.java | Adds regression tests for null-path fallback and leading/trailing hyphen trimming. |
|
The Tracking this in #421. Verification this is unrelated:
The fixes in this PR touch
|
Related Issue
Closes #417, closes #418, closes #419
What does this PR do?
Phase 1 of the Sonar Bug Remediation blueprint — resolve all 4 MAJOR bugs reported by the SonarQube quality gate (run #1516,
main @ dcfd01c):java:S2116HttpClientAdapter.javagetPassword().toString()withnew String(getPassword())java:S2259OasImportConverter.deriveResourceNamepathandslugagainstnull; fall back to"root"java:S5850OasImportConverter.toKebabCase"^-|-$"with explicitly-grouped"(^-)|(-$)"The
S2116fix is the only one with runtime impact — before this change, every Basic and Digest authenticated outbound HTTP call was sending the JVM array identity (e.g.[C@5a3b7c) as the secret instead of the configured password. The two existing auth tests masked the bug because they only assertedassertNotNull(getSecret()).Tests
HttpClientAdapterTest.basicAuthenticationShouldSetIdentifierAndSecretanddigestAuthenticationShouldSetIdentifierAndSecret: strengthened fromassertNotNull(getSecret())toassertEquals("<expected>", String.valueOf(getSecret())). These strengthened assertions fail onmain(proving the S2116 bug), and pass after the fix. A comment in each test explains why this assertion strengthening is itself the non-regression guard.OasImportConverterTest.deriveResourceNameShouldFallBackToRootWhenPathIsNull(new): verifies the null-path fallback. Fails with NPE before the fix.OasImportConverterTest.toKebabCaseShouldTrimLeadingAndTrailingHyphens(new): verifies the regex still trims both ends. Passes against both old and new regex (S5850 is a code-quality issue, not a behavioral bug); kept as a defensive regression test for the new explicitly-grouped form.Verification
Checklist
mainAgent Context (optional)