Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Acceptance test for Auto Reload Config #1135

Merged
merged 8 commits into from
Apr 19, 2022
Merged

Adding Acceptance test for Auto Reload Config #1135

merged 8 commits into from
Apr 19, 2022

Conversation

jmurret
Copy link
Member

@jmurret jmurret commented Apr 1, 2022

NOTE: This looks like more files at first glance but there are many files that changed because of a signature change to SetupConsulClient

Changes proposed in this PR:

  • Added TestVault_TlsAutoReload to verify that certificates get rotated
  • had to change signature of SetupConsulClient to also return the portward address

How I've tested this PR:

  • Acceptance test added

How I expect reviewers to test this PR:

  • 👀

Checklist:

  • Tests added
  • CHANGELOG entry added

    HashiCorp engineers only, community PRs should not add a changelog entry.
    Entries should use present tense (e.g. Add support for...)

@@ -264,7 +264,7 @@ func (c *CLICluster) SetupConsulClient(t *testing.T, secure bool) *api.Client {
consulClient, err := api.NewClient(config)
require.NoError(t, err)

return consulClient
return consulClient, config.Address
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now also returning the address so that we can dial it in the test to get the cert and check the expiration.

@@ -211,12 +211,38 @@ func (h *HelmCluster) Upgrade(t *testing.T, helmValues map[string]string) {
k8s.WaitForAllPodsToBeReady(t, h.kubernetesClient, h.helmOptions.KubectlOptions.Namespace, fmt.Sprintf("release=%s", h.releaseName))
}

func (h *HelmCluster) SetupConsulClient(t *testing.T, secure bool) *api.Client {
func (h *HelmCluster) CreatePortForwardTunnel(t *testing.T, remotePort int) string {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted this out so that we can set up a tunnel without having to get another client.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

// TestVault_TlsAutoReload installs Vault, bootstraps it with secrets, policies, and Kube Auth Method.
// It then gets certs for https and rpc on the server. It then waits for the certs to rotate and checks
// that certs have different expirations.
func TestVault_TlsAutoReload(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is essentially the TestVault() test, but we make the certificate expiration very short and then we also get HTTPS and RPC certs before and after the time we expect them to expire to confirm that they have been rotated, as indicated by a new NotAfter value.


// verify that a previous cert expired and that a new one has been issued
// by comparing the NotAfter on the two certs.
require.NotEqual(t, httpsCert.NotAfter, httpsCert2.NotAfter)
Copy link
Member Author

@jmurret jmurret Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the main assertion and how it differs from TestVault().

@jmurret jmurret marked this pull request as ready for review April 14, 2022 16:07
@jmurret jmurret requested review from a team, curtbushko and t-eckert and removed request for a team April 14, 2022 16:07
Copy link
Contributor

@curtbushko curtbushko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job John! I really like the change to the portforward tunnelling.

I only have a couple tiny questions/comments below

@@ -211,12 +211,38 @@ func (h *HelmCluster) Upgrade(t *testing.T, helmValues map[string]string) {
k8s.WaitForAllPodsToBeReady(t, h.kubernetesClient, h.helmOptions.KubectlOptions.Namespace, fmt.Sprintf("release=%s", h.releaseName))
}

func (h *HelmCluster) SetupConsulClient(t *testing.T, secure bool) *api.Client {
func (h *HelmCluster) CreatePortForwardTunnel(t *testing.T, remotePort int) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition!

acceptance/framework/vault/helpers.go Outdated Show resolved Hide resolved
@@ -194,7 +194,7 @@ func (c *CLICluster) Destroy(t *testing.T) {
require.NoError(t, err)
}

func (c *CLICluster) SetupConsulClient(t *testing.T, secure bool) *api.Client {
func (c *CLICluster) SetupConsulClient(t *testing.T, secure bool) (*api.Client, string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name the returns so that the signature is clearer when looking up the function

`func (c *CLICluster) SetupConsulClient(t *testing.T, secure bool) (client *api.Client, configAddress string)

acceptance/tests/vault/vault_tls_auto_reload_test.go Outdated Show resolved Hide resolved
charts/consul/test/unit/client-daemonset.bats Show resolved Hide resolved
Copy link
Contributor

@t-eckert t-eckert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, John. A good quality of life improvement.

Copy link
Contributor

@thisisnotashwin thisisnotashwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job here John!!!

@jmurret jmurret merged commit 0e4285a into main Apr 19, 2022
@jmurret jmurret deleted the jm/auto-reload branch April 19, 2022 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants