Skip to content

Commit

Permalink
sds: Correct comments and tests - remove mentions of non-existent req…
Browse files Browse the repository at this point in the history
…uestedCertType function (openservicemesh#2298)

Signed-off-by: Delyan Raychev <delyan.raychev@microsoft.com>
  • Loading branch information
draychev authored Jan 20, 2021
1 parent 712cf95 commit d8697f8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/envoy/ads/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var _ = Describe("Test ADS response functions", func() {
Name: serviceName,
}

Context("Test getRequestedCertType()", func() {
Context("Test makeRequestForAllSecrets()", func() {
It("returns service cert", func() {

actual := makeRequestForAllSecrets(proxy, mc)
Expand Down
5 changes: 2 additions & 3 deletions pkg/envoy/sds/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *sdsImpl) createDiscoveryResponse(request *xds_discovery.DiscoveryReques
// Resources corresponding to SDS secrets returned as a part of the DiscoveryResponse
var resources []*any.Any

// The DisvoceryRequest contains the requested certs
// The DiscoveryRequest contains the requested certs
requestedCerts := request.ResourceNames
log.Trace().Msgf("Received SDS request for ResourceNames (certificates) %+v on proxy %s, services: %v", requestedCerts, s.proxy.GetCommonName(), s.proxyServices)

Expand Down Expand Up @@ -100,7 +100,6 @@ func (s *sdsImpl) getSDSSecrets(cert certificate.Certificater, requestedCerts []

// The Envoy makes a request for a list of resources (aka certificates), which we will send as a response to the SDS request.
for _, requestedCertificate := range requestedCerts {
// requestedCertType could be either "service-cert" or "root-cert"
sdsCert, err := envoy.UnmarshalSDSCert(requestedCertificate)
if err != nil {
log.Error().Err(err).Msgf("Invalid resource kind requested: %q", requestedCertificate)
Expand All @@ -110,8 +109,8 @@ func (s *sdsImpl) getSDSSecrets(cert certificate.Certificater, requestedCerts []
log.Debug().Msgf("proxy %s (member of service %s) requested %s", s.proxy.GetCommonName(), proxyService, requestedCertificate)

switch sdsCert.CertType {
// A service certificate is requested
case envoy.ServiceCertType:
// A service certificate is requested
envoySecret, err := getServiceCertSecret(cert, requestedCertificate)
if err != nil {
log.Error().Err(err).Msgf("Error creating cert %s for proxy %s for service %s", requestedCertificate, s.proxy.GetCommonName(), proxyService)
Expand Down
9 changes: 3 additions & 6 deletions pkg/envoy/xdsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (ct SDSCertType) String() string {
return string(ct)
}

// SDSCertType enums
const (
// ServiceCertType is the prefix for the service certificate resource name. Example: "service-cert:webservice"
ServiceCertType SDSCertType = "service-cert"
Expand All @@ -51,13 +52,9 @@ const (

// RootCertTypeForHTTPS is the prefix for the HTTPS root certificate resource name. Example: "root-cert-https:webservice"
RootCertTypeForHTTPS SDSCertType = "root-cert-https"
)

// Outbound refers to Envoy upstream connectivity direction for TLS certs
Outbound SDSDirection = true

// Inbound refers to Envoy downstream connectivity direction for TLS certs
Inbound SDSDirection = false

const (
// Separator is the separator between the prefix and the name of the certificate.
Separator = ":"

Expand Down
5 changes: 2 additions & 3 deletions pkg/envoy/xdsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var _ = Describe("Test Envoy tools", func() {
addr := "blah"
port := uint32(95346)
actual := GetAddress(addr, port)

expected := &core.Address{
Address: &core.Address_SocketAddress{
SocketAddress: &core.SocketAddress{
Expand All @@ -34,7 +35,7 @@ var _ = Describe("Test Envoy tools", func() {
})
})

Context("Test CertName interface", func() {
Context("Test UnmarshalSDSCert()", func() {
It("Interface marshals and unmarshals preserving the exact same data", func() {
InitialObj := SDSCert{
CertType: ServiceCertType,
Expand All @@ -53,9 +54,7 @@ var _ = Describe("Test Envoy tools", func() {
// First and final object must be equal
Expect(*finalObj).To(Equal(InitialObj))
})
})

Context("Test getRequestedCertType()", func() {
It("returns service cert", func() {
actual, err := UnmarshalSDSCert("service-cert:namespace-test/blahBlahBlahCert")
Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit d8697f8

Please sign in to comment.