Skip to content

Commit

Permalink
Add MATCH_SUPERSET and MATCH_ANY to SPIRE Server agent endpoints (#2468)
Browse files Browse the repository at this point in the history
* add MATCH_SUPERSET and MATCH_ANY to SPIRE Server agent endpoints

Signed-off-by: Marcos Yacob <marcos.yacob@hpe.com>
  • Loading branch information
MarcosDY committed Aug 24, 2021
1 parent 3f98149 commit f3598ff
Showing 1 changed file with 248 additions and 0 deletions.
248 changes: 248 additions & 0 deletions pkg/server/api/agent/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,254 @@ func TestListAgents(t *testing.T) {
},
},
},
{
name: "by selectors - match any",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_ANY,
Selectors: []*types.Selector{
{Type: "a", Value: "1"},
{Type: "b", Value: "2"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{
{Id: api.ProtoFromID(node1ID)},
{Id: api.ProtoFromID(node2ID)},
},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_ANY",
telemetry.BySelectors: "a:1,b:2",
},
},
},
},
{
name: "by selectors - match any (no results)",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_ANY,
Selectors: []*types.Selector{
{Type: "d", Value: "2"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_ANY",
telemetry.BySelectors: "d:2",
},
},
},
},
{
name: "by selectors - match exact",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_EXACT,
Selectors: []*types.Selector{
{Type: "a", Value: "1"},
{Type: "b", Value: "2"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{
{Id: api.ProtoFromID(node1ID)},
},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_EXACT",
telemetry.BySelectors: "a:1,b:2",
},
},
},
},
{
name: "by selectors - match exact (no results)",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_EXACT,
Selectors: []*types.Selector{
{Type: "b", Value: "2"},
{Type: "c", Value: "3"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_EXACT",
telemetry.BySelectors: "b:2,c:3",
},
},
},
},
{
name: "by selectors - match subset",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_SUBSET,
Selectors: []*types.Selector{
{Type: "a", Value: "1"},
{Type: "c", Value: "3"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{
{Id: api.ProtoFromID(node2ID)},
},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_SUBSET",
telemetry.BySelectors: "a:1,c:3",
},
},
},
},
{
name: "by selectors - match subset (no results)",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_SUBSET,
Selectors: []*types.Selector{
{Type: "b", Value: "2"},
{Type: "c", Value: "3"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_SUBSET",
telemetry.BySelectors: "b:2,c:3",
},
},
},
},
{
name: "by selectors - match superset",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_SUPERSET,
Selectors: []*types.Selector{
{Type: "a", Value: "1"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{
{Id: api.ProtoFromID(node1ID)},
{Id: api.ProtoFromID(node2ID)},
},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_SUPERSET",
telemetry.BySelectors: "a:1",
},
},
},
},
{
name: "by selectors - match superset (no results)",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_SUPERSET,
Selectors: []*types.Selector{
{Type: "b", Value: "2"},
{Type: "c", Value: "3"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_SUPERSET",
telemetry.BySelectors: "b:2,c:3",
},
},
},
},
{
name: "with pagination",
req: &agentv1.ListAgentsRequest{
Expand Down

0 comments on commit f3598ff

Please sign in to comment.