From 6dbcb1d88e39461e4a94113ad4036ef269f629df Mon Sep 17 00:00:00 2001 From: alex <8968914+acpana@users.noreply.github.com> Date: Tue, 14 Jun 2022 10:59:53 -0700 Subject: [PATCH] peering: intentions list test (#13435) --- agent/intentions_endpoint_test.go | 41 ++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/agent/intentions_endpoint_test.go b/agent/intentions_endpoint_test.go index fbff357f7..ef54ccce3 100644 --- a/agent/intentions_endpoint_test.go +++ b/agent/intentions_endpoint_test.go @@ -62,6 +62,36 @@ func TestIntentionList(t *testing.T) { ids = append(ids, reply) } + // set up an intention for a peered service + // TODO(peering): when we handle Upserts, we can use the for loop above. But it may be that we + // rip out legacy intentions before supporting that use case so run a config entry request instead here. + { + configEntryIntention := structs.ServiceIntentionsConfigEntry{ + Kind: structs.ServiceIntentions, + Name: "bar", + Sources: []*structs.SourceIntention{ + { + Name: "peered", + Peer: "peer1", + Action: structs.IntentionActionAllow, + }, + }, + } + + req, err := http.NewRequest("PUT", "/v1/config", jsonReader(configEntryIntention)) + require.NoError(t, err) + resp := httptest.NewRecorder() + + obj, err := a.srv.ConfigApply(resp, req) + require.NoError(t, err) + + if applied, ok := obj.(bool); ok { + require.True(t, applied) + } else { + t.Fatal("ConfigApply returns a boolean type") + } + } + // Request req, err := http.NewRequest("GET", "/v1/connect/intentions", nil) require.NoError(t, err) @@ -71,22 +101,27 @@ func TestIntentionList(t *testing.T) { require.NoError(t, err) value := obj.(structs.Intentions) - require.Len(t, value, 4) + require.Len(t, value, 5) - require.Equal(t, []string{"bar->db", "foo->db", "zim->gir", "*->db"}, + require.Equal(t, []string{"bar->db", "foo->db", "zim->gir", "peered->bar", "*->db"}, []string{ value[0].SourceName + "->" + value[0].DestinationName, value[1].SourceName + "->" + value[1].DestinationName, value[2].SourceName + "->" + value[2].DestinationName, value[3].SourceName + "->" + value[3].DestinationName, + value[4].SourceName + "->" + value[4].DestinationName, }) - require.Equal(t, []string{ids[2], ids[1], "", ids[0]}, + require.Equal(t, []string{ids[2], ids[1], "", "", ids[0]}, []string{ value[0].ID, value[1].ID, value[2].ID, value[3].ID, + value[4].ID, }) + + // check that a source peer exists for the intention of the peered service + require.Equal(t, "peer1", value[3].SourcePeer) }) }