Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 2511ea2

Browse files
committed
address comments
Signed-off-by: Sean Teeling <[email protected]>
1 parent bfdfc9b commit 2511ea2

File tree

3 files changed

+54
-40
lines changed

3 files changed

+54
-40
lines changed

pkg/debugger/proxy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func (ds DebugConfig) printProxies(w http.ResponseWriter) {
5858
}
5959

6060
func (ds DebugConfig) getConfigDump(uuid string, w http.ResponseWriter) {
61-
proxy, ok := ds.proxyRegistry.GetConnectedProxy(uuid)
62-
if !ok {
61+
proxy := ds.proxyRegistry.GetConnectedProxy(uuid)
62+
if proxy != nil {
6363
msg := fmt.Sprintf("Proxy for UUID %s not found, may have been disconnected", uuid)
6464
log.Error().Msg(msg)
6565
if _, err := w.Write([]byte(msg)); err != nil {

pkg/envoy/ads/stream.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func isCNforProxy(proxy *envoy.Proxy, cn certificate.CommonName) bool {
335335
func getCertificateCommonNameMeta(cn certificate.CommonName) (envoy.ProxyKind, uuid.UUID, identity.ServiceIdentity, error) {
336336
// XDS cert CN is of the form <proxy-UUID>.<kind>.<proxy-identity>.<namespace>.<trust-domain>
337337
chunks := strings.SplitN(cn.String(), constants.DomainDelimiter, 5)
338-
if len(chunks) < 3 {
338+
if len(chunks) < 4 {
339339
return "", uuid.UUID{}, "", errInvalidCertificateCN
340340
}
341341
proxyUUID, err := uuid.Parse(chunks[0])
@@ -345,6 +345,15 @@ func getCertificateCommonNameMeta(cn certificate.CommonName) (envoy.ProxyKind, u
345345
return "", uuid.UUID{}, "", err
346346
}
347347

348+
switch {
349+
case chunks[1] == "":
350+
return "", uuid.UUID{}, "", errInvalidCertificateCN
351+
case chunks[2] == "":
352+
return "", uuid.UUID{}, "", errInvalidCertificateCN
353+
case chunks[3] == "":
354+
return "", uuid.UUID{}, "", errInvalidCertificateCN
355+
}
356+
348357
return envoy.ProxyKind(chunks[1]), proxyUUID, identity.New(chunks[2], chunks[3]), nil
349358
}
350359

pkg/envoy/ads/stream_test.go

+42-37
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
"fmt"
55
"testing"
66

7-
. "github.com/onsi/ginkgo"
8-
. "github.com/onsi/gomega"
9-
107
xds_discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
118
"github.com/google/uuid"
129
tassert "github.com/stretchr/testify/assert"
@@ -85,42 +82,50 @@ func TestMapsetToSliceConvFunctions(t *testing.T) {
8582
assert.False(findSliceElem(nameSlice, "D"))
8683
}
8784

88-
var _ = Describe("Test ADS response functions", func() {
89-
defer GinkgoRecover()
90-
Context("Test getCertificateCommonNameMeta()", func() {
91-
It("parses CN into certificateCommonNameMeta", func() {
92-
proxyUUID := uuid.New()
93-
testNamespace := uuid.New().String()
94-
serviceAccount := uuid.New().String()
95-
96-
cn := certificate.CommonName(fmt.Sprintf("%s.%s.%s.%s.cluster.local", proxyUUID, envoy.KindSidecar, serviceAccount, testNamespace))
85+
func TestGetCertificateCommonNameMeta(t *testing.T) {
86+
testCases := []struct {
87+
name string
88+
uuid uuid.UUID
89+
identity identity.ServiceIdentity
90+
// trustDomain string
91+
err error
92+
}{
93+
{
94+
name: "valid cn",
95+
uuid: uuid.New(),
96+
identity: identity.New("foo", "bar"),
97+
},
98+
{
99+
name: "invalid uuid",
100+
uuid: uuid.Nil,
101+
identity: identity.New("foo", "bar"),
102+
},
103+
{
104+
name: "invalid identity",
105+
uuid: uuid.New(),
106+
identity: identity.New("foo", ""),
107+
err: errInvalidCertificateCN,
108+
},
109+
{
110+
name: "no identity",
111+
uuid: uuid.New(),
112+
err: errInvalidCertificateCN,
113+
},
114+
}
115+
for _, tc := range testCases {
116+
t.Run(tc.name, func(t *testing.T) {
117+
assert := tassert.New(t)
118+
cn := certificate.CommonName(fmt.Sprintf("%s.%s.%s", tc.uuid, envoy.KindSidecar, tc.identity))
97119

98120
kind, uuid, si, err := getCertificateCommonNameMeta(cn)
99-
Expect(err).ToNot(HaveOccurred())
100-
Expect(kind).To(Equal(envoy.KindSidecar))
101-
Expect(uuid).To(Equal(proxyUUID))
102-
Expect(si).To(Equal(identity.New(serviceAccount, testNamespace)))
103-
})
104121

105-
It("parses CN into certificateCommonNameMeta", func() {
106-
_, _, _, err := getCertificateCommonNameMeta("a")
107-
Expect(err).To(HaveOccurred())
108-
})
109-
})
122+
assert.Equal(tc.err, err)
110123

111-
Context("Test NewXDSCertCommonName() and getCertificateCommonNameMeta() together", func() {
112-
It("returns the identifier of the form <proxyID>.<kind>.<service-account>.<namespace>", func() {
113-
proxyUUID := uuid.New()
114-
serviceAccount := uuid.New().String()
115-
namespace := uuid.New().String()
116-
117-
cn := envoy.NewXDSCertCommonName(proxyUUID, envoy.KindSidecar, serviceAccount, namespace)
118-
119-
actualKind, actualUUID, actualSI, err := getCertificateCommonNameMeta(cn)
120-
Expect(err).ToNot(HaveOccurred())
121-
Expect(actualKind).To(Equal(envoy.KindSidecar))
122-
Expect(actualUUID).To(Equal(proxyUUID))
123-
Expect(actualSI).To(Equal(identity.New(serviceAccount, namespace)))
124+
if err == nil {
125+
assert.Equal(envoy.KindSidecar, kind)
126+
assert.Equal(tc.uuid, uuid)
127+
assert.Equal(tc.identity, si)
128+
}
124129
})
125-
})
126-
})
130+
}
131+
}

0 commit comments

Comments
 (0)