fix(sonarqube): handle missing service_key_1 in test_product_connection#14412
Open
samiat4911 wants to merge 2 commits intoDefectDojo:devfrom
Open
fix(sonarqube): handle missing service_key_1 in test_product_connection#14412samiat4911 wants to merge 2 commits intoDefectDojo:devfrom
samiat4911 wants to merge 2 commits intoDefectDojo:devfrom
Conversation
valentijnscholten
approved these changes
Feb 28, 2026
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
This PR addresses a severe defect in the SonarQube API client where the connection test sequence crashes under specific UI configurations.
The Issue (Bug):
When a user attempts to configure a SonarQube API scan via the UI, the "Service key 1" parameter is presented as optional. However, if this field is left blank (passing
Noneto the backend), thetest_product_connectionmethod withinapi_client.pyblindly passes thisNonevalue to the SonarQube API'sget_projectmethod. Because the SonarQube API strictly requires thecomponentparameter for connection tests, it responds with a fatal400 Bad Requesterror:{"errors":[{"msg":"The 'component' parameter is missing"}]}Root Cause & Architecture:
Upon reviewing the broader
api_sonarqubemodule, it became evident that the data ingestion methods (import_issuesandimport_hotspotsinimporter.py) were architected correctly to handle this edge case. They implement a robust validation check: ifservice_key_1is absent, they gracefully fall back to utilizingfind_project(product.name). Thetest_product_connectionmethod lacked parity with this design pattern, causing the failure during the initial configuration test sequence.The Solution:
I have refactored the
test_product_connectionmethod to mirror the established fallback architecture found in the importer logic. The connection test now evaluates the presence ofservice_key_1; if present, it strictly queries by that key viaget_project(). If absent, it safely falls back to a broad search utilizingfind_project(product.name), completely resolving the400 Bad Requestcondition.Visual Evidence (Code Changes)
Before / After in
api_client.py:Test results
flake8and passes all localrufflinting processes.get_project()whenservice_key_1is fully hydrated.find_project(product.name)whenservice_key_1evaluates toNone.find_project(product.name)whenservice_key_1resolves to an empty string ("").organizationparameter (service_key_2) is faithfully appended to the outbound request in all routing conditions.Documentation
No documentation updates are necessary. This commit implements a behavioral patch to existing infrastructure without altering public interfaces or introducing novel capabilities.
Checklist
This checklist is for your information.
dev.dev.bugfixbranch.