Skip to content

Commit

Permalink
feat(policy): add unsafe attribute RPC db connectivity (#1022)
Browse files Browse the repository at this point in the history
3rd PR for #115 

 - [x] reactivate (no cascade down)
 - [x] update definition name (and upsert fqn)
- [x] upsert name fqn changes from namespaces down and from attribute
definition down to values
 - [X] update rule (changes access)
 - [x] reorder of values (changes hierarchy)
 - [x] delete (cascading)
  • Loading branch information
jakedoublev authored Jul 1, 2024
1 parent 8193cec commit fbc02f3
Show file tree
Hide file tree
Showing 12 changed files with 882 additions and 295 deletions.
10 changes: 10 additions & 0 deletions docs/grpc/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions docs/openapi/policy/unsafe/unsafe.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

326 changes: 170 additions & 156 deletions protocol/go/policy/unsafe/unsafe.pb.go

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions service/integration/attribute_fqns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,57 @@ func (s *AttributeFqnSuite) TestGetAttributesByValueFqns_Fails_WithDeactivatedAt
s.Require().ErrorIs(err, db.ErrNotFound)
}

func (s *AttributeFqnSuite) TestGetAttributesByValueFqns_Fails_WithDeactivatedAttributeValue() {
// create a new namespace
ns, err := s.db.PolicyClient.CreateNamespace(s.ctx, &namespaces.CreateNamespaceRequest{
Name: "test_fqn_namespace.goodbye",
})
s.Require().NoError(err)

// give it an attribute with two values
attr, err := s.db.PolicyClient.CreateAttribute(s.ctx, &attributes.CreateAttributeRequest{
NamespaceId: ns.GetId(),
Name: "deactivating_attr",
Rule: policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF,
})
s.Require().NoError(err)

v1, err := s.db.PolicyClient.CreateAttributeValue(s.ctx, attr.GetId(), &attributes.CreateAttributeValueRequest{
Value: "value1",
})
s.Require().NoError(err)

v2, err := s.db.PolicyClient.CreateAttributeValue(s.ctx, attr.GetId(), &attributes.CreateAttributeValueRequest{
Value: "value2",
})
s.Require().NoError(err)

// deactivate the first attribute value only
_, err = s.db.PolicyClient.DeactivateAttributeValue(s.ctx, v1.GetId())
s.Require().NoError(err)

// get the attribute by the value fqn for v1
v, err := s.db.PolicyClient.GetAttributesByValueFqns(s.ctx, &attributes.GetAttributeValuesByFqnsRequest{
Fqns: []string{fqnBuilder(ns.GetName(), attr.GetName(), v1.GetValue())},
WithValue: &policy.AttributeValueSelector{
WithSubjectMaps: true,
},
})
s.Require().Error(err)
s.Nil(v)
s.Require().ErrorIs(err, db.ErrNotFound)

// get the attribute by the value fqn for v2
v, err = s.db.PolicyClient.GetAttributesByValueFqns(s.ctx, &attributes.GetAttributeValuesByFqnsRequest{
Fqns: []string{fqnBuilder(ns.GetName(), attr.GetName(), v2.GetValue())},
WithValue: &policy.AttributeValueSelector{
WithSubjectMaps: true,
},
})
s.Require().NoError(err)
s.Len(v, 1)
}

func (s *AttributeFqnSuite) TestGetAttributesByValueFqns_Fails_WithNonValueFqns() {
nsFqn := fqnBuilder("example.com", "", "")
attrFqn := fqnBuilder("example.com", "attr1", "")
Expand Down
Loading

0 comments on commit fbc02f3

Please sign in to comment.