Skip to content

fix(import-url): validate artifact URL scheme - #560

Merged
yada merged 4 commits into
microcks:masterfrom
dipak0000812:fix/534-import-url-scheme-validation
Oct 28, 2026
Merged

yada merged 4 commits into
microcks:masterfrom
dipak0000812:fix/534-import-url-scheme-validation

Conversation

@dipak0000812

Copy link
Copy Markdown
Contributor

Description

Fixes #534

When import-url receives an artifact argument without an http:// or https:// prefix, parseImportURLArg previously returned the input unchanged and it was passed to mc.DownloadArtifact, resulting in a misleading server or connection error.

This change:

  • Validates the artifact URL scheme in parseImportURLArg.
  • Returns an errors.KindUsage error when the input does not start with http:// or https://.
  • Propagates the validation error from import-url's RunE.
  • Adds regression tests for relative paths, unsupported schemes (ftp://, file:///), empty input, and the reported issue syntax.

Testing

  • go test -v ./cmd -run "TestImportURL|TestParseImportURLArg"
  • go test ./...
  • go vet ./...
  • git diff --check

AI Assistance Disclosure

AI assistance was used minimally during development for codebase/policy lookup and review. The implementation, tests, and final verification were performed and reviewed by the author.

@github-actions

Copy link
Copy Markdown

👋 @dipak0000812

Welcome to the Microcks community! 💖

Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly.

Hope you have a great time there!

@Syedowais312

Copy link
Copy Markdown
Contributor

LGTM, this matches what I proposed in #534. Thanks for picking it up, @dipak0000812

Comment thread cmd/importURL.go
f,
)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this way it gives to many responsibilities to this function.
Cobra offer pre-hook Args which is the right place for this kind of validation
this is also valid for the if len(arg) == 0 check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I totally agree here. We can use that functionality to shift our validation much closer to the actual user input.

@Harsh4902 Harsh4902 added this to the Next milestone Oct 9, 2026
@Harsh4902 Harsh4902 added component/cli go Pull requests that update go code labels Oct 9, 2026
Comment thread cmd/importURL.go Outdated
@dipak0000812

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. I've updated the implementation:

  • Moved missing-argument and URL-scheme validation into Cobra's Args validator.
  • Validated all comma-separated URLs before RunE executes, preventing partial imports caused by invalid entries.
  • Made scheme validation case-insensitive while preserving the original URL.
  • Added regression tests for mixed-case schemes and upfront validation.

The targeted tests, go vet ./cmd/..., and git diff --check pass. I also verified that the full-suite Windows path-related failures reproduce on clean master.

I've pushed the changes in 2806c15. Thanks for the review.

Comment thread cmd/importURL.go Outdated
// Check if URL starts with https or http
if strings.HasPrefix(f, "https://") || strings.HasPrefix(f, "http://") {
lower := strings.ToLower(f)
if strings.HasPrefix(lower, "https://") || strings.HasPrefix(lower, "http://") {

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.

@dipak0000812 I think this validation can be removed from parseImportURLArg, since the Cobra Args validator already checks the URL scheme before RunE is called.

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.

Good point. I've removed the redundant scheme check from parseImportURLArg; URL scheme validation now happens in Cobra's Args validator, before RunE. The parser is focused on suffix parsing, and the existing regression tests pass. Pushed the update.

@yada yada added the kind/bug Something isn't working label Oct 15, 2026

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

Thanks @dipak0000812, the case-insensitive scheme handling and the Args-hook validation both look good now.

Nit, optional: treat bare http:// and https:// as invalid.

Comment thread cmd/importURL.go
Comment thread cmd/importURL_test.go
@yada

yada commented Oct 28, 2026

Copy link
Copy Markdown
Member

Verified the merge result (build, go vet, go test ./... pass). import-url with ftp://…, file:///… or a scheme-less URL is accepted on master and sends the download request. With this PR it fails with exit 2 (must start with http:// or https://) and sends no request. http(s) URLs, including the :true suffix, work as before.

Disclosure: this comment was drafted with AI assistance, and the results were run locally.

@yada yada left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified locally. Disclosure: AI-assisted verification.

@yada
yada merged commit 224ff5c into microcks:master Oct 28, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown

🎉 @dipak0000812

You are now a Microcks community contributor! 💖

Thanks and congrats 🚀 on merging your first pull request! We are delighted and very proud of you! 👏

📢 If you're using Microcks in your organization, please add your company name to this list. 🙏 It really helps the project to gain momentum and credibility. It's a small contribution back to the project with a big impact.

If you need to know why and how to add yourself to the list, please read the blog post "Join the Microcks Adopters list and Empower the vibrant open source Community 🙌"

Kudos and please keep going, we need you 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/cli go Pull requests that update go code kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: import-url doesn't validate URL scheme, fails with misleading error instead

6 participants