Skip to content

feat: allow localhost as a valid host in URL validation#785

Open
marwan562 wants to merge 1 commit intogoharbor:mainfrom
marwan562:fix/allow-localhost-login
Open

feat: allow localhost as a valid host in URL validation#785
marwan562 wants to merge 1 commit intogoharbor:mainfrom
marwan562:fix/allow-localhost-login

Conversation

@marwan562
Copy link
Copy Markdown
Contributor

Description

This pull request modifies the ValidateURL function to allow localhost as a valid host. Previously, local development addresses lacking a top-level domain (like localhost or http://localhost:8080) failed the domain validation regex, which prevented users from successfully logging into local Harbor instances.

Type of Change

Please select the relevant type.

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

Changes

  • Added an early return check for "localhost" in pkg/utils/helper.go's ValidateURL function before the strict domain regex is evaluated.
  • Expanded the URL validation test suite in pkg/utils/helper_test.go to include coverage for localhost addresses using both HTTP and HTTPS schemes, as well as with and without ports.

Signed-off-by: marwan562 <mixing.gamer546@gmail.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 7.82%. Comparing base (60ad0bd) to head (b87cd21).
⚠️ Report is 123 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main    #785      +/-   ##
=========================================
- Coverage   10.99%   7.82%   -3.17%     
=========================================
  Files         173     270      +97     
  Lines        8671   13163    +4492     
=========================================
+ Hits          953    1030      +77     
- Misses       7612   12020    +4408     
- Partials      106     113       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@NucleoFusion NucleoFusion left a comment

Choose a reason for hiding this comment

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

lgtm
Thanks for the contribution

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.

Allow localhost as valid server address in login

2 participants