3939 projectAvengersFQN = createAttrValueFQN (baseNamespace , "project" , "avengers" )
4040 projectXmenFQN = createAttrValueFQN (baseNamespace , "project" , "xmen" )
4141 projectFantasicFourFQN = createAttrValueFQN (baseNamespace , "project" , "fantasticfour" )
42+
43+ // Registered resource values
44+ netRegResValFQN = createRegisteredResourceValueFQN ("network" , "external" )
45+ platRegResValFQN = createRegisteredResourceValueFQN ("platform" , "internal" )
4246)
4347
4448var (
@@ -155,8 +159,53 @@ func (s *EvaluateTestSuite) SetupTest() {
155159 }
156160
157161 // Setup accessible registered resource values map
158- // TODO: DSPX-1295
159- s .accessibleRegisteredResourceValues = map [string ]* policy.RegisteredResourceValue {}
162+ // Create the registered resource values with action attribute values
163+ s .accessibleRegisteredResourceValues = map [string ]* policy.RegisteredResourceValue {
164+ netRegResValFQN : {
165+ Id : "network-registered-res-id" ,
166+ Value : "external" ,
167+ ActionAttributeValues : []* policy.RegisteredResourceValue_ActionAttributeValue {
168+ {
169+ Id : "network-action-attr-val-1" ,
170+ Action : actionRead ,
171+ AttributeValue : & policy.Value {
172+ Fqn : levelHighestFQN ,
173+ Value : "highest" ,
174+ },
175+ },
176+ {
177+ Id : "network-action-attr-val-2" ,
178+ Action : actionCreate ,
179+ AttributeValue : & policy.Value {
180+ Fqn : levelMidFQN ,
181+ Value : "mid" ,
182+ },
183+ },
184+ },
185+ },
186+ platRegResValFQN : {
187+ Id : "platform-registered-res-id" ,
188+ Value : "internal" ,
189+ ActionAttributeValues : []* policy.RegisteredResourceValue_ActionAttributeValue {
190+ {
191+ Id : "platform-action-attr-val-1" ,
192+ Action : actionRead ,
193+ AttributeValue : & policy.Value {
194+ Fqn : projectAvengersFQN ,
195+ Value : "avengers" ,
196+ },
197+ },
198+ {
199+ Id : "platform-action-attr-val-2" ,
200+ Action : actionRead ,
201+ AttributeValue : & policy.Value {
202+ Fqn : projectJusticeLeagueFQN ,
203+ Value : "justiceleague" ,
204+ },
205+ },
206+ },
207+ },
208+ }
160209}
161210
162211func TestEvaluateSuite (t * testing.T ) {
@@ -751,11 +800,14 @@ func (s *EvaluateTestSuite) TestEvaluateResourceAttributeValues() {
751800
752801// Test cases for getResourceDecision
753802func (s * EvaluateTestSuite ) TestGetResourceDecision () {
803+ nonExistentRegResValueFQN := createRegisteredResourceValueFQN ("nonexistent" , "value" )
804+
754805 tests := []struct {
755806 name string
756807 resource * authz.Resource
757808 entitlements subjectmappingbuiltin.AttributeValueFQNsToActions
758809 expectError bool
810+ expectPass bool
759811 }{
760812 {
761813 name : "attribute values resource" ,
@@ -765,18 +817,105 @@ func (s *EvaluateTestSuite) TestGetResourceDecision() {
765817 Fqns : []string {levelMidFQN },
766818 },
767819 },
820+ EphemeralId : "test-attr-values-id-1" ,
768821 },
769822 entitlements : subjectmappingbuiltin.AttributeValueFQNsToActions {
770823 levelMidFQN : []* policy.Action {actionRead },
771824 },
772825 expectError : false ,
826+ expectPass : true ,
827+ },
828+ {
829+ name : "registered resource value with all entitlements" ,
830+ resource : & authz.Resource {
831+ Resource : & authz.Resource_RegisteredResourceValueFqn {
832+ RegisteredResourceValueFqn : netRegResValFQN ,
833+ },
834+ EphemeralId : "test-reg-res-id-1" ,
835+ },
836+ entitlements : subjectmappingbuiltin.AttributeValueFQNsToActions {
837+ levelHighestFQN : []* policy.Action {actionRead },
838+ },
839+ expectError : false ,
840+ expectPass : true ,
841+ },
842+ {
843+ name : "registered resource value with project values" ,
844+ resource : & authz.Resource {
845+ Resource : & authz.Resource_RegisteredResourceValueFqn {
846+ RegisteredResourceValueFqn : platRegResValFQN ,
847+ },
848+ EphemeralId : "test-reg-res-id-2" ,
849+ },
850+ entitlements : subjectmappingbuiltin.AttributeValueFQNsToActions {
851+ projectAvengersFQN : []* policy.Action {actionRead },
852+ projectJusticeLeagueFQN : []* policy.Action {actionRead },
853+ },
854+ expectError : false ,
855+ expectPass : true ,
856+ },
857+ {
858+ name : "registered resource value with missing entitlements" ,
859+ resource : & authz.Resource {
860+ Resource : & authz.Resource_RegisteredResourceValueFqn {
861+ RegisteredResourceValueFqn : platRegResValFQN ,
862+ },
863+ EphemeralId : "test-reg-res-id-3" ,
864+ },
865+ entitlements : subjectmappingbuiltin.AttributeValueFQNsToActions {
866+ // Missing projectJusticeLeagueFQN
867+ projectAvengersFQN : []* policy.Action {actionRead },
868+ },
869+ expectError : false ,
870+ expectPass : false , // Missing entitlement for projectJusticeLeagueFQN
871+ },
872+ {
873+ name : "registered resource value with wrong action" ,
874+ resource : & authz.Resource {
875+ Resource : & authz.Resource_RegisteredResourceValueFqn {
876+ RegisteredResourceValueFqn : netRegResValFQN ,
877+ },
878+ EphemeralId : "test-reg-res-id-4" ,
879+ },
880+ entitlements : subjectmappingbuiltin.AttributeValueFQNsToActions {
881+ // Wrong action
882+ levelHighestFQN : []* policy.Action {actionCreate },
883+ },
884+ expectError : false ,
885+ expectPass : false ,
886+ },
887+ {
888+ name : "nonexistent registered resource value" ,
889+ resource : & authz.Resource {
890+ Resource : & authz.Resource_RegisteredResourceValueFqn {
891+ RegisteredResourceValueFqn : nonExistentRegResValueFQN ,
892+ },
893+ EphemeralId : "test-reg-res-id-5" ,
894+ },
895+ entitlements : subjectmappingbuiltin.AttributeValueFQNsToActions {},
896+ expectError : true ,
897+ expectPass : false ,
773898 },
774899 {
775900 name : "invalid nil resource" ,
776901 resource : nil ,
777902 entitlements : subjectmappingbuiltin.AttributeValueFQNsToActions {},
778903 expectError : true ,
779904 },
905+ {
906+ name : "case insensitive registered resource value FQN" ,
907+ resource : & authz.Resource {
908+ Resource : & authz.Resource_RegisteredResourceValueFqn {
909+ RegisteredResourceValueFqn : strings .ToUpper (netRegResValFQN ), // Test case insensitivity
910+ },
911+ EphemeralId : "test-reg-res-id-6" ,
912+ },
913+ entitlements : subjectmappingbuiltin.AttributeValueFQNsToActions {
914+ levelHighestFQN : []* policy.Action {actionRead },
915+ },
916+ expectError : false ,
917+ expectPass : true ,
918+ },
780919 }
781920
782921 for _ , tc := range tests {
@@ -796,6 +935,8 @@ func (s *EvaluateTestSuite) TestGetResourceDecision() {
796935 } else {
797936 s .Require ().NoError (err )
798937 s .NotNil (decision )
938+ s .Equal (tc .expectPass , decision .Passed , "Decision pass status didn't match" )
939+ s .Equal (tc .resource .GetEphemeralId (), decision .ResourceID , "Resource ID didn't match" )
799940 }
800941 })
801942 }
0 commit comments