4
0

windows_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //go:build !go1.23
  2. package sceptest
  3. import (
  4. "crypto/rand"
  5. "crypto/rsa"
  6. "net/http"
  7. "sync"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. )
  12. func TestIssuesCertificateToEmulatedWindowsClient(t *testing.T) {
  13. c := newTestCA(t, "Step E2E | SCEP Regular w/ Windows Client")
  14. var wg sync.WaitGroup
  15. wg.Add(1)
  16. go func() {
  17. defer wg.Done()
  18. err := c.run()
  19. require.ErrorIs(t, err, http.ErrServerClosed)
  20. }()
  21. // instantiate a client for the CA running at the random address
  22. caClient := newCAClient(t, c.caURL, c.rootFilepath)
  23. requireHealthyCA(t, caClient)
  24. scepClient := createSCEPClient(t, c.caURL, c.root)
  25. signer, err := rsa.GenerateKey(rand.Reader, 2048)
  26. require.NoError(t, err)
  27. tmpl := createWindowsTemplate(t, signer)
  28. cert, err := scepClient.requestCertificate(t, withTemplate(tmpl), withSigner(signer))
  29. require.NoError(t, err)
  30. require.NotNil(t, cert)
  31. assert.Equal(t, "test.localhost", cert.Subject.CommonName)
  32. assert.Equal(t, "Step E2E | SCEP Regular w/ Windows Client Intermediate CA", cert.Issuer.CommonName)
  33. // done testing; stop and wait for the server to quit
  34. err = c.stop()
  35. require.NoError(t, err)
  36. wg.Wait()
  37. }