regular_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package sceptest
  2. import (
  3. "net/http"
  4. "sync"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. "github.com/smallstep/scep"
  9. )
  10. func TestIssuesCertificateUsingRegularSCEPConfiguration(t *testing.T) {
  11. c := newTestCA(t, "Step E2E | SCEP Regular")
  12. var wg sync.WaitGroup
  13. wg.Go(func() {
  14. err := c.run()
  15. require.ErrorIs(t, err, http.ErrServerClosed)
  16. })
  17. // instantiate a client for the CA running at the random address
  18. caClient := newCAClient(t, c.caURL, c.rootFilepath)
  19. requireHealthyCA(t, caClient)
  20. scepClient := createSCEPClient(t, c.caURL, c.root)
  21. cert, err := scepClient.requestCertificate(t)
  22. require.NoError(t, err)
  23. require.NotNil(t, cert)
  24. assert.Equal(t, "test.localhost", cert.Subject.CommonName)
  25. assert.Equal(t, "Step E2E | SCEP Regular Intermediate CA", cert.Issuer.CommonName)
  26. // done testing; stop and wait for the server to quit
  27. err = c.stop()
  28. require.NoError(t, err)
  29. wg.Wait()
  30. }
  31. func TestBlocksCertificateRequestUsingInvalidChallenge(t *testing.T) {
  32. c := newTestCA(t, "Step E2E | SCEP Regular w/ invalid challenge")
  33. var wg sync.WaitGroup
  34. wg.Go(func() {
  35. err := c.run()
  36. require.ErrorIs(t, err, http.ErrServerClosed)
  37. })
  38. // instantiate a client for the CA running at the random address
  39. caClient := newCAClient(t, c.caURL, c.rootFilepath)
  40. requireHealthyCA(t, caClient)
  41. scepClient := createSCEPClient(t, c.caURL, c.root)
  42. cert, err := scepClient.requestCertificate(t, withChallenge("an-invalid-challenge"))
  43. require.Error(t, err)
  44. require.Nil(t, cert)
  45. // done testing; stop and wait for the server to quit
  46. err = c.stop()
  47. require.NoError(t, err)
  48. wg.Wait()
  49. }
  50. func TestBlocksUnsupportedMessageType(t *testing.T) {
  51. c := newTestCA(t, "Step E2E | SCEP Regular w/ unsupported message type")
  52. var wg sync.WaitGroup
  53. wg.Go(func() {
  54. err := c.run()
  55. require.ErrorIs(t, err, http.ErrServerClosed)
  56. })
  57. // instantiate a client for the CA running at the random address
  58. caClient := newCAClient(t, c.caURL, c.rootFilepath)
  59. requireHealthyCA(t, caClient)
  60. scepClient := createSCEPClient(t, c.caURL, c.root)
  61. cert, err := scepClient.requestCertificate(t, withMessageType(scep.CertPoll))
  62. require.Error(t, err)
  63. require.Nil(t, cert)
  64. // done testing; stop and wait for the server to quit
  65. err = c.stop()
  66. require.NoError(t, err)
  67. wg.Wait()
  68. }