Skip to content

restricts registryURL format #76

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

Merged
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
2 changes: 1 addition & 1 deletion pkg/devfile/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func parseFromRegistry(parentId, registryURL string, curDevfileCtx devfileCtx.De

func getDevfileFromRegistry(parentId, registryURL string) ([]byte, error) {
if !strings.HasPrefix(registryURL, "http://") && !strings.HasPrefix(registryURL, "https://") {
registryURL = fmt.Sprintf("http://%s", registryURL)
return nil, fmt.Errorf("the provided registryURL: %s is not a valid URL", registryURL)
}
param := util.HTTPRequestParams{
URL: fmt.Sprintf("%s/devfiles/%s", registryURL, parentId),
Expand Down
11 changes: 6 additions & 5 deletions pkg/devfile/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2466,7 +2466,7 @@ func Test_parseParentFromRegistry(t *testing.T) {
DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{
Parent: &v1.Parent{
ImportReference: v1.ImportReference{
RegistryUrl: validRegistry,
RegistryUrl: "http://" + validRegistry,
ImportReferenceUnion: v1.ImportReferenceUnion{
Id: "nodejs",
},
Expand Down Expand Up @@ -2577,7 +2577,7 @@ func Test_parseParentFromRegistry(t *testing.T) {
}

ctxWithRegistry := devfileCtx.NewDevfileCtx(OutputDevfileYamlPath)
ctxWithRegistry.SetRegistryURLs([]string{validRegistry})
ctxWithRegistry.SetRegistryURLs([]string{"http://" + validRegistry})

tests := []struct {
name string
Expand Down Expand Up @@ -2908,7 +2908,7 @@ func Test_parseFromRegistry(t *testing.T) {
)

ctxWithRegistry := devfileCtx.NewDevfileCtx(OutputDevfileYamlPath)
ctxWithRegistry.SetRegistryURLs([]string{registry})
ctxWithRegistry.SetRegistryURLs([]string{"http://" + registry})

parentDevfile := DevfileObj{
Data: &v2.DevfileV2{
Expand Down Expand Up @@ -2978,11 +2978,12 @@ func Test_parseFromRegistry(t *testing.T) {
wantErr bool
}{
{
name: "should be able to parse from provided registryUrl without prefix",
name: "should fail if provided registryUrl does not have protocol prefix",
curDevfileCtx: devfileCtx.NewDevfileCtx(OutputDevfileYamlPath),
wantDevFile: parentDevfile,
registryUrl: registry,
registryId: registryId,
wantErr: true,
Copy link
Member

Choose a reason for hiding this comment

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

test title should be should NOT be able to parse from provided registryUrl without prefix

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

},
{
name: "should be able to parse from provided registryUrl with prefix",
Expand Down Expand Up @@ -3026,7 +3027,7 @@ func Test_parseFromRegistry(t *testing.T) {
return
}

if !reflect.DeepEqual(got.Data, tt.wantDevFile.Data) {
if err == nil && !reflect.DeepEqual(got.Data, tt.wantDevFile.Data) {
t.Errorf("wanted: %v, got: %v, difference at %v", tt.wantDevFile, got, pretty.Compare(tt.wantDevFile, got))
}
})
Expand Down