Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Yacob <[email protected]>
  • Loading branch information
MarcosDY committed Aug 11, 2024
1 parent 5c212e6 commit 5b8ebf6
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions pkg/server/plugin/upstreamauthority/spire/spire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
svidv1 "github.com/spiffe/spire-api-sdk/proto/spire/api/server/svid/v1"
"github.com/spiffe/spire-api-sdk/proto/spire/api/types"
"github.com/spiffe/spire/pkg/common/catalog"
"github.com/spiffe/spire/pkg/common/coretypes/x509certificate"
"github.com/spiffe/spire/pkg/common/cryptoutil"
"github.com/spiffe/spire/pkg/common/x509svid"
"github.com/spiffe/spire/pkg/server/plugin/upstreamauthority"
Expand Down Expand Up @@ -140,6 +141,31 @@ func TestMintX509CA(t *testing.T) {
serverCertUpdate, _ := ca.CreateX509Certificate(
testca.WithID(spiffeid.RequireFromPath(trustDomain, "/another")),
)
serverCertUpdateTainted, _ := ca.CreateX509Certificate(
testca.WithID(spiffeid.RequireFromPath(trustDomain, "/another")),
)
expectedServerUpdateAuthority := []*x509certificate.X509Authority{
{
Certificate: serverCertUpdate[0],
},
{
Certificate: serverCertUpdateTainted[0],
Tainted: true,
},
}

certToAuthority := func(certs []*x509.Certificate) []*x509certificate.X509Authority {
var authorities []*x509certificate.X509Authority
for _, eachCert := range certs {
authorities = append(authorities, &x509certificate.X509Authority{
Certificate: eachCert,
})
}
return authorities
}
// TODO: since now we can taint authorities may we add this feature
// to go-spiffe?
expectedX509Authorities := certToAuthority(ca.Bundle().X509Authorities())

csr, pubKey, err := util.NewCSRTemplate(trustDomain.IDString())
require.NoError(t, err)
Expand Down Expand Up @@ -270,7 +296,7 @@ func TestMintX509CA(t *testing.T) {
return
}

require.Equal(t, ca.X509Bundle().X509Authorities(), x509Authorities)
require.Equal(t, expectedX509Authorities, x509Authorities)

wantTTL := c.ttl
if wantTTL == 0 {
Expand All @@ -289,6 +315,7 @@ func TestMintX509CA(t *testing.T) {
// the upstream poll frequency twice to ensure the plugin picks up
// the change to the bundle.
server.sAPIServer.appendRootCA(&types.X509Certificate{Asn1: serverCertUpdate[0].Raw})
server.sAPIServer.appendRootCA(&types.X509Certificate{Asn1: serverCertUpdateTainted[0].Raw, Tainted: true})
mockClock.Add(upstreamPollFreq)
mockClock.Add(upstreamPollFreq)
mockClock.Add(internalPollFreq)
Expand All @@ -297,7 +324,7 @@ func TestMintX509CA(t *testing.T) {
bundleUpdateResp, err := stream.RecvUpstreamX509Authorities()
require.NoError(t, err)

expectBundles := append(ca.X509Authorities(), serverCertUpdate...)
expectBundles := append(expectedX509Authorities, expectedServerUpdateAuthority...)

Check failure on line 327 in pkg/server/plugin/upstreamauthority/spire/spire_test.go

View workflow job for this annotation

GitHub Actions / lint (linux)

appendAssign: append result not assigned to the same slice (gocritic)

Check failure on line 327 in pkg/server/plugin/upstreamauthority/spire/spire_test.go

View workflow job for this annotation

GitHub Actions / lint (windows)

appendAssign: append result not assigned to the same slice (gocritic)
require.Equal(t, expectBundles, bundleUpdateResp)

// Cancel ctx to stop getting updates
Expand Down

0 comments on commit 5b8ebf6

Please sign in to comment.