@@ -15,6 +15,7 @@ import (
1515 "testing"
1616 "time"
1717
18+ "github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1"
1819 "github.com/openshift-pipelines/pipelines-as-code/pkg/params"
1920 "github.com/openshift-pipelines/pipelines-as-code/pkg/params/clients"
2021 "github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
@@ -309,13 +310,14 @@ func TestSetClient(t *testing.T) {
309310 name string
310311 apiURL string
311312 opts * info.Event
313+ repo * v1alpha1.Repository
312314 wantErrSubstr string
313315 muxUser func (w http.ResponseWriter , r * http.Request )
314316 }{
315317 {
316- name : "bad/no username " ,
318+ name : "bad/no token " ,
317319 opts : info .NewEvent (),
318- wantErrSubstr : "no spec.git_provider.user " ,
320+ wantErrSubstr : "no spec.git_provider.secret " ,
319321 },
320322 {
321323 name : "bad/no secret" ,
@@ -350,7 +352,26 @@ func TestSetClient(t *testing.T) {
350352 _ , _ = w .Write ([]byte (`{"errors": [{"message": "Unauthorized"}]}` ))
351353 },
352354 apiURL : "https://foo.bar/rest" ,
353- wantErrSubstr : "cannot get user foo with token" ,
355+ wantErrSubstr : "failed validation of user foo with provided token: Unauthorized" ,
356+ },
357+ {
358+ name : "bad/invalid secret" ,
359+ opts : & info.Event {
360+ Provider : & info.Provider {
361+ Token : "bar" ,
362+ URL : "https://foo.bar" ,
363+ },
364+ },
365+ repo : & v1alpha1.Repository {
366+ Spec : v1alpha1.RepositorySpec {
367+ URL : "rest/api/1.0/users/foo" ,
368+ },
369+ },
370+ muxUser : func (w http.ResponseWriter , _ * http.Request ) {
371+ w .WriteHeader (http .StatusUnauthorized )
372+ },
373+ apiURL : "https://foo.bar" ,
374+ wantErrSubstr : "token validation failed: unauthorized" ,
354375 },
355376 {
356377 name : "bad/unknown error" ,
@@ -366,7 +387,7 @@ func TestSetClient(t *testing.T) {
366387 _ , _ = w .Write ([]byte (`{"errors": [{"message": "Internal Server Error"}]}` ))
367388 },
368389 apiURL : "https://foo.bar/rest" ,
369- wantErrSubstr : "cannot get user foo : Internal Server Error" ,
390+ wantErrSubstr : "user validation failed with : Internal Server Error" ,
370391 },
371392 {
372393 name : "good/url append /rest" ,
@@ -399,7 +420,7 @@ func TestSetClient(t *testing.T) {
399420 mux .HandleFunc ("/users/foo" , tt .muxUser )
400421 }
401422 v := & Provider {client : client , baseURL : tURL }
402- err := v .SetClient (ctx , fakeRun , tt .opts , nil , nil )
423+ err := v .SetClient (ctx , fakeRun , tt .opts , tt . repo , nil )
403424 if tt .wantErrSubstr != "" {
404425 assert .ErrorContains (t , err , tt .wantErrSubstr )
405426 return
0 commit comments