Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix app discovery endpoint #4421

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
47 changes: 43 additions & 4 deletions pkg/pillar/cmd/msrv/msrv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package msrv_test
import (
"bytes"
"encoding/json"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -107,7 +106,7 @@ func TestPostKubeconfig(t *testing.T) {
Logger: logger,
}

dir, err := ioutil.TempDir("/tmp", "msrv_test")
dir, err := os.MkdirTemp("/tmp", "msrv_test")
g.Expect(err).ToNot(gomega.HaveOccurred())
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -217,7 +216,7 @@ func TestRequestPatchEnvelopes(t *testing.T) {
Logger: logger,
}

dir, err := ioutil.TempDir("/tmp", "msrv_test")
dir, err := os.MkdirTemp("/tmp", "msrv_test")
g.Expect(err).ToNot(gomega.HaveOccurred())
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -313,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 @@ -344,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 @@ -371,7 +399,7 @@ func TestHandleAppInstanceDiscovery(t *testing.T) {
Logger: logger,
}

dir, err := ioutil.TempDir("/tmp", "msrv_test")
dir, err := os.MkdirTemp("/tmp", "msrv_test")
g.Expect(err).ToNot(gomega.HaveOccurred())
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -401,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
Loading