2021-10-22 18:41:17 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-11-22 14:13:26 +00:00
|
|
|
"errors"
|
2023-10-27 18:28:54 +00:00
|
|
|
"os"
|
2021-10-22 18:41:17 +00:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
2022-02-14 16:43:34 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/service"
|
2021-10-22 18:41:17 +00:00
|
|
|
"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")
|
|
|
|
}
|
2022-02-14 16:43:34 +00:00
|
|
|
|
2021-10-22 18:41:17 +00:00
|
|
|
tmpDir := t.TempDir()
|
|
|
|
configPath := filepath.Join(tmpDir, "config")
|
|
|
|
config := `contexts:
|
|
|
|
default:
|
|
|
|
tls-skip-verify: true
|
|
|
|
token: phIEGWGzKxXui1uZYFBXFwZ1Wv1iMxl79gbqMbOmMxgyZP2O5jga5qyhvEjzlGsdM7ax93iDqjnVSu9Fi8q1/w==`
|
2023-10-27 18:28:54 +00:00
|
|
|
err := os.WriteFile(configPath, []byte(config), configFilePerms)
|
2021-10-22 18:41:17 +00:00
|
|
|
require.NoError(t, err)
|
2022-02-14 16:43:34 +00:00
|
|
|
|
|
|
|
_, err = runAppNoChecks([]string{"get", "queries", "--config", configPath})
|
|
|
|
require.ErrorIs(t, err, service.ErrUnauthenticated)
|
2021-10-22 18:41:17 +00:00
|
|
|
}
|