Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/grpc/index.html

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

4 changes: 2 additions & 2 deletions docs/openapi/policy/actions/actions.openapi.yaml

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

314 changes: 158 additions & 156 deletions protocol/go/policy/actions/actions.pb.go

Large diffs are not rendered by default.

84 changes: 70 additions & 14 deletions service/integration/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,20 @@ func (s *ActionsSuite) TearDownSuite() {
}

func (s *ActionsSuite) Test_ListActions_NoPagination_Succeeds() {
fixtureCustomAction1 := s.f.GetCustomActionKey("custom_action_1")
fixtureCustomAction2 := s.f.GetCustomActionKey("other_special_action")
name1 := fmt.Sprintf("scoped-list-nopage-1-%d", time.Now().UnixNano())
name2 := fmt.Sprintf("scoped-list-nopage-2-%d", time.Now().UnixNano())

created1, err := s.db.PolicyClient.CreateAction(s.ctx, &actions.CreateActionRequest{
Name: name1,
NamespaceId: s.defaultNamespaceID(),
})
s.Require().NoError(err)

created2, err := s.db.PolicyClient.CreateAction(s.ctx, &actions.CreateActionRequest{
Name: name2,
NamespaceId: s.defaultNamespaceID(),
})
s.Require().NoError(err)

list, err := s.db.PolicyClient.ListActions(s.ctx, &actions.ListActionsRequest{NamespaceId: s.defaultNamespaceID()})
s.NotNil(list)
Expand All @@ -56,10 +68,10 @@ func (s *ActionsSuite) Test_ListActions_NoPagination_Succeeds() {
foundDelete := false

for _, action := range list.GetActionsCustom() {
switch action.GetName() {
case fixtureCustomAction1.Name:
switch action.GetId() {
case created1.GetId():
foundCustomAction1 = true
case fixtureCustomAction2.Name:
case created2.GetId():
foundCustomAction2 = true
}
}
Expand Down Expand Up @@ -187,28 +199,73 @@ func (s *ActionsSuite) Test_ListActions_FiltersCustomActionsByNamespace_Succeeds
s.False(foundSecond)
}

func (s *ActionsSuite) Test_ListActions_LegacyCustomAction_NamespaceProjection_Succeeds() {
func (s *ActionsSuite) Test_ListActions_WithoutNamespace_ReturnsAcrossNamespaces_Succeeds() {
name := fmt.Sprintf("global-list-action-%d", time.Now().UnixNano())

inDefault, err := s.db.PolicyClient.CreateAction(s.ctx, &actions.CreateActionRequest{
Name: name,
NamespaceId: s.defaultNamespaceID(),
})
s.Require().NoError(err)

inOther, err := s.db.PolicyClient.CreateAction(s.ctx, &actions.CreateActionRequest{
Name: name,
NamespaceId: s.otherNamespaceID(),
})
s.Require().NoError(err)

list, err := s.db.PolicyClient.ListActions(s.ctx, &actions.ListActionsRequest{})
s.Require().NoError(err)

foundDefault := false
foundOther := false
for _, action := range list.GetActionsCustom() {
if action.GetId() == inDefault.GetId() {
foundDefault = true
s.Equal(s.defaultNamespaceID(), action.GetNamespace().GetId())
}
if action.GetId() == inOther.GetId() {
foundOther = true
s.Equal(s.otherNamespaceID(), action.GetNamespace().GetId())
}
}

s.True(foundDefault)
s.True(foundOther)
}
Comment thread
elizabethhealy marked this conversation as resolved.
Resolved

func (s *ActionsSuite) Test_ListActions_LegacyCustomAction_ScopedExcluded_UnscopedIncluded_Succeeds() {
legacy := s.f.GetCustomActionKey("custom_action_1")
assertLegacyProjected := func(list *actions.ListActionsResponse) {
assertLegacyAbsent := func(list *actions.ListActionsResponse) {
s.T().Helper()
found := false
for _, action := range list.GetActionsCustom() {
if action.GetId() == legacy.ID {
found = true
s.Equal(s.defaultNamespaceID(), action.GetNamespace().GetId())
s.Equal(s.defaultNamespaceFQN(), action.GetNamespace().GetFqn())
}
}
s.True(found)
s.False(found)
}

listByID, err := s.db.PolicyClient.ListActions(s.ctx, &actions.ListActionsRequest{NamespaceId: s.defaultNamespaceID()})
Comment thread
elizabethhealy marked this conversation as resolved.
Resolved
s.Require().NoError(err)
assertLegacyProjected(listByID)
assertLegacyAbsent(listByID)

listByFQN, err := s.db.PolicyClient.ListActions(s.ctx, &actions.ListActionsRequest{NamespaceFqn: s.defaultNamespaceFQN()})
s.Require().NoError(err)
assertLegacyProjected(listByFQN)
assertLegacyAbsent(listByFQN)

listUnscoped, err := s.db.PolicyClient.ListActions(s.ctx, &actions.ListActionsRequest{})
s.Require().NoError(err)

foundUnscoped := false
for _, action := range listUnscoped.GetActionsCustom() {
if action.GetId() == legacy.ID {
foundUnscoped = true
s.Nil(action.GetNamespace())
}
}
s.True(foundUnscoped)
Comment thread
elizabethhealy marked this conversation as resolved.
Resolved
}

func (s *ActionsSuite) Test_GetAction_Id_Succeeds() {
Expand Down Expand Up @@ -304,8 +361,7 @@ func (s *ActionsSuite) Test_GetAction_Name_LegacyCustomAction_Succeeds() {
assertLegacyGet := func(action *policy.Action) {
s.T().Helper()
s.Equal(legacy.ID, action.GetId())
s.Equal(s.defaultNamespaceID(), action.GetNamespace().GetId())
s.Equal(s.defaultNamespaceFQN(), action.GetNamespace().GetFqn())
s.Nil(action.GetNamespace())
}

byID, err := s.db.PolicyClient.GetAction(s.ctx, &actions.GetActionRequest{
Expand Down
13 changes: 8 additions & 5 deletions service/policy/actions/actions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "policy/selectors.proto";
*/
Comment thread
elizabethhealy marked this conversation as resolved.
Resolved

message GetActionRequest {
option (buf.validate.message).oneof = { fields: ["namespace_id", "namespace_fqn"], required: false };
option (buf.validate.message).cel = {
id: "namespace_required_for_name"
message: "Either namespace_id or namespace_fqn must be provided when getting an action by name"
Expand Down Expand Up @@ -54,12 +55,14 @@ message GetActionResponse {
}

message ListActionsRequest {
// Required
option (buf.validate.message).oneof = { fields: ["namespace_id", "namespace_fqn"], required: true };
// Optional
option (buf.validate.message).oneof = { fields: ["namespace_id", "namespace_fqn"], required: false };

// ID of the namespace. Required if namespace_fqn is not provided.
string namespace_id = 1 [(buf.validate.field).string.uuid = true];
// FQN of the namespace. Required if namespace_id is not provided.
// ID of the namespace to scope results. If omitted, returns actions across namespaces.
string namespace_id = 1 [
(buf.validate.field).string.uuid = true
];
// FQN of the namespace to scope results. If omitted, returns actions across namespaces.
string namespace_fqn = 2 [
(buf.validate.field).string = {
min_len : 1
Expand Down
16 changes: 7 additions & 9 deletions service/policy/actions/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,17 @@ func (s *ActionSuite) Test_GetAction_Fails() {
}

func (s *ActionSuite) Test_ListActions_Succeeds() {
reqNoNamespace := &actions.ListActionsRequest{}
err := s.v.Validate(reqNoNamespace)
s.Require().NoError(err)

reqPaginated := &actions.ListActionsRequest{
NamespaceId: validUUID,
Pagination: &policy.PageRequest{
Limit: 1,
},
}
err := s.v.Validate(reqPaginated)
err = s.v.Validate(reqPaginated)
s.Require().NoError(err)

reqPaginated.Pagination.Offset = 100
Expand All @@ -259,15 +263,9 @@ func (s *ActionSuite) Test_ListActions_Succeeds() {
}

func (s *ActionSuite) Test_ListActions_Fails() {
// missing namespace
req := &actions.ListActionsRequest{}
err := s.v.Validate(req)
s.Require().Error(err)
s.Require().Contains(err.Error(), errMessageOneof)

// invalid namespace id
req = &actions.ListActionsRequest{NamespaceId: "invalid-uuid"}
err = s.v.Validate(req)
req := &actions.ListActionsRequest{NamespaceId: "invalid-uuid"}
err := s.v.Validate(req)
s.Require().Error(err)
s.Require().Contains(err.Error(), errMessageUUID)

Expand Down
Loading
Loading