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

[release-4.7] [release-4.8] Bug 1995074: revert incorrect allowance of ssh:// prefix with scp styled URLs #902

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions pkg/helpers/newapp/cmd/newapp_test.go
Expand Up @@ -457,6 +457,51 @@ func TestBuildPipelinesWithUnresolvedImage(t *testing.T) {
}
}

func TestBuildPipelinesWithSSHGitURL(t *testing.T) {
sshURL := "ssh://git@github.com:22/user/repo.git"
sourceRepo, err := app.NewSourceRepository(sshURL, newapp.StrategyDocker)
if err != nil {
t.Fatal(err)
}
refs := app.ComponentReferences{
app.ComponentReference(&app.ComponentInput{
Value: "ruby",
Uses: sourceRepo,
ExpectToBuild: true,
ResolvedMatch: &app.ComponentMatch{
Value: "ruby",
},
}),
}

a := AppConfig{}
a.Out = &bytes.Buffer{}
group, err := a.buildPipelines(refs, app.Environment{}, app.Environment{})
if err != nil {
t.Error(err)
}
gitLocationOK := false
for _, p := range group {
if p.Build != nil {
bc, err := p.Build.BuildConfig()
if err != nil {
t.Error(err)
}
if bc.Spec.Source.Git == nil {
continue
}
if bc.Spec.Source.Git.URI == sshURL {
gitLocationOK = true
break
}
}
}
if !gitLocationOK {
t.Error("ssh git location not preserved")
}

}

func TestBuildOutputCycleResilience(t *testing.T) {

config := &AppConfig{}
Expand Down
8 changes: 0 additions & 8 deletions pkg/helpers/source-to-image/git/url.go
Expand Up @@ -86,8 +86,6 @@ func splitOnByte(s string, c byte) (string, string) {
// Parse parses a "Git URL"
func Parse(rawurl string) (*URL, error) {
if urlSchemeRegexp.MatchString(rawurl) &&
// at least through golang 1.14.9, url.Parse cannot handle ssh://git@github.com:sclorg/nodejs-ex
!strings.HasPrefix(rawurl, "ssh://") &&
(runtime.GOOS != "windows" || !dosDriveRegexp.MatchString(rawurl)) {
u, err := url.Parse(rawurl)
if err != nil {
Expand All @@ -108,12 +106,6 @@ func Parse(rawurl string) (*URL, error) {
}, nil
}

// if ssh://git@github.com:sclorg/nodejs-ex then strip ssh:// a la what we
// see in other upstream git parsing handling of scp styled git URLs;
if strings.HasPrefix(rawurl, "ssh://") {
rawurl = strings.Trim(rawurl, "ssh://")
}

s, fragment := splitOnByte(rawurl, '#')

if m := scpRegexp.FindStringSubmatch(s); m != nil &&
Expand Down
39 changes: 16 additions & 23 deletions pkg/helpers/source-to-image/git/url_test.go
Expand Up @@ -10,7 +10,6 @@ import (

type parseTest struct {
rawurl string
ammendedRawURL string
expectedGitURL *URL
expectedError bool
}
Expand Down Expand Up @@ -186,15 +185,19 @@ func TestParse(t *testing.T) {
},
},
parseTest{
rawurl: "ssh://git@github.com:sclorg/nodejs-ex",
ammendedRawURL: "git@github.com:sclorg/nodejs-ex",
rawurl: "ssh://git@github.com:sclorg/nodejs-ex",
expectedError: true,
},
parseTest{
rawurl: "ssh://git@github.com:22/user/repo.git",
expectedGitURL: &URL{
URL: url.URL{
User: url.User("git"),
Host: "github.com",
Path: "sclorg/nodejs-ex",
Scheme: "ssh",
User: url.User("git"),
Host: "github.com:22",
Path: "/user/repo.git",
},
Type: URLTypeSCP,
Type: URLTypeURL,
},
expectedError: false,
},
Expand Down Expand Up @@ -235,24 +238,14 @@ func TestParse(t *testing.T) {
t.Errorf("%s: Parse() returned\n\t%#v\nWanted\n\t%#v", test.rawurl, parsedURL, test.expectedGitURL)
}

if len(test.ammendedRawURL) > 0 {
if parsedURL.String() != test.ammendedRawURL {
t.Errorf("%s: String() returned %s", test.ammendedRawURL, parsedURL.String())
}

if parsedURL.StringNoFragment() != strings.SplitN(test.ammendedRawURL, "#", 2)[0] {
t.Errorf("%s: StringNoFragment() returned %s", test.ammendedRawURL, parsedURL.StringNoFragment())
}

} else {
if parsedURL.String() != test.rawurl {
t.Errorf("%s: String() returned %s", test.rawurl, parsedURL.String())
}
if parsedURL.String() != test.rawurl {
t.Errorf("%s: String() returned %s", test.rawurl, parsedURL.String())
}

if parsedURL.StringNoFragment() != strings.SplitN(test.rawurl, "#", 2)[0] {
t.Errorf("%s: StringNoFragment() returned %s", test.rawurl, parsedURL.StringNoFragment())
}
if parsedURL.StringNoFragment() != strings.SplitN(test.rawurl, "#", 2)[0] {
t.Errorf("%s: StringNoFragment() returned %s", test.rawurl, parsedURL.StringNoFragment())
}

}
}

Expand Down