Skip to content

Commit

Permalink
Fix tests to expect new behavior (incl. ensuring scripts being disabl…
Browse files Browse the repository at this point in the history
…ed has no effect)
  • Loading branch information
iansltx committed Dec 16, 2024
1 parent d2cba3f commit f1aa3d8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/fleetctl/mdm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ func TestMDMWipeCommand(t *testing.T) {
{appCfgAllMDM, "valid windows but host is locked", []string{"--host", winEnrolledLocked.host.UUID}, "Host cannot be wiped until it is unlocked."},
{appCfgAllMDM, "valid macos but host is locked", []string{"--host", macEnrolledLocked.host.UUID}, "Host cannot be wiped until it is unlocked."},
{appCfgAllMDM, "valid macos but host is locked", []string{"--host", macEnrolledLocked.host.UUID}, "Host cannot be wiped until it is unlocked."},
{appCfgScriptsDisabled, "valid linux but script are disabled", []string{"--host", linuxEnrolled.host.UUID}, "Can't wipe host because running scripts is disabled in organization settings."},
{appCfgScriptsDisabled, "valid linux and scripts are disabled", []string{"--host", linuxEnrolled.host.UUID}, ""},
}

successfulOutput := func(ident string) string {
Expand Down
11 changes: 4 additions & 7 deletions ee/server/service/software_installers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ func TestInstallUninstallAuth(t *testing.T) {
svc := newTestService(t, ds)

ds.AppConfigFunc = func(ctx context.Context) (*fleet.AppConfig, error) {
return &fleet.AppConfig{}, nil
return &fleet.AppConfig{
ServerSettings: fleet.ServerSettings{ScriptsDisabled: true}, // global scripts being disabled shouldn't impact (un)installs
}, nil
}
ds.HostFunc = func(ctx context.Context, id uint) (*fleet.Host, error) {
return &fleet.Host{
Expand Down Expand Up @@ -181,23 +183,18 @@ func TestUninstallSoftwareTitle(t *testing.T) {
return host, nil
}

// Scripts disabled
// Global scripts disabled (doesn't matter)
ds.AppConfigFunc = func(ctx context.Context) (*fleet.AppConfig, error) {
return &fleet.AppConfig{
ServerSettings: fleet.ServerSettings{
ScriptsDisabled: true,
},
}, nil
}
require.ErrorContains(t, svc.UninstallSoftwareTitle(context.Background(), 1, 10), fleet.RunScriptScriptsDisabledGloballyErrMsg)
ds.AppConfigFunc = func(ctx context.Context) (*fleet.AppConfig, error) {
return &fleet.AppConfig{}, nil
}

// Host scripts disabled
host.ScriptsEnabled = ptr.Bool(false)
require.ErrorContains(t, svc.UninstallSoftwareTitle(context.Background(), 1, 10), fleet.RunScriptsOrbitDisabledErrMsg)

}

func checkAuthErr(t *testing.T, shouldFail bool, err error) {
Expand Down
5 changes: 4 additions & 1 deletion server/service/hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,10 @@ func TestLockUnlockWipeHostAuth(t *testing.T) {
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
ds.AppConfigFunc = func(ctx context.Context) (*fleet.AppConfig, error) {
return &fleet.AppConfig{MDM: fleet.MDM{EnabledAndConfigured: true, WindowsEnabledAndConfigured: true}}, nil
return &fleet.AppConfig{
MDM: fleet.MDM{EnabledAndConfigured: true, WindowsEnabledAndConfigured: true},
ServerSettings: fleet.ServerSettings{ScriptsDisabled: true}, // scripts being disabled shouldn't stop lock/unlock/wipe
}, nil
}
ctx := viewer.NewContext(ctx, viewer.Viewer{User: tt.user})

Expand Down
6 changes: 6 additions & 0 deletions server/service/integration_enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11866,6 +11866,7 @@ func (s *integrationEnterpriseTestSuite) TestSoftwareInstallerHostRequests() {
appConf, err := s.ds.AppConfig(context.Background())
require.NoError(s.T(), err)
appConf.Features.EnableSoftwareInventory = true
appConf.ServerSettings.ScriptsDisabled = true // shouldn't stop installs/uninstalls
err = s.ds.SaveAppConfig(context.Background(), appConf)
require.NoError(s.T(), err)
time.Sleep(2 * time.Second) // Wait for the app config cache to clear
Expand Down Expand Up @@ -12276,6 +12277,11 @@ func (s *integrationEnterpriseTestSuite) TestSoftwareInstallerHostRequests() {
assert.EqualValues(t, 1, *scriptResultResp.ExitCode)
assert.Equal(t, "not ok", scriptResultResp.Output)
assert.Less(t, beforeUninstall, scriptResultResp.CreatedAt)

// Enabling software inventory globally, which will be inherited by the team
appConf.ServerSettings.ScriptsDisabled = false // set back to normal
err = s.ds.SaveAppConfig(context.Background(), appConf)
require.NoError(s.T(), err)
}

func (s *integrationEnterpriseTestSuite) TestSelfServiceSoftwareInstall() {
Expand Down

0 comments on commit f1aa3d8

Please sign in to comment.