@@ -10,6 +10,7 @@ import (
1010 "connectrpc.com/connect"
1111 "github.com/stretchr/testify/require"
1212 corev1 "k8s.io/api/core/v1"
13+ apierrors "k8s.io/apimachinery/pkg/api/errors"
1314 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415 "k8s.io/apimachinery/pkg/runtime/schema"
1516 "k8s.io/apimachinery/pkg/types"
@@ -441,11 +442,46 @@ func Test_server_approveFreight(t *testing.T) {
441442 require .Equal (t , http .StatusNotFound , w .Code )
442443 },
443444 },
445+ {
446+ name : "not authorized to approve (not authorized to promote)" ,
447+ clientBuilder : fake .NewClientBuilder ().
448+ WithObjects (testProject , testFreight , testStage ).
449+ WithStatusSubresource (testFreight ),
450+ serverSetup : func (_ * testing.T , s * server ) {
451+ s .authorizeFn = func (
452+ context.Context ,
453+ string ,
454+ schema.GroupVersionResource ,
455+ string ,
456+ client.ObjectKey ,
457+ ) error {
458+ return apierrors .NewForbidden (
459+ kargoapi .GroupVersion .WithResource ("stages" ).GroupResource (),
460+ testStageName ,
461+ errors .New ("not authorized" ),
462+ )
463+ }
464+ },
465+ assertions : func (t * testing.T , w * httptest.ResponseRecorder , _ client.Client ) {
466+ require .Equal (t , http .StatusForbidden , w .Code )
467+ },
468+ },
444469 {
445470 name : "approves Freight" ,
446471 clientBuilder : fake .NewClientBuilder ().
447472 WithObjects (testProject , testFreight , testStage ).
448473 WithStatusSubresource (testFreight ),
474+ serverSetup : func (_ * testing.T , s * server ) {
475+ s .authorizeFn = func (
476+ context.Context ,
477+ string ,
478+ schema.GroupVersionResource ,
479+ string ,
480+ client.ObjectKey ,
481+ ) error {
482+ return nil
483+ }
484+ },
449485 assertions : func (t * testing.T , w * httptest.ResponseRecorder , c client.Client ) {
450486 require .Equal (t , http .StatusOK , w .Code )
451487
0 commit comments