Skip to content

fix(robot): handle empty permissions in robot view#998

Open
Jay2006sawant wants to merge 1 commit into
goharbor:mainfrom
Jay2006sawant:fix/robot-view-empty-permissions
Open

fix(robot): handle empty permissions in robot view#998
Jay2006sawant wants to merge 1 commit into
goharbor:mainfrom
Jay2006sawant:fix/robot-view-empty-permissions

Conversation

@Jay2006sawant

Copy link
Copy Markdown

Description

harbor robot view panics when the Harbor API returns a robot with an empty or nil permissions array. The view indexed robot.Permissions[0] unconditionally, while harbor robot list already guarded this case.

This PR adds safe fallbacks for the permission count and project namespace header, matching the list view behavior.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • Add robotPermissionSummary helper to safely read permission count and namespace
  • Use placeholders (0, --) when permission details are missing
  • Add unit tests for nil/empty and populated permissions

Test plan

  • go test ./pkg/views/robot/view/... -v
  • Verified robotPermissionSummary returns safe defaults for nil/empty permissions (no index panic)

Fixes goharbor#997

Signed-off-by: Jay2006sawant <jay242902@gmail.com>
@Jay2006sawant

Copy link
Copy Markdown
Author

@Vad1mo Can you please look into this?

@NucleoFusion NucleoFusion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I dont think so we can create robots with 0 permissions. (I confirmed you cant)
But i think the gaurd is not a bad to have.
@qcserestipy what do you think? Should we have it or is it redundant?

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.

[bug]: robot view panics when robot has empty permissions

2 participants