Skip to content

Commit beb9b85

Browse files
committed
Fix up FIPS upgrade test to use postWatcherSuccessHook to test FIPS compliance of upgraded Agent
1 parent 41eb610 commit beb9b85

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

testing/integration/upgrade_standalone_fips_test.go

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
package integration
88

99
import (
10+
"context"
11+
"errors"
12+
"fmt"
1013
"testing"
1114

1215
"github.com/stretchr/testify/require"
1316

1417
atesting "github.com/elastic/elastic-agent/pkg/testing"
1518
"github.com/elastic/elastic-agent/pkg/testing/define"
19+
"github.com/elastic/elastic-agent/pkg/version"
1620
"github.com/elastic/elastic-agent/testing/upgradetest"
1721
)
1822

@@ -29,26 +33,50 @@ func TestStandaloneUpgradeFIPStoFIPS(t *testing.T) {
2933

3034
// Start with a FIPS-compliant Agent artifact
3135
fipsArtifactFetcher := atesting.ArtifactFetcher(atesting.WithArtifactFIPSOnly())
32-
startFixture, err := atesting.NewFixture(
33-
t,
34-
startVersion.String(),
35-
atesting.WithFetcher(fipsArtifactFetcher),
36-
)
37-
require.NoError(t, err, "error creating previous agent fixture")
38-
39-
// Upgrade to newer version of Agent
40-
endFixture, err := define.NewFixtureFromLocalBuild(t, endVersion)
41-
require.NoError(t, err)
4236

43-
err = upgradetest.PerformUpgrade(ctx, startFixture, endFixture, t, upgradetest.WithUnprivileged(unprivileged))
37+
versionList, err := upgradetest.GetUpgradableVersions()
38+
require.NoError(t, err)
39+
endVersion, err := version.ParseVersion(define.Version())
4440
require.NoError(t, err)
4541

4642
// Check that new (post-upgrade) Agent is also FIPS-compliant
47-
client := endFixture.Client()
48-
err = client.Connect(ctx)
49-
require.NoError(t, err)
43+
postWatcherSuccessHook := func(ctx context.Context, endFixture *atesting.Fixture) error {
44+
client := endFixture.Client()
45+
err := client.Connect(ctx)
46+
if err != nil {
47+
return err
48+
}
5049

51-
ver, err := client.Version(ctx)
52-
require.NoError(t, err)
53-
require.True(t, ver.Fips)
50+
ver, err := client.Version(ctx)
51+
if err != nil {
52+
return err
53+
}
54+
55+
if !ver.Fips {
56+
return errors.New("expected upgraded Agent to be FIPS-compliant")
57+
}
58+
59+
return nil
60+
}
61+
62+
for _, startVersion := range versionList {
63+
upgradeOpts := []upgradetest.UpgradeOpt{
64+
upgradetest.WithPostWatcherSuccessHook(postWatcherSuccessHook),
65+
}
66+
67+
unprivilegedAvailable := false
68+
if upgradetest.SupportsUnprivileged(startVersion, endVersion) {
69+
unprivilegedAvailable = true
70+
}
71+
t.Run(fmt.Sprintf("Upgrade %s to %s (privileged)", startVersion, define.Version()), func(t *testing.T) {
72+
upgradeOpts = append(upgradeOpts, upgradetest.WithUnprivileged(false))
73+
testStandaloneUpgrade(t, startVersion, define.Version(), fipsArtifactFetcher, upgradeOpts...)
74+
})
75+
if unprivilegedAvailable {
76+
upgradeOpts = append(upgradeOpts, upgradetest.WithUnprivileged(true))
77+
t.Run(fmt.Sprintf("Upgrade %s to %s (unprivileged)", startVersion, define.Version()), func(t *testing.T) {
78+
testStandaloneUpgrade(t, startVersion, define.Version(), fipsArtifactFetcher, upgradeOpts...)
79+
})
80+
}
81+
}
5482
}

0 commit comments

Comments
 (0)