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

Do not validate commit ID from within projectfile. #3490

Merged
merged 1 commit into from
Sep 16, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions pkg/projectfile/projectfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/ActiveState/cli/internal/sliceutils"
"github.com/ActiveState/cli/internal/strutils"
"github.com/ActiveState/cli/pkg/sysinfo"
"github.com/go-openapi/strfmt"
"github.com/google/uuid"
"github.com/imdario/mergo"
"github.com/spf13/cast"
Expand Down Expand Up @@ -660,19 +659,6 @@ func (p *Project) parseURL() (projectURL, error) {
return parseURL(p.Project)
}

func validateUUID(uuidStr string) error {
if ok := strfmt.Default.Validates("uuid", uuidStr); !ok {
return locale.NewError("err_commit_id_invalid", "", uuidStr)
}

var uuid strfmt.UUID
if err := uuid.UnmarshalText([]byte(uuidStr)); err != nil {
return locale.WrapError(err, "err_commit_id_unmarshal", "Failed to unmarshal the commit id {{.V0}} read from activestate.yaml.", uuidStr)
}

return nil
}

func parseURL(rawURL string) (projectURL, error) {
p := projectURL{}

Expand Down Expand Up @@ -701,12 +687,6 @@ func parseURL(rawURL string) (projectURL, error) {
p.LegacyCommitID = c
}

if p.LegacyCommitID != "" {
if err := validateUUID(p.LegacyCommitID); err != nil {
return p, err
}
}

if b := q.Get("branch"); b != "" {
p.BranchName = b
}
Expand Down
25 changes: 8 additions & 17 deletions pkg/projectfile/projectfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,48 +377,39 @@ func TestValidateProjectURL(t *testing.T) {

func Test_parseURL(t *testing.T) {
tests := []struct {
name string
rawURL string
want projectURL
wantErr bool
name string
rawURL string
want projectURL
}{
{
"Valid full legacy URL",
"Full URL",
"https://platform.activestate.com/Owner/Name?commitID=7BA74758-8665-4D3F-921C-757CD271A0C1&branch=main",
projectURL{
Owner: "Owner",
Name: "Name",
LegacyCommitID: "7BA74758-8665-4D3F-921C-757CD271A0C1",
BranchName: "main",
},
false,
},
{
"Valid commit URL",
"Legacy commit URL",
"https://platform.activestate.com/commit/7BA74758-8665-4D3F-921C-757CD271A0C1",
projectURL{
Owner: "",
Name: "",
LegacyCommitID: "7BA74758-8665-4D3F-921C-757CD271A0C1",
BranchName: "",
},
false,
},
{
"Invalid commit",
"https://platform.activestate.com/commit/nope",
projectURL{},
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseURL(tt.rawURL)
if (err != nil) != tt.wantErr {
t.Errorf("parseURL() error = %v, wantErr %v", err, tt.wantErr)
if err != nil {
t.Errorf("parseURL() error = %v", err)
return
}
if !tt.wantErr && !reflect.DeepEqual(got, tt.want) {
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseURL() got = %v, want %v", got, tt.want)
}
})
Expand Down
Loading