fleet/cmd/fleetctl/session_test.go
Michal Nicpon 075702113a
Print version warning when using fleetctl (#4139)
* Remove deprecated call in fleetctl
* Remove duplicate error returned by app.Run in tests
2022-02-14 09:43:34 -07:00

36 lines
1012 B
Go

package main
import (
"context"
"errors"
"io/ioutil"
"path/filepath"
"testing"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/service"
"github.com/stretchr/testify/require"
)
func TestEarlySessionCheck(t *testing.T) {
_, ds := runServerWithMockedDS(t)
ds.ListQueriesFunc = func(ctx context.Context, opt fleet.ListQueryOptions) ([]*fleet.Query, error) {
return nil, nil
}
ds.SessionByKeyFunc = func(ctx context.Context, key string) (*fleet.Session, error) {
return nil, errors.New("invalid session")
}
tmpDir := t.TempDir()
configPath := filepath.Join(tmpDir, "config")
config := `contexts:
default:
tls-skip-verify: true
token: phIEGWGzKxXui1uZYFBXFwZ1Wv1iMxl79gbqMbOmMxgyZP2O5jga5qyhvEjzlGsdM7ax93iDqjnVSu9Fi8q1/w==`
err := ioutil.WriteFile(configPath, []byte(config), configFilePerms)
require.NoError(t, err)
_, err = runAppNoChecks([]string{"get", "queries", "--config", configPath})
require.ErrorIs(t, err, service.ErrUnauthenticated)
}