@@ -19,6 +19,7 @@ import (
1919 ctrlutil "github.com/stacklok/toolhive/cmd/thv-operator/pkg/controllerutil"
2020 "github.com/stacklok/toolhive/cmd/thv-operator/pkg/runconfig/configmap/checksum"
2121 "github.com/stacklok/toolhive/pkg/authz"
22+ "github.com/stacklok/toolhive/pkg/authz/authorizers/cedar"
2223 "github.com/stacklok/toolhive/pkg/container/kubernetes"
2324 "github.com/stacklok/toolhive/pkg/runner"
2425 transporttypes "github.com/stacklok/toolhive/pkg/transport/types"
@@ -322,14 +323,15 @@ func TestCreateRunConfigFromMCPServer(t *testing.T) {
322323 // Verify authorization config is set
323324 assert .NotNil (t , config .AuthzConfig )
324325 assert .Equal (t , "v1" , config .AuthzConfig .Version )
325- assert .Equal (t , authz .ConfigTypeCedarV1 , config .AuthzConfig .Type )
326- assert .NotNil (t , config .AuthzConfig .Cedar )
326+ assert .Equal (t , authz .ConfigType (cedar .ConfigType ), config .AuthzConfig .Type )
327327
328328 // Check Cedar-specific configuration
329- assert .Len (t , config .AuthzConfig .Cedar .Policies , 2 )
330- assert .Contains (t , config .AuthzConfig .Cedar .Policies , `permit(principal, action == Action::"call_tool", resource == Tool::"weather");` )
331- assert .Contains (t , config .AuthzConfig .Cedar .Policies , `permit(principal, action == Action::"get_prompt", resource == Prompt::"greeting");` )
332- assert .Equal (t , `[{"uid": {"type": "User", "id": "user1"}, "attrs": {}}]` , config .AuthzConfig .Cedar .EntitiesJSON )
329+ cedarCfg , err := cedar .ExtractConfig (config .AuthzConfig )
330+ require .NoError (t , err )
331+ assert .Len (t , cedarCfg .Options .Policies , 2 )
332+ assert .Contains (t , cedarCfg .Options .Policies , `permit(principal, action == Action::"call_tool", resource == Tool::"weather");` )
333+ assert .Contains (t , cedarCfg .Options .Policies , `permit(principal, action == Action::"get_prompt", resource == Prompt::"greeting");` )
334+ assert .Equal (t , `[{"uid": {"type": "User", "id": "user1"}, "attrs": {}}]` , cedarCfg .Options .EntitiesJSON )
333335 },
334336 },
335337 {
@@ -359,11 +361,13 @@ func TestCreateRunConfigFromMCPServer(t *testing.T) {
359361 // For ConfigMap type, with new feature, authorization config is embedded in RunConfig
360362 require .NotNil (t , config .AuthzConfig )
361363 assert .Equal (t , "v1" , config .AuthzConfig .Version )
362- assert .Equal (t , authz .ConfigTypeCedarV1 , config .AuthzConfig .Type )
363- require .NotNil (t , config .AuthzConfig .Cedar )
364- assert .Len (t , config .AuthzConfig .Cedar .Policies , 1 )
365- assert .Contains (t , config .AuthzConfig .Cedar .Policies [0 ], "call_tool" )
366- assert .Equal (t , "[]" , config .AuthzConfig .Cedar .EntitiesJSON )
364+ assert .Equal (t , authz .ConfigType (cedar .ConfigType ), config .AuthzConfig .Type )
365+
366+ cedarCfg , err := cedar .ExtractConfig (config .AuthzConfig )
367+ require .NoError (t , err )
368+ assert .Len (t , cedarCfg .Options .Policies , 1 )
369+ assert .Contains (t , cedarCfg .Options .Policies [0 ], "call_tool" )
370+ assert .Equal (t , "[]" , cedarCfg .Options .EntitiesJSON )
367371 },
368372 },
369373 {
@@ -748,14 +752,15 @@ func TestEnsureRunConfigConfigMap(t *testing.T) {
748752 // Verify authorization configuration is properly serialized
749753 assert .NotNil (t , runConfig .AuthzConfig , "AuthzConfig should be present in runconfig.json" )
750754 assert .Equal (t , "v1" , runConfig .AuthzConfig .Version )
751- assert .Equal (t , authz .ConfigTypeCedarV1 , runConfig .AuthzConfig .Type )
752- assert .NotNil (t , runConfig .AuthzConfig .Cedar )
755+ assert .Equal (t , authz .ConfigType (cedar .ConfigType ), runConfig .AuthzConfig .Type )
753756
754757 // Check Cedar-specific configuration
755- assert .Len (t , runConfig .AuthzConfig .Cedar .Policies , 2 )
756- assert .Contains (t , runConfig .AuthzConfig .Cedar .Policies , `permit(principal, action == Action::"call_tool", resource == Tool::"weather");` )
757- assert .Contains (t , runConfig .AuthzConfig .Cedar .Policies , `permit(principal, action == Action::"get_prompt", resource == Prompt::"greeting");` )
758- assert .Equal (t , `[{"uid": {"type": "User", "id": "user1"}, "attrs": {}}]` , runConfig .AuthzConfig .Cedar .EntitiesJSON )
758+ cedarCfg , err := cedar .ExtractConfig (runConfig .AuthzConfig )
759+ require .NoError (t , err )
760+ assert .Len (t , cedarCfg .Options .Policies , 2 )
761+ assert .Contains (t , cedarCfg .Options .Policies , `permit(principal, action == Action::"call_tool", resource == Tool::"weather");` )
762+ assert .Contains (t , cedarCfg .Options .Policies , `permit(principal, action == Action::"get_prompt", resource == Prompt::"greeting");` )
763+ assert .Equal (t , `[{"uid": {"type": "User", "id": "user1"}, "attrs": {}}]` , cedarCfg .Options .EntitiesJSON )
759764 },
760765 },
761766 {
@@ -968,12 +973,14 @@ func TestEnsureRunConfigConfigMap(t *testing.T) {
968973
969974 require .NotNil (t , runConfig .AuthzConfig )
970975 assert .Equal (t , "v1" , runConfig .AuthzConfig .Version )
971- assert .Equal (t , authz .ConfigTypeCedarV1 , runConfig .AuthzConfig .Type )
972- require .NotNil (t , runConfig .AuthzConfig .Cedar )
973- assert .Len (t , runConfig .AuthzConfig .Cedar .Policies , 2 )
974- assert .Contains (t , runConfig .AuthzConfig .Cedar .Policies , `permit(principal, action == Action::"call_tool", resource == Tool::"weather");` )
975- assert .Contains (t , runConfig .AuthzConfig .Cedar .Policies , `permit(principal, action == Action::"get_prompt", resource == Prompt::"greeting");` )
976- assert .Equal (t , `[{"uid": {"type": "User", "id": "user1"}, "attrs": {}}]` , runConfig .AuthzConfig .Cedar .EntitiesJSON )
976+ assert .Equal (t , authz .ConfigType (cedar .ConfigType ), runConfig .AuthzConfig .Type )
977+
978+ cedarCfg , err := cedar .ExtractConfig (runConfig .AuthzConfig )
979+ require .NoError (t , err )
980+ assert .Len (t , cedarCfg .Options .Policies , 2 )
981+ assert .Contains (t , cedarCfg .Options .Policies , `permit(principal, action == Action::"call_tool", resource == Tool::"weather");` )
982+ assert .Contains (t , cedarCfg .Options .Policies , `permit(principal, action == Action::"get_prompt", resource == Prompt::"greeting");` )
983+ assert .Equal (t , `[{"uid": {"type": "User", "id": "user1"}, "attrs": {}}]` , cedarCfg .Options .EntitiesJSON )
977984 })
978985}
979986
0 commit comments