From a1df2081498bbcc46e0fe6fb21b83a5a5b1c45a6 Mon Sep 17 00:00:00 2001 From: kaanyalti Date: Tue, 3 Dec 2024 19:27:15 -0500 Subject: [PATCH] enhancement(5832): added integration tests --- .../integration/restrict_upgrade_deb_test.go | 54 +++++++++++++++++++ .../integration/restrict_upgrade_rpm_test.go | 54 +++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 testing/integration/restrict_upgrade_deb_test.go create mode 100644 testing/integration/restrict_upgrade_rpm_test.go diff --git a/testing/integration/restrict_upgrade_deb_test.go b/testing/integration/restrict_upgrade_deb_test.go new file mode 100644 index 00000000000..d4589227b0b --- /dev/null +++ b/testing/integration/restrict_upgrade_deb_test.go @@ -0,0 +1,54 @@ +//go:build integration + +package integration + +import ( + "context" + "testing" + "time" + + "github.com/elastic/elastic-agent/internal/pkg/agent/cmd" + atesting "github.com/elastic/elastic-agent/pkg/testing" + "github.com/elastic/elastic-agent/pkg/testing/define" + "github.com/stretchr/testify/require" +) + +func TestRestrictUpgradeDeb(t *testing.T) { + define.Require(t, define.Requirements{ + Group: Deb, + Stack: &define.Stack{}, + Sudo: true, + OS: []define.OS{ + { + Type: define.Linux, + Distro: "ubuntu", + }, + }, + }) + t.Run("when agent is deployed via deb, a user should not be able to upgrade the agent using the cli", func(t *testing.T) { + ctx := context.Background() + + fixture, err := define.NewFixtureFromLocalBuild(t, define.Version(), atesting.WithPackageFormat("deb")) + require.NoError(t, err) + installOpts := atesting.InstallOpts{ + NonInteractive: true, + Privileged: true, + Force: true, + } + + _, err = fixture.InstallWithoutEnroll(ctx, &installOpts) + require.NoError(t, err) + + require.Eventuallyf(t, func() bool { + err = fixture.IsHealthy(ctx) + return err == nil + }, 5*time.Minute, time.Second, + "Elastic-Agent did not report healthy. Agent status error: \"%v\"", + err, + ) + + out, err := fixture.Exec(ctx, []string{"upgrade", "1.0.0"}) + require.Error(t, err) + require.Contains(t, string(out), cmd.UpgradeDisabledError.Error()) + }) +} diff --git a/testing/integration/restrict_upgrade_rpm_test.go b/testing/integration/restrict_upgrade_rpm_test.go new file mode 100644 index 00000000000..f99d52f9e07 --- /dev/null +++ b/testing/integration/restrict_upgrade_rpm_test.go @@ -0,0 +1,54 @@ +//go:build integration + +package integration + +import ( + "context" + "testing" + "time" + + "github.com/elastic/elastic-agent/internal/pkg/agent/cmd" + atesting "github.com/elastic/elastic-agent/pkg/testing" + "github.com/elastic/elastic-agent/pkg/testing/define" + "github.com/stretchr/testify/require" +) + +func TestRestrictUpgradeRPM(t *testing.T) { + define.Require(t, define.Requirements{ + Group: RPM, + Stack: &define.Stack{}, + Sudo: true, + OS: []define.OS{ + { + Type: define.Linux, + Distro: "rhel", + }, + }, + }) + t.Run("when agent is deployed via rpm, a user should not be able to upgrade the agent using the cli", func(t *testing.T) { + ctx := context.Background() + + fixture, err := define.NewFixtureFromLocalBuild(t, define.Version(), atesting.WithPackageFormat("rpm")) + require.NoError(t, err) + installOpts := atesting.InstallOpts{ + NonInteractive: true, + Privileged: true, + Force: true, + } + + _, err = fixture.InstallWithoutEnroll(ctx, &installOpts) + require.NoError(t, err) + + require.Eventuallyf(t, func() bool { + err = fixture.IsHealthy(ctx) + return err == nil + }, 5*time.Minute, time.Second, + "Elastic-Agent did not report healthy. Agent status error: \"%v\"", + err, + ) + + out, err := fixture.Exec(ctx, []string{"upgrade", "1.0.0"}) + require.Error(t, err) + require.Contains(t, string(out), cmd.UpgradeDisabledError.Error()) + }) +}