Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Validation Domain for login command #271

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Standing-Man
Copy link
Contributor

fixed #269.

Add the Validation function

@bupd bupd self-requested a review November 30, 2024 00:10
Copy link
Member

@Vad1mo Vad1mo left a comment

Choose a reason for hiding this comment

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

What happens for those use cases:

  • subdomain with prot -> subdomain.domain.com:port
  • ip -> 127.0.0.1 and 127.0.0.1:8080
  • top level domain -> registry.com

@Standing-Man
Copy link
Contributor Author

Standing-Man commented Dec 4, 2024

Hi @Vad1mo, the validation method allow these cases:

  • demo.gohabor.io and demo.goharbor.io:8080
  • 127.0.0.1 and 127.0.0.1:80
  • top level domain like registry.com

The port cannot be less than 0 or greater than 65535 and it validates each label in the domain name for correctness.

@Standing-Man Standing-Man requested a review from Vad1mo December 4, 2024 02:06
@bupd bupd removed their request for review December 19, 2024 21:31
@bupd bupd added the Priority: Low A problem that causes minor errors—such as formatting or display problems label Dec 19, 2024
Copy link
Contributor

@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.

❯ ./harbor-dev login
┃ Server
┃ Server address eg. demo.goharbor.io
┃ > https://127.0.0.4:50

  User Name
  > lsadkjf

  Password
  >

  Name of Credential
  Name of credential to be stored in the harbor config file.
  > [email protected]

 * invalid domain format: too many colons

the above is a valid domain

TIP

@Standing-Man, Instead of checking if the domain is valid. check only if its invalid by adding only these rules
Incorrect Domain Names:

http:// (missing domain)
https:// (missing domain)
http://example (missing TLD, not valid)
http://127.0.0.256 (invalid IP, exceeds valid octet range)
http://my_site.local (invalid local domain, underscores are not allowed in domain names)
https://example..com (double period, invalid syntax)
https://.example.com (leading dot in the domain, invalid)
http://-example.com/ (hyphen at the start, invalid)
https://example.c (single character TLD, invalid)
http://192.168.0.999 (invalid IP, octet exceeds range)
Domain Names with Special Characters (Not Valid)
http://example (missing TLD, not valid)

Standing-Man and others added 5 commits January 1, 2025 16:59
…0.0 (goharbor#189)

Bumps [github.com/charmbracelet/bubbles](https://github.com/charmbracelet/bubbles) from 0.18.0 to 0.20.0.
- [Release notes](https://github.com/charmbracelet/bubbles/releases)
- [Changelog](https://github.com/charmbracelet/bubbles/blob/master/.goreleaser.yml)
- [Commits](charmbracelet/bubbles@v0.18.0...v0.20.0)

---
updated-dependencies:
- dependency-name: github.com/charmbracelet/bubbles
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Alan Tang <[email protected]>
@Standing-Man
Copy link
Contributor Author

Hi @bupd, i'm confused about issue #297 and how to reproduce this issue.

harbor login registry.bupd.xyz -> login successfully and store in config
harbor login http://registry.bupd.xyz/ -> failed to log in

or just

harbor login http://registry.bupd.xyz/  -> failed to pass the validation of server address

Anyway, i added more restrictions to validate server address and you can try to check if issue #297 solved.

@Standing-Man Standing-Man requested a review from bupd January 1, 2025 09:22
@bupd
Copy link
Contributor

bupd commented Jan 9, 2025

@Standing-Man server address with leading slash result in failed login. We should fix it.

@@ -39,6 +41,124 @@ func FormatUrl(url string) string {
return url
}

// ValidateDomain validates subdomain, IP, or top-level domain formats
func ValidateDomain(domain string) error {
url := FormatUrl(domain)
Copy link
Contributor

Choose a reason for hiding this comment

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

In FormatUrl function. I would suggest adding the removal of leading slash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

The URL http://registry.bupd.xyz/ is still working for me, so I'm a bit unsure about what might be going wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Low A problem that causes minor errors—such as formatting or display problems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Validation for Server in login
3 participants