Skip to content

Commit

Permalink
msrv: use AllowToDiscover flag in discovery endpoint
Browse files Browse the repository at this point in the history
Previously, flag AllowToDiscover was disregarded, which is not
the indented behaviour

Signed-off-by: Pavel Abramov <uncle.decart@gmail.com>
(cherry picked from commit bd0f057)
  • Loading branch information
uncleDecart committed Nov 8, 2024
1 parent 5044fd2 commit 5433c01
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
40 changes: 40 additions & 0 deletions pkg/pillar/cmd/msrv/msrv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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))
}
4 changes: 2 additions & 2 deletions pkg/pillar/cmd/msrv/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 5433c01

Please sign in to comment.