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

Bug 1971332: revert incorrect ssh scp fix #238

Merged
merged 1 commit into from Jul 23, 2021
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
8 changes: 0 additions & 8 deletions pkg/build/apis/build/validation/s2i_validation.go
Expand Up @@ -56,8 +56,6 @@ type URL struct {
// Parse parses a "Git URL"
func parseGitURL(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 @@ -78,12 +76,6 @@ func parseGitURL(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
80 changes: 77 additions & 3 deletions pkg/build/apis/build/validation/validation_test.go
Expand Up @@ -258,7 +258,7 @@ func TestBuildValidationFailure(t *testing.T) {
}
}

func TestBuildValidationWithSCPStyledURL(t *testing.T) {
func TestBuildValidationWithSSHSCPStyledURL(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a test that verifies git@github.com:sclorg/nodejs-ex - can you please add one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added / pushed @adambkaplan

build := &buildapi.Build{
ObjectMeta: metav1.ObjectMeta{Name: "", Namespace: ""},
Spec: buildapi.BuildSpec{
Expand All @@ -283,8 +283,82 @@ func TestBuildValidationWithSCPStyledURL(t *testing.T) {
Phase: buildapi.BuildPhaseNew,
},
}
if result := ValidateBuild(build); len(result) != 2 {
t.Errorf("Unexpected validation result: %v", result)
result := ValidateBuild(build)
foundError := false
for _, r := range result {
if r.Type == field.ErrorTypeInvalid && r.Field == "spec.source.git.uri" {
foundError = true
break
}
}
if !foundError {
t.Errorf("did not find expected error")
}
}

func TestBuildValidationWithSSHStyledURL(t *testing.T) {
build := &buildapi.Build{
ObjectMeta: metav1.ObjectMeta{Name: "", Namespace: ""},
Spec: buildapi.BuildSpec{
CommonSpec: buildapi.CommonSpec{
Source: buildapi.BuildSource{
Git: &buildapi.GitBuildSource{
URI: "ssh://git@github.com:22/user/repo.git",
},
},
Strategy: buildapi.BuildStrategy{
DockerStrategy: &buildapi.DockerBuildStrategy{},
},
Output: buildapi.BuildOutput{
To: &kapi.ObjectReference{
Kind: "DockerImage",
Name: "repository/data",
},
},
},
},
Status: buildapi.BuildStatus{
Phase: buildapi.BuildPhaseNew,
},
}
result := ValidateBuild(build)
for _, r := range result {
if r.Field == "spec.source.git.uri" {
t.Errorf("Unexpected error with uri: %s", r.Detail)
}
}
}

func TestBuildValidationWithSCPStyledURL(t *testing.T) {
build := &buildapi.Build{
ObjectMeta: metav1.ObjectMeta{Name: "", Namespace: ""},
Spec: buildapi.BuildSpec{
CommonSpec: buildapi.CommonSpec{
Source: buildapi.BuildSource{
Git: &buildapi.GitBuildSource{
URI: "git@github.com:sclorg/nodejs-ex",
},
},
Strategy: buildapi.BuildStrategy{
DockerStrategy: &buildapi.DockerBuildStrategy{},
},
Output: buildapi.BuildOutput{
To: &kapi.ObjectReference{
Kind: "DockerImage",
Name: "repository/data",
},
},
},
},
Status: buildapi.BuildStatus{
Phase: buildapi.BuildPhaseNew,
},
}
result := ValidateBuild(build)
for _, r := range result {
if r.Field == "spec.source.git.uri" {
t.Errorf("Unexpected error with uri: %s", r.Detail)
}
}
}

Expand Down