FIX: Disallow Empty robot_name_prefix to prevent OIDC CLI login from being blocked#22556
FIX: Disallow Empty robot_name_prefix to prevent OIDC CLI login from being blocked#22556falconlee236 wants to merge 5 commits intogoharbor:mainfrom
robot_name_prefix to prevent OIDC CLI login from being blocked#22556Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22556 +/- ##
===========================================
+ Coverage 45.36% 66.01% +20.64%
===========================================
Files 244 1074 +830
Lines 13333 116423 +103090
Branches 2719 2937 +218
===========================================
+ Hits 6049 76859 +70810
- Misses 6983 35310 +28327
- Partials 301 4254 +3953
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
bupd
left a comment
There was a problem hiding this comment.
/lgtm
you would also need to update this from the frontend to make sure the ui doesnt give spaces as input. currently it allows robot_prefix with only spaces. this should not be the case.
todo: need to add spaces validation to the frontend.
122ff66 to
fa22397
Compare
|
Hi @bupd, This pattern not allow trailing whitespace. so this PR meets your proposal. And I have one more question. Please Kindly tell to me what i missing steps. Thanks. |
bupd
left a comment
There was a problem hiding this comment.
UI side changes good.
for the backend the prefix should have bit more vaidation that is it should trim spaces so update the handler with trim spaces so it trims the spaces front and back - since this causes issues in robot validation prefix should not contain spaces.
❯ curl -X PUT http://localhost:8080/api/v2.0/configurations \
-u admin:Harbor12345 \
-H "Content-Type: application/json" \
--data '{"robot_name_prefix":" spaces "}' \
--insecure
the above request should not pass.
Once the above requested changes are done, this pr should be ready to be merged.
Thanks for your contribution @falconlee236
|
Added trim logic in Why manager.go?
Now And Please review my PR (#22553). |
| strVal := utils.GetStrValueOfAnyType(value) | ||
|
|
||
| // Trim spaces from the robot_name_prefix before validation | ||
| if key == common.RobotNamePrefix { |
There was a problem hiding this comment.
why this validation in ValidateCfg is needed given NonEmptyStringType already validates?
There was a problem hiding this comment.
add please add ut, like:
func (suite *ValidateCfgTestSuite) TestValidateCfg_RobotNamePrefix_EmptyString() {
cfgs := map[string]any{
common.RobotNamePrefix: "",
}
err := suite.manager.ValidateCfg(suite.ctx, cfgs)
suite.Require().Error(err)
suite.Contains(err.Error(), "empty")
}
There was a problem hiding this comment.
NonEmptyStringType rejects empty/whitespace-only values (e.g., " ").
However, the reviewer also asked to "trim spaces front and back" for valid values. For example:
- Input:
" robot$ " - Without trim: stored as
" robot$ "→ causes robot validation issues - With trim: stored as
"robot$"
So ValidateCfg trim logic is needed to normalize valid values (trim spaces),
while NonEmptyStringType rejects invalid ones (empty/whitespace-only).
Both validations serve different purposes:
- NonEmptyStringType: validation (reject invalid)
- ValidateCfg: normalization (trim valid values)
src/portal/src/app/base/left-side-nav/config/system/system-settings.component.html
Show resolved
Hide resolved
Head branch was pushed to by a user without write access
|
@wy65701436 I included the following test cases in ValidateCfgTestSuite:
This confirms that the validation logic not only checks the value but also sanitizes it before storage. |
Signed-off-by: falconlee236 <falconlee236@gmail.com>
Signed-off-by: falconlee236 <falconlee236@gmail.com>
Signed-off-by: falconlee236 <falconlee236@gmail.com>
Signed-off-by: falconlee236 <falconlee236@gmail.com>
f0f70a1 to
e95d79c
Compare
What
robot_name_prefixas non-empty so and empty/whitespace-only prefix cannot be saved.Why
string.HasPrefix(username, prefix)always being trueHow
Thanks to @stonezdj, I found clue how to handle this issue.
robot_name_prefixfromStringType toNonEmptyStringType`metadata.NewCfgValue(...)->ConfigureValue.Set(...)->ItemType.Validate(...). so empty/space-only values now returnErrStringValueIsEmptyand are rejected during config update.Issue being fixed
Fixes #22395
Please indicate you've done the following: