mirror of https://github.com/hashicorp/consul
Merge pull request #7485 from hashicorp/dnephin/do-not-skip-tests-on-ci
ci: Make it harder to accidentally skip tests on CI, and doc why some are skippedpull/7555/head
commit
9d959907a4
|
@ -605,8 +605,8 @@ jobs:
|
||||||
ENVOY_VERSIONS: "1.13.0"
|
ENVOY_VERSIONS: "1.13.0"
|
||||||
steps: *ENVOY_INTEGRATION_TEST_STEPS
|
steps: *ENVOY_INTEGRATION_TEST_STEPS
|
||||||
|
|
||||||
# run tests on vault ca provider integration tests
|
# run integration tests for the connect ca providers
|
||||||
vault-ca-provider:
|
test-connect-ca-providers:
|
||||||
docker:
|
docker:
|
||||||
- image: *GOLANG_IMAGE
|
- image: *GOLANG_IMAGE
|
||||||
environment:
|
environment:
|
||||||
|
@ -622,7 +622,7 @@ jobs:
|
||||||
# Gather deps to run go tests
|
# Gather deps to run go tests
|
||||||
- checkout
|
- checkout
|
||||||
# Run go tests
|
# Run go tests
|
||||||
- run: make test-vault-ca-provider
|
- run: make test-connect-ca-providers
|
||||||
- store_test_results:
|
- store_test_results:
|
||||||
path: *TEST_RESULTS_DIR
|
path: *TEST_RESULTS_DIR
|
||||||
|
|
||||||
|
@ -670,6 +670,8 @@ workflows:
|
||||||
- go-test
|
- go-test
|
||||||
- go-test-api
|
- go-test-api
|
||||||
- go-test-sdk
|
- go-test-sdk
|
||||||
|
- test-connect-ca-providers: *go-test
|
||||||
|
|
||||||
build-distros:
|
build-distros:
|
||||||
jobs:
|
jobs:
|
||||||
- check-vendor:
|
- check-vendor:
|
||||||
|
@ -746,9 +748,7 @@ workflows:
|
||||||
- envoy-integration-test-1.13.0:
|
- envoy-integration-test-1.13.0:
|
||||||
requires:
|
requires:
|
||||||
- dev-build
|
- dev-build
|
||||||
- vault-ca-provider:
|
|
||||||
requires:
|
|
||||||
- dev-build
|
|
||||||
website:
|
website:
|
||||||
jobs:
|
jobs:
|
||||||
- build-website
|
- build-website
|
||||||
|
|
|
@ -356,14 +356,14 @@ ui-docker: ui-build-image
|
||||||
test-envoy-integ: $(ENVOY_INTEG_DEPS)
|
test-envoy-integ: $(ENVOY_INTEG_DEPS)
|
||||||
@$(SHELL) $(CURDIR)/test/integration/connect/envoy/run-tests.sh
|
@$(SHELL) $(CURDIR)/test/integration/connect/envoy/run-tests.sh
|
||||||
|
|
||||||
test-vault-ca-provider:
|
test-connect-ca-providers:
|
||||||
ifeq ("$(CIRCLECI)","true")
|
ifeq ("$(CIRCLECI)","true")
|
||||||
# Run in CI
|
# Run in CI
|
||||||
gotestsum --format=short-verbose --junitfile "$(TEST_RESULTS_DIR)/gotestsum-report.xml" -- $(CURDIR)/agent/connect/ca/* -run 'TestVault(CA)?Provider'
|
gotestsum --format=short-verbose --junitfile "$(TEST_RESULTS_DIR)/gotestsum-report.xml" -- ./agent/connect/ca
|
||||||
else
|
else
|
||||||
# Run locally
|
# Run locally
|
||||||
@echo "Running /agent/connect/ca TestVault(CA)?Provider tests in verbose mode"
|
@echo "Running /agent/connect/ca tests in verbose mode"
|
||||||
@go test $(CURDIR)/agent/connect/ca/* -run 'TestVault(CA)?Provider' -v
|
@go test -v ./agent/connect/ca
|
||||||
endif
|
endif
|
||||||
|
|
||||||
proto-delete:
|
proto-delete:
|
||||||
|
|
|
@ -10,22 +10,25 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func skipIfAWSNotConfigured(t *testing.T) bool {
|
// skipIfAWSNotConfigured skips the test unless ENABLE_AWS_PCA_TESTS=true.
|
||||||
|
//
|
||||||
|
// These tests are not run in CI. If you are making changes to the AWS provider
|
||||||
|
// you probably want to run these tests locally. The tests will run using any
|
||||||
|
// credentials available to the AWS SDK. See
|
||||||
|
// https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials
|
||||||
|
// for a list of options.
|
||||||
|
func skipIfAWSNotConfigured(t *testing.T) {
|
||||||
enabled := os.Getenv("ENABLE_AWS_PCA_TESTS")
|
enabled := os.Getenv("ENABLE_AWS_PCA_TESTS")
|
||||||
ok, err := strconv.ParseBool(enabled)
|
ok, err := strconv.ParseBool(enabled)
|
||||||
if err != nil || !ok {
|
if err != nil || !ok {
|
||||||
t.Skip("Skipping because AWS tests are not enabled")
|
t.Skip("Skipping because AWS tests are not enabled")
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAWSBootstrapAndSignPrimary(t *testing.T) {
|
func TestAWSBootstrapAndSignPrimary(t *testing.T) {
|
||||||
// Note not parallel since we could easily hit AWS limits of too many CAs if
|
// Note not parallel since we could easily hit AWS limits of too many CAs if
|
||||||
// all of these tests run at once.
|
// all of these tests run at once.
|
||||||
if skipIfAWSNotConfigured(t) {
|
skipIfAWSNotConfigured(t)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range KeyTestCases {
|
for _, tc := range KeyTestCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
|
@ -83,9 +86,7 @@ func testSignAndValidate(t *testing.T, p Provider, rootPEM string, intermediateP
|
||||||
func TestAWSBootstrapAndSignSecondary(t *testing.T) {
|
func TestAWSBootstrapAndSignSecondary(t *testing.T) {
|
||||||
// Note not parallel since we could easily hit AWS limits of too many CAs if
|
// Note not parallel since we could easily hit AWS limits of too many CAs if
|
||||||
// all of these tests run at once.
|
// all of these tests run at once.
|
||||||
if skipIfAWSNotConfigured(t) {
|
skipIfAWSNotConfigured(t)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
p1 := testAWSProvider(t, testProviderConfigPrimary(t, nil))
|
p1 := testAWSProvider(t, testProviderConfigPrimary(t, nil))
|
||||||
defer p1.Cleanup()
|
defer p1.Cleanup()
|
||||||
|
@ -179,9 +180,7 @@ func TestAWSBootstrapAndSignSecondary(t *testing.T) {
|
||||||
func TestAWSBootstrapAndSignSecondaryConsul(t *testing.T) {
|
func TestAWSBootstrapAndSignSecondaryConsul(t *testing.T) {
|
||||||
// Note not parallel since we could easily hit AWS limits of too many CAs if
|
// Note not parallel since we could easily hit AWS limits of too many CAs if
|
||||||
// all of these tests run at once.
|
// all of these tests run at once.
|
||||||
if skipIfAWSNotConfigured(t) {
|
skipIfAWSNotConfigured(t)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("pri=consul,sec=aws", func(t *testing.T) {
|
t.Run("pri=consul,sec=aws", func(t *testing.T) {
|
||||||
conf := testConsulCAConfig()
|
conf := testConsulCAConfig()
|
||||||
|
@ -215,9 +214,7 @@ func TestAWSBootstrapAndSignSecondaryConsul(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAWSNoCrossSigning(t *testing.T) {
|
func TestAWSNoCrossSigning(t *testing.T) {
|
||||||
if skipIfAWSNotConfigured(t) {
|
skipIfAWSNotConfigured(t)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
p1 := testAWSProvider(t, testProviderConfigPrimary(t, nil))
|
p1 := testAWSProvider(t, testProviderConfigPrimary(t, nil))
|
||||||
defer p1.Cleanup()
|
defer p1.Cleanup()
|
||||||
|
@ -246,15 +243,6 @@ func testAWSProvider(t *testing.T, cfg ProviderConfig) *AWSProvider {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
type testLogger struct {
|
|
||||||
t *testing.T
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *testLogger) Write(b []byte) (int, error) {
|
|
||||||
l.t.Log(string(b))
|
|
||||||
return len(b), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func testProviderConfigPrimary(t *testing.T, cfg map[string]interface{}) ProviderConfig {
|
func testProviderConfigPrimary(t *testing.T, cfg map[string]interface{}) ProviderConfig {
|
||||||
rawCfg := make(map[string]interface{})
|
rawCfg := make(map[string]interface{})
|
||||||
for k, v := range cfg {
|
for k, v := range cfg {
|
||||||
|
|
|
@ -40,9 +40,7 @@ func TestVaultCAProvider_VaultTLSConfig(t *testing.T) {
|
||||||
func TestVaultCAProvider_Bootstrap(t *testing.T) {
|
func TestVaultCAProvider_Bootstrap(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
if skipIfVaultNotPresent(t) {
|
skipIfVaultNotPresent(t)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
provider, testVault := testVaultProvider(t)
|
provider, testVault := testVaultProvider(t)
|
||||||
defer testVault.Stop()
|
defer testVault.Stop()
|
||||||
|
@ -103,9 +101,7 @@ func assertCorrectKeyType(t *testing.T, want, certPEM string) {
|
||||||
func TestVaultCAProvider_SignLeaf(t *testing.T) {
|
func TestVaultCAProvider_SignLeaf(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
if skipIfVaultNotPresent(t) {
|
skipIfVaultNotPresent(t)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range KeyTestCases {
|
for _, tc := range KeyTestCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
|
@ -189,9 +185,7 @@ func TestVaultCAProvider_SignLeaf(t *testing.T) {
|
||||||
func TestVaultCAProvider_CrossSignCA(t *testing.T) {
|
func TestVaultCAProvider_CrossSignCA(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
if skipIfVaultNotPresent(t) {
|
skipIfVaultNotPresent(t)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := CASigningKeyTypeCases()
|
tests := CASigningKeyTypeCases()
|
||||||
|
|
||||||
|
@ -246,9 +240,7 @@ func TestVaultCAProvider_CrossSignCA(t *testing.T) {
|
||||||
func TestVaultProvider_SignIntermediate(t *testing.T) {
|
func TestVaultProvider_SignIntermediate(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
if skipIfVaultNotPresent(t) {
|
skipIfVaultNotPresent(t)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := CASigningKeyTypeCases()
|
tests := CASigningKeyTypeCases()
|
||||||
|
|
||||||
|
@ -277,9 +269,7 @@ func TestVaultProvider_SignIntermediate(t *testing.T) {
|
||||||
func TestVaultProvider_SignIntermediateConsul(t *testing.T) {
|
func TestVaultProvider_SignIntermediateConsul(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
if skipIfVaultNotPresent(t) {
|
skipIfVaultNotPresent(t)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// primary = Vault, secondary = Consul
|
// primary = Vault, secondary = Consul
|
||||||
t.Run("pri=vault,sec=consul", func(t *testing.T) {
|
t.Run("pri=vault,sec=consul", func(t *testing.T) {
|
||||||
|
@ -395,10 +385,11 @@ func testVaultProviderWithConfig(t *testing.T, isPrimary bool, rawConf map[strin
|
||||||
return provider, testVault
|
return provider, testVault
|
||||||
}
|
}
|
||||||
|
|
||||||
var printedVaultVersion sync.Once
|
// skipIfVaultNotPresent skips the test if the vault binary is not in PATH.
|
||||||
|
//
|
||||||
// skipIfVaultNotPresent skips the test and returns true if vault is not found
|
// These tests may be skipped in CI. They are run as part of a separate
|
||||||
func skipIfVaultNotPresent(t *testing.T) bool {
|
// integration test suite.
|
||||||
|
func skipIfVaultNotPresent(t *testing.T) {
|
||||||
vaultBinaryName := os.Getenv("VAULT_BINARY_NAME")
|
vaultBinaryName := os.Getenv("VAULT_BINARY_NAME")
|
||||||
if vaultBinaryName == "" {
|
if vaultBinaryName == "" {
|
||||||
vaultBinaryName = "vault"
|
vaultBinaryName = "vault"
|
||||||
|
@ -407,9 +398,7 @@ func skipIfVaultNotPresent(t *testing.T) bool {
|
||||||
path, err := exec.LookPath(vaultBinaryName)
|
path, err := exec.LookPath(vaultBinaryName)
|
||||||
if err != nil || path == "" {
|
if err != nil || path == "" {
|
||||||
t.Skipf("%q not found on $PATH - download and install to run this test", vaultBinaryName)
|
t.Skipf("%q not found on $PATH - download and install to run this test", vaultBinaryName)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTestVault() (*testVaultServer, error) {
|
func runTestVault() (*testVaultServer, error) {
|
||||||
|
@ -482,6 +471,8 @@ type testVaultServer struct {
|
||||||
returnPortsFn func()
|
returnPortsFn func()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var printedVaultVersion sync.Once
|
||||||
|
|
||||||
func (v *testVaultServer) WaitUntilReady(t *testing.T) {
|
func (v *testVaultServer) WaitUntilReady(t *testing.T) {
|
||||||
var version string
|
var version string
|
||||||
retry.Run(t, func(r *retry.R) {
|
retry.Run(t, func(r *retry.R) {
|
||||||
|
|
|
@ -17,27 +17,23 @@ type KeyConfig struct {
|
||||||
keyBits int
|
keyBits int
|
||||||
}
|
}
|
||||||
|
|
||||||
var goodParams, badParams []KeyConfig
|
var goodParams = []KeyConfig{
|
||||||
|
{keyType: "rsa", keyBits: 2048},
|
||||||
func init() {
|
{keyType: "rsa", keyBits: 4096},
|
||||||
goodParams = []KeyConfig{
|
{keyType: "ec", keyBits: 224},
|
||||||
{keyType: "rsa", keyBits: 2048},
|
{keyType: "ec", keyBits: 256},
|
||||||
{keyType: "rsa", keyBits: 4096},
|
{keyType: "ec", keyBits: 384},
|
||||||
{keyType: "ec", keyBits: 224},
|
{keyType: "ec", keyBits: 521},
|
||||||
{keyType: "ec", keyBits: 256},
|
}
|
||||||
{keyType: "ec", keyBits: 384},
|
var badParams = []KeyConfig{
|
||||||
{keyType: "ec", keyBits: 521},
|
{keyType: "rsa", keyBits: 0},
|
||||||
}
|
{keyType: "rsa", keyBits: 1024},
|
||||||
badParams = []KeyConfig{
|
{keyType: "rsa", keyBits: 24601},
|
||||||
{keyType: "rsa", keyBits: 0},
|
{keyType: "ec", keyBits: 0},
|
||||||
{keyType: "rsa", keyBits: 1024},
|
{keyType: "ec", keyBits: 512},
|
||||||
{keyType: "rsa", keyBits: 24601},
|
{keyType: "ec", keyBits: 321},
|
||||||
{keyType: "ec", keyBits: 0},
|
{keyType: "ecdsa", keyBits: 256}, // test for "ecdsa" instead of "ec"
|
||||||
{keyType: "ec", keyBits: 512},
|
{keyType: "aes", keyBits: 128},
|
||||||
{keyType: "ec", keyBits: 321},
|
|
||||||
{keyType: "ecdsa", keyBits: 256}, // test for "ecdsa" instead of "ec"
|
|
||||||
{keyType: "aes", keyBits: 128},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeConfig(kc KeyConfig) structs.CommonCAProviderConfig {
|
func makeConfig(kc KeyConfig) structs.CommonCAProviderConfig {
|
||||||
|
|
|
@ -12,29 +12,22 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// hasOpenSSL is used to determine if the openssl CLI exists for unit tests.
|
var mustAlwaysRun = os.Getenv("CI") == "true"
|
||||||
var hasOpenSSL bool
|
|
||||||
|
|
||||||
func init() {
|
func skipIfMissingOpenSSL(t *testing.T) {
|
||||||
goodParams = []KeyConfig{
|
openSSLBinaryName := "openssl"
|
||||||
{keyType: "rsa", keyBits: 2048},
|
_, err := exec.LookPath(openSSLBinaryName)
|
||||||
{keyType: "rsa", keyBits: 4096},
|
if err != nil {
|
||||||
{keyType: "ec", keyBits: 224},
|
if mustAlwaysRun {
|
||||||
{keyType: "ec", keyBits: 256},
|
t.Fatalf("%q not found on $PATH", openSSLBinaryName)
|
||||||
{keyType: "ec", keyBits: 384},
|
}
|
||||||
{keyType: "ec", keyBits: 521},
|
t.Skipf("%q not found on $PATH", openSSLBinaryName)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := exec.LookPath("openssl")
|
|
||||||
hasOpenSSL = err == nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that the TestCA and TestLeaf functions generate valid certificates.
|
// Test that the TestCA and TestLeaf functions generate valid certificates.
|
||||||
func testCAAndLeaf(t *testing.T, keyType string, keyBits int) {
|
func testCAAndLeaf(t *testing.T, keyType string, keyBits int) {
|
||||||
if !hasOpenSSL {
|
skipIfMissingOpenSSL(t)
|
||||||
t.Skip("openssl not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
|
@ -66,10 +59,7 @@ func testCAAndLeaf(t *testing.T, keyType string, keyBits int) {
|
||||||
|
|
||||||
// Test cross-signing.
|
// Test cross-signing.
|
||||||
func testCAAndLeaf_xc(t *testing.T, keyType string, keyBits int) {
|
func testCAAndLeaf_xc(t *testing.T, keyType string, keyBits int) {
|
||||||
if !hasOpenSSL {
|
skipIfMissingOpenSSL(t)
|
||||||
t.Skip("openssl not found")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue