From b2ee8d3b846cbe9835054dbe79cbb6f6c32916c5 Mon Sep 17 00:00:00 2001 From: Pavel Abramov Date: Wed, 6 Nov 2024 11:14:01 +0100 Subject: [PATCH] msrv: use AllowToDiscover flag in discovery endpoint Previously, flag AllowToDiscover was disregarded, which is not the indented behaviour Signed-off-by: Pavel Abramov (cherry picked from commit bd0f05793a569bf6d63a5a16fb656bfc14757a41) --- pkg/pillar/cmd/msrv/msrv_test.go | 40 ++++++++++++++++++++++++++++++++ pkg/pillar/cmd/msrv/pubsub.go | 4 ++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/pkg/pillar/cmd/msrv/msrv_test.go b/pkg/pillar/cmd/msrv/msrv_test.go index 20a78ec6f8..ac753b7319 100644 --- a/pkg/pillar/cmd/msrv/msrv_test.go +++ b/pkg/pillar/cmd/msrv/msrv_test.go @@ -312,6 +312,8 @@ func TestHandleAppInstanceDiscovery(t *testing.T) { g.Expect(err).ToNot(gomega.HaveOccurred()) u1, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-000000000001") g.Expect(err).ToNot(gomega.HaveOccurred()) + u2, err := uuid.FromString("6ba7b810-9dad-11d1-80b4-000000000002") + g.Expect(err).ToNot(gomega.HaveOccurred()) appInstanceStatus, err := ps.NewPublication(pubsub.PublicationOptions{ AgentName: "zedmanager", @@ -343,6 +345,33 @@ func TestHandleAppInstanceDiscovery(t *testing.T) { } err = appInstanceStatus.Publish(u.String(), a) g.Expect(err).ToNot(gomega.HaveOccurred()) + + // AppInstance which is not allowed to discover + b := types.AppInstanceStatus{ + UUIDandVersion: types.UUIDandVersion{ + UUID: u2, + Version: "1.0", + }, + AppNetAdapters: []types.AppNetAdapterStatus{ + { + AssignedAddresses: types.AssignedAddrs{ + IPv4Addrs: []types.AssignedAddr{ + { + Address: net.ParseIP("192.168.1.3"), + }, + }, + IPv6Addrs: nil, + }, + AppNetAdapterConfig: types.AppNetAdapterConfig{ + IfIdx: 2, + AllowToDiscover: false, + }, + }, + }, + } + err = appInstanceStatus.Publish(u2.String(), b) + g.Expect(err).ToNot(gomega.HaveOccurred()) + discoverableNet := types.AppNetAdapterStatus{ AssignedAddresses: types.AssignedAddrs{ IPv4Addrs: []types.AssignedAddr{ @@ -400,6 +429,17 @@ func TestHandleAppInstanceDiscovery(t *testing.T) { Port: discoverableNet.Vif, Address: discoverableNet.AssignedAddresses.IPv4Addrs[0].Address.String(), }}, + + u2.String(): {{ + Port: "", + Address: b.AppNetAdapters[0].AssignedAddresses.IPv4Addrs[0].Address.String(), + }}, } g.Expect(got).To(gomega.BeEquivalentTo(expected)) + + descReq = httptest.NewRequest(http.MethodGet, "/eve/v1/discover-network.json", nil) + descReq.RemoteAddr = "192.168.1.3:0" + descResp = httptest.NewRecorder() + handler.ServeHTTP(descResp, descReq) + g.Expect(descResp.Code).To(gomega.Equal(http.StatusForbidden)) } diff --git a/pkg/pillar/cmd/msrv/pubsub.go b/pkg/pillar/cmd/msrv/pubsub.go index a5268e7a6e..81f6720697 100644 --- a/pkg/pillar/cmd/msrv/pubsub.go +++ b/pkg/pillar/cmd/msrv/pubsub.go @@ -47,12 +47,12 @@ func (srv *Msrv) lookupAppInstStatusByAppIP(ip net.IP) (*types.AppInstanceStatus for _, adapterStatus := range status.AppNetAdapters { for _, adapterIP := range adapterStatus.AssignedAddresses.IPv4Addrs { if adapterIP.Address.Equal(ip) { - return &status, true + return &status, adapterStatus.AllowToDiscover } } for _, adapterIP := range adapterStatus.AssignedAddresses.IPv6Addrs { if adapterIP.Address.Equal(ip) { - return &status, true + return &status, adapterStatus.AllowToDiscover } } }