Skip to content

Conversation

@johnstcn
Copy link
Member

Relates to #485

@bjornrobertsson notified me of some issues with parsing ssh:// URLs.

The root of the issue is that we were using github.com/chainguard-dev/git-urls to do our URL validation, and not go-git's own validation library.

This PR removes the dependency on git-urls and uses go-git's transport.NewEndpoint instead, with some additional massaging to keep our current behaviour in line.

Other changes:

  • Fixed the SSH server implementation in gittest that was causing us to be unable to properly test SSH clones.
  • Fixed another test flake I ran into in log.

@johnstcn johnstcn self-assigned this Jan 22, 2026
Comment on lines +442 to +446
require.NoError(t, err)
dockerFilePath := execContainer(t, ctr, "find /workspaces -name Dockerfile")
require.NotEmpty(t, dockerFilePath)
dockerFile := execContainer(t, ctr, "cat "+dockerFilePath)
require.Contains(t, dockerFile, testImageAlpine)
Copy link
Member Author

Choose a reason for hiding this comment

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

🎉

Comment on lines +267 to +269
require.NoError(t, err)
require.True(t, cloned)
require.Equal(t, "Hello, world!", mustRead(t, clientFS, "/workspace/README.md"))
Copy link
Member Author

Choose a reason for hiding this comment

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

🎉

addr, ok := l.Addr().(*net.TCPAddr)
require.True(t, ok)
tr, err := transport.NewEndpoint(fmt.Sprintf("ssh://git@%s:%d/", addr.IP, addr.Port))
tr, err := transport.NewEndpoint(fmt.Sprintf("ssh://git@%s:%d%s", addr.IP, addr.Port, fs.Root()))
Copy link
Member Author

Choose a reason for hiding this comment

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

I think previous me was to blame for this, for which I humbly apologise.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't add new tests for this function as I figured the existing tests should suffice.

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Nice improvement! I'm however a bit concerned about the potentially brittle parsing.

git/git.go Outdated

_, err = git.CloneContext(ctx, gitStorage, fs, &git.CloneOptions{
URL: parsed.String(),
URL: opts.RepoURL, // Use the EXACT URL provided.
Copy link
Member

Choose a reason for hiding this comment

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

Do we have tests to verify that whitespace won't cause issues here for go-git?

Copy link
Member Author

Choose a reason for hiding this comment

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

Leading and trailing whitespace can cause issues, but whitespace in the URL itself appears to be handled 'correctly'. I've added some tests + added logic to return the "cleaned" URL (with whitespace and #ref trimmed) in 3618988.

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.

3 participants