Repository navigation
[Fix-17813][ApiServer][Part1] Treat the mask value echoed back by the frontend as an unmodified password when updating or testing the connection - #18737
Conversation
|
@ruanwenjun @SbloodyS |
|
Please add e2e test case. |
… when testing the connection
Hi @ruanwenjun, thanks for the review. I've added an e2e test case in d0d81aa:
|
| - name: PostgresDataSourceE2ETest | ||
| class: org.apache.dolphinscheduler.e2e.cases.PostgresDataSourceE2ETest | ||
| - name: PostgresDataSourceEditE2ETest | ||
| class: org.apache.dolphinscheduler.e2e.cases.PostgresDataSourceEditE2ETest |
There was a problem hiding this comment.
It's best to add verification of success and failure of modification in existing test cases.
There was a problem hiding this comment.
It's best to add verification of success and failure of modification in existing test cases.
Hi @SbloodyS, thanks for the review.
I folded the two edit checks into the existing PostgresDataSourceE2ETest (67739ea) and removed the separate class and its matrix entry. Success is verified explicitly (the first edit's connection test only succeeds against the stored password), and the failure path is locked implicitly: the second edit re-opens the form and asserts the connection test still succeeds — if the previous save had persisted the mask, it would necessarily fail. The e2e UI exposes no failure signal (a failed connection is silent), so an explicit failure case isn't assertable; the two rounds cover it.
Was this PR generated or assisted by AI?
Yes, generate test cases by AI
Purpose of the pull request
Fix part of #17813 (the password-overwrite half; also reported by #18004).
The query APIs (
queryDataSource,queryDataSourceListPaging) always return the password masked asConstants.XXXXXX(******). The edit form echoes this value back unchanged on save, and on devupdateDataSourceonly treats a blankpassword as "not updated" — so the literal mask gets stored as the real password:
That is exactly the #18004 failure mode on dev: edit a datasource, save without touching the password, and the stored password is silently overwritten; SQL tasks on that datasource stop connecting afterwards.
Brief change log
DataSourceServiceImpl#updateDataSource: "password not updated" now meansblank OR equals the mask value returned by the query APIs, reusing the existing old-password backfill branch.The comparison happens on the raw DTO value (
dataSourceParam.getPassword()) beforebuildConnectionParams, so it also holds whenDATASOURCE_ENCRYPTION_ENABLEis on (the connection param carries the Base64-encoded password in that case — comparing there would silently break).The mask reference is the same one the query APIs use to mask, so the guard and the read path can never drift apart.
No config switch: this value can only originate from our own echo and never deserves to be written as a password. Semantically this extends the existing "blank keeps the old password" rule from {blank} to {blank, mask}; the only
input lost is setting the password to a literal
******, the same class as the existing "cannot set an empty password".POST /datasources/connect (new DataSourceService#checkConnection overload): when the request targets an existing datasource (id present) and the password echoes the mask value, the connectivity check runs against the credentials already stored for that datasource instead of the mask value — the same rule applied to the other path that receives the echoed edit form.
Resolving the stored password requires read access to sensitive fields, so the fallback goes through the same permission check as connectionTest (RESOURCE_NOT_EXIST / USER_NO_OPERATION_PERM on failure).
Creating a datasource (no id in the form) is unaffected: the submitted password is used as-is.
Verify this pull request
Added 4 contract tests to
DataSourceServiceTest, each asserting the persistedconnectionParams.passwordbyte-for-byte:******, default config → old stored value kept******,DATASOURCE_ENCRYPTION_ENABLE=true→ old stored value kept(guards the compare-on-raw-DTO decision; comparing on the encoded connection
param differs in exactly this case)
Added 5 tests to DataSourceServiceTest for the connection-test path, asserting the credentials handed to the connectivity check byte-for-byte:
DataSourceServiceTest: 23/23 green.
Mutation-checked: removing the backfill turns the edit-with-mask case red (expected: but was: <******>), forcing the fallback on unconditionally turns both non-fallback cases red, and removing the permission check flips the no-permission case to a connection failure.
Pull Request Notice
Pull Request Notice
If your pull request contains incompatible change, you should also add it to
docs/docs/en/guide/upgrade/incompatible.md