Skip to content

fixed username validator#239

Merged
Vad1mo merged 2 commits intogoharbor:mainfrom
Roaster05:main
Nov 11, 2024
Merged

fixed username validator#239
Vad1mo merged 2 commits intogoharbor:mainfrom
Roaster05:main

Conversation

@Roaster05
Copy link
Copy Markdown
Contributor

The username validator previously implemented only allowed alphanumeric characters, which resulted in rejecting valid usernames accepted by the server, such as harbor-cli. This inconsistency also caused failures in login tests.

To resolve this, the current implementation of the validator has been aligned with the server's username validation criteria. You can view the server-side validator here.

This PR references issue #234

Comment thread pkg/utils/helper.go
pattern := `^[a-zA-Z0-9]{1,255}$`
re := regexp.MustCompile(pattern)
return re.MatchString(username)
return len(username) >= 1 && len(username) <= 255 && !strings.ContainsAny(username, `,"~#%$`)
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.

Yes, it meets the username validators, but it also satisfy certain requirements outlined in the issue #195.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just to confirm, should I add space trimming and an empty-check to the username validation here to fully meet issue #195 requirements, or handle that separately?

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 think it would be better to validate and trim spaces in the input fields here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@JianMinTang @bupd is it fine now?

Roaster05 and others added 2 commits November 7, 2024 11:46
Signed-off-by: Roaster05 <krishnamadhwani2@gmail.com>
Signed-off-by: Roaster05 <100672872+Roaster05@users.noreply.github.com>
Signed-off-by: Roaster05 <100672872+Roaster05@users.noreply.github.com>
@bupd bupd added the Priority: Critical Impacts essential functionality, degrading the user experie label Nov 11, 2024
Copy link
Copy Markdown
Collaborator

@bupd bupd left a comment

Choose a reason for hiding this comment

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

LGTM

@Vad1mo Vad1mo merged commit d059ef2 into goharbor:main Nov 11, 2024
Vad1mo added a commit that referenced this pull request Nov 11, 2024
Vad1mo added a commit that referenced this pull request Nov 11, 2024
@Vad1mo
Copy link
Copy Markdown
Member

Vad1mo commented Nov 11, 2024

reverting back as test fail.

Comment thread pkg/utils/helper.go
pattern := `^[a-zA-Z0-9]{1,255}$`
re := regexp.MustCompile(pattern)
return re.MatchString(username)
username = strings.TrimSpace(username)
Copy link
Copy Markdown
Contributor

@Standing-Man Standing-Man Nov 14, 2024

Choose a reason for hiding this comment

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

this code may not work as expected. If you enter harbor-cli with extra spaces, the strings.TrimSpace(username) doesn't properly store the value in the login.LoginView variable. Could you please fix this if you still want to continue? @Roaster05

@bupd bupd self-requested a review November 25, 2024 07:02
@bupd bupd mentioned this pull request Nov 26, 2024
Copy link
Copy Markdown
Collaborator

@bupd bupd left a comment

Choose a reason for hiding this comment

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

.

qcserestipy pushed a commit to qcserestipy/harbor-cli that referenced this pull request Dec 22, 2024
Signed-off-by: Patrick Eschenbach <patrickeschenbach96@gmail.com>
qcserestipy pushed a commit to qcserestipy/harbor-cli that referenced this pull request Dec 22, 2024
This reverts commit d059ef2.

Signed-off-by: Patrick Eschenbach <patrickeschenbach96@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Critical Impacts essential functionality, degrading the user experie

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants