-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When creating the repository, the URL must be set and must have a valid scheme (http or https). Let's add a check on the webhook to make sure the user has provider a proper URL. We make the global repository URL mandatory compared to before, but since we are TP for global repository, we can make still change that behaviour. Fixes #1852 Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
- Loading branch information
Showing
5 changed files
with
182 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
package test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1" | ||
"github.com/openshift-pipelines/pipelines-as-code/pkg/params" | ||
pacrepo "github.com/openshift-pipelines/pipelines-as-code/test/pkg/repository" | ||
"github.com/tektoncd/pipeline/pkg/names" | ||
"gotest.tools/v3/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestRepoValidation(t *testing.T) { | ||
ctx := context.TODO() | ||
run := params.New() | ||
assert.NilError(t, run.Clients.NewClients(ctx, &run.Info)) | ||
targetNS := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-ns") | ||
assert.NilError(t, pacrepo.CreateNS(ctx, targetNS, run)) | ||
|
||
tests := []struct { | ||
name string | ||
url string | ||
expectedErr string | ||
}{ | ||
{ | ||
name: "not http or https", | ||
url: "foobar", | ||
expectedErr: "URL scheme must be http or https", | ||
}, | ||
{ | ||
name: "invalid URL", | ||
url: "http:// ", | ||
expectedErr: "invalid URL format", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
repository := &v1alpha1.Repository{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: targetNS, | ||
}, | ||
Spec: v1alpha1.RepositorySpec{ | ||
URL: tt.url, | ||
}, | ||
} | ||
err := pacrepo.CreateRepo(ctx, targetNS, run, repository) | ||
assert.ErrorContains(t, err, tt.expectedErr) | ||
}) | ||
} | ||
} |