Skip to content

Bug: import-url loses URL path/port when parsing :primary and secret suffixes #260

@cotishq

Description

@cotishq

Describe the bug

The import-url command parses artifact URLs with strings.Split(f, ":").

This breaks normal URLs that contain additional colons, for example URLs with ports:

http://localhost:8080/spec.yaml:true

The current parsing logic reconstructs the URL from only the first two split parts:

f = urlAndMainAtrifactAndSecretName[0] + ":" + urlAndMainAtrifactAndSecretName[1]

So http://localhost:8080/spec.yaml:true becomes http://localhost, losing the port, path, and filename.

This affects import-url when using the optional :primary and secret suffixes.

Expected behavior

import-url should preserve the full URL, including scheme, host, port, path, query string, and fragment.

For example:

microcks import-url http://localhost:8080/spec.yaml:true

should send this URL to microcks:

http://localhost:8080/spec.yaml

with mainArtifact=true.

URLs without suffixes should also continue to work unchanged.

Actual behavior

The URL is split on every colon. For a URL like:

http://localhost:8080/spec.yaml:true

the parser splits it into parts like:

["http", "//localhost", "8080/spec.yaml", "true"]

Then it reconstructs only:

http://localhost

As a result, Microcks receives an incorrect artifact URL.

How to Reproduce?

Reproducer:

  1. Run import-url with a URL that contains a port and the :primary suffix:
microcks import-url http://localhost:8080/spec.yaml:true \
  --microcksURL=http://localhost:8080/api \
  --keycloakClientId=<client-id> \
  --keycloakClientSecret=<client-secret>
  1. Observe that the CLI parses the artifact URL incorrectly before calling DownloadArtifact.
Image

Microcks version or git rev

Microcks CLI 1.0.2

Install method (docker-compose, helm chart, operator, docker-desktop extension,...)

built from source

Additional information

A possible fix is to avoid splitting the whole URL on every colon.

Options:

  • parse suffixes from the right side only, for example with strings.LastIndex;
  • use URL-aware parsing and only treat trailing :true, :false, and optional secret values as CLI metadata;
  • add focused unit tests for URLs with ports, paths, query strings, and suffixes.

Related code:

urlAndMainAtrifactAndSecretName := strings.Split(f, ":")
n := len(urlAndMainAtrifactAndSecretName)
f = urlAndMainAtrifactAndSecretName[0] + ":" + urlAndMainAtrifactAndSecretName[1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    component/cligoPull requests that update go codekind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions