mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-02 06:08:23 +08:00
Converts most items to use servicecfg.Config.Logger instead of servicecfg.Config.Log. The deprecated logrus logger unfortunately cannot be removed yet as it's still used in e. Additionally all logging within the config package was converted to use slog.
82 lines
2.6 KiB
Go
82 lines
2.6 KiB
Go
/*
|
|
* Teleport
|
|
* Copyright (C) 2023 Gravitational, Inc.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package integration
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/gravitational/teleport/api/client"
|
|
"github.com/gravitational/teleport/integration/helpers"
|
|
"github.com/gravitational/teleport/lib/service/servicecfg"
|
|
"github.com/gravitational/teleport/lib/utils"
|
|
)
|
|
|
|
// TestClientWithExpiredCredentialsAndDetailedErrorMessage creates and connects to the Auth service
|
|
// using an expired user identity
|
|
// We should receive an error message which contains the real cause (ssh: handshake)
|
|
func TestClientWithExpiredCredentialsAndDetailedErrorMessage(t *testing.T) {
|
|
cfg := helpers.InstanceConfig{
|
|
ClusterName: "root.example.com",
|
|
HostID: uuid.New().String(),
|
|
NodeName: Loopback,
|
|
Logger: utils.NewSlogLoggerForTests(),
|
|
}
|
|
cfg.Listeners = helpers.SingleProxyPortSetup(t, &cfg.Fds)
|
|
rc := helpers.NewInstance(t, cfg)
|
|
|
|
rcConf := servicecfg.MakeDefaultConfig()
|
|
rcConf.DataDir = t.TempDir()
|
|
rcConf.Auth.Enabled = true
|
|
rcConf.Proxy.Enabled = true
|
|
rcConf.Proxy.DisableWebInterface = true
|
|
rcConf.SSH.Enabled = true
|
|
rcConf.Version = "v2"
|
|
|
|
username := helpers.MustGetCurrentUser(t).Username
|
|
rc.AddUser(username, []string{username})
|
|
|
|
err := rc.CreateEx(t, nil, rcConf)
|
|
require.NoError(t, err)
|
|
err = rc.Start()
|
|
require.NoError(t, err)
|
|
defer rc.StopAll()
|
|
|
|
// Create an expired identity file: ttl is 1 second in the past
|
|
identityFilePath := helpers.MustCreateUserIdentityFile(t, rc, username, -time.Second)
|
|
|
|
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Second)
|
|
defer cancelFunc()
|
|
_, err = client.New(ctx, client.Config{
|
|
Addrs: []string{rc.Auth},
|
|
Credentials: []client.Credentials{client.LoadIdentityFile(identityFilePath)},
|
|
DialOpts: []grpc.DialOption{
|
|
// ask for underlying errors
|
|
grpc.WithReturnConnectionError(),
|
|
},
|
|
})
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "ssh: handshake failed")
|
|
}
|