Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
  • Loading branch information
greedy52 committed Dec 11, 2024
1 parent 1cd0ec1 commit a5cb9a6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
1 change: 1 addition & 0 deletions lib/reversetunnel/localsite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ func Test_shouldDialAndForward(t *testing.T) {
},
nil,
)
require.NoError(t, err)
openSSHNode, err := types.NewNode(
"openssh",
types.SubKindOpenSSHNode,
Expand Down
30 changes: 13 additions & 17 deletions lib/srv/forward/sshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,12 @@ func (s *ServerConfig) CheckDefaults() error {
s.TracerProvider = tracing.DefaultProvider()
}

if s.component == "" {
switch {
case s.TargetServer != nil && s.TargetServer.GetKind() == types.KindGitServer:
s.component = teleport.ComponentForwardingGit
s.Emitter = git.NewEmitter(s.Emitter)
default:
s.component = teleport.ComponentForwardingNode
}
switch {
case s.TargetServer != nil && s.TargetServer.GetKind() == types.KindGitServer:
s.component = teleport.ComponentForwardingGit
s.Emitter = git.NewEmitter(s.Emitter)
default:
s.component = teleport.ComponentForwardingNode
}
return nil
}
Expand All @@ -345,7 +343,7 @@ func New(c ServerConfig) (*Server, error) {

s := &Server{
component: c.component,
logger: slog.With(teleport.ComponentKey, teleport.ComponentForwardingNode,
logger: slog.With(teleport.ComponentKey, c.component,
"src_addr", c.SrcAddr.String(),
"dst_addr", c.DstAddr.String(),
),
Expand Down Expand Up @@ -519,14 +517,10 @@ func (s *Server) GetHostSudoers() srv.HostSudoers {
return &srv.HostSudoersNotImplemented{}
}

// GetInfo returns a services.Server that represents this server.
// GetInfo returns a types.Server that represents this server.
func (s *Server) GetInfo() types.Server {
spec := types.ServerSpecV2{
Addr: s.AdvertiseAddr(),
}
if s.targetServer != nil {
spec.Hostname = s.targetServer.GetHostname()
spec.GitHub = s.targetServer.GetGitHub()
if s.component == teleport.ComponentForwardingGit && s.targetServer != nil {
return s.targetServer
}
return &types.ServerV2{
Kind: types.KindNode,
Expand All @@ -535,7 +529,9 @@ func (s *Server) GetInfo() types.Server {
Name: s.ID(),
Namespace: s.GetNamespace(),
},
Spec: spec,
Spec: types.ServerSpecV2{
Addr: s.AdvertiseAddr(),
},
}
}

Expand Down
17 changes: 17 additions & 0 deletions lib/srv/regular/sshserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,7 @@ func TestProxyRoundRobin(t *testing.T) {
Log: logger,
LockWatcher: lockWatcher,
NodeWatcher: nodeWatcher,
GitServerWatcher: newGitServerWatcher(ctx, t, proxyClient),
CertAuthorityWatcher: caWatcher,
CircuitBreakerConfig: breaker.NoopBreakerConfig(),
})
Expand Down Expand Up @@ -1814,6 +1815,7 @@ func TestProxyDirectAccess(t *testing.T) {
Log: logger,
LockWatcher: lockWatcher,
NodeWatcher: nodeWatcher,
GitServerWatcher: newGitServerWatcher(ctx, t, proxyClient),
CertAuthorityWatcher: caWatcher,
CircuitBreakerConfig: breaker.NoopBreakerConfig(),
})
Expand Down Expand Up @@ -2502,6 +2504,7 @@ func TestParseSubsystemRequest(t *testing.T) {
Log: logrus.StandardLogger(),
LockWatcher: lockWatcher,
NodeWatcher: nodeWatcher,
GitServerWatcher: newGitServerWatcher(ctx, t, proxyClient),
CertAuthorityWatcher: caWatcher,
})
require.NoError(t, err)
Expand Down Expand Up @@ -2766,6 +2769,7 @@ func TestIgnorePuTTYSimpleChannel(t *testing.T) {
Log: logger,
LockWatcher: lockWatcher,
NodeWatcher: nodeWatcher,
GitServerWatcher: newGitServerWatcher(ctx, t, proxyClient),
CertAuthorityWatcher: caWatcher,
})
require.NoError(t, err)
Expand Down Expand Up @@ -3105,6 +3109,18 @@ func newNodeWatcher(ctx context.Context, t *testing.T, client *authclient.Client
t.Cleanup(nodeWatcher.Close)
return nodeWatcher
}
func newGitServerWatcher(ctx context.Context, t *testing.T, client *authclient.Client) *services.GenericWatcher[types.Server, readonly.Server] {
watcher, err := services.NewGitServerWatcher(ctx, services.GitServerWatcherConfig{
ResourceWatcherConfig: services.ResourceWatcherConfig{
Component: "test",
Client: client,
},
GitServerGetter: client,
})
require.NoError(t, err)
t.Cleanup(watcher.Close)
return watcher
}

func newCertAuthorityWatcher(ctx context.Context, t *testing.T, client types.Events) *services.CertAuthorityWatcher {
caWatcher, err := services.NewCertAuthorityWatcher(ctx, services.CertAuthorityWatcherConfig{
Expand Down Expand Up @@ -3189,6 +3205,7 @@ func TestHostUserCreationProxy(t *testing.T) {
Log: logger,
LockWatcher: lockWatcher,
NodeWatcher: nodeWatcher,
GitServerWatcher: newGitServerWatcher(ctx, t, proxyClient),
CertAuthorityWatcher: caWatcher,
CircuitBreakerConfig: breaker.NoopBreakerConfig(),
})
Expand Down
4 changes: 2 additions & 2 deletions lib/srv/sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1481,8 +1481,8 @@ func newRecorder(s *session, ctx *ServerContext) (events.SessionPreparerRecorder
return events.WithNoOpPreparer(events.NewDiscardRecorder()), nil
}

// Don't record Git commands through Git proxy servers. Dedicated Git
// command events will be emitted.
// Git commands have no recordings. Dedicated Git command events will be
// emitted.
if s.registry.Srv.Component() == teleport.ComponentForwardingGit {
return events.WithNoOpPreparer(events.NewDiscardRecorder()), nil
}
Expand Down
20 changes: 20 additions & 0 deletions lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ func newWebSuiteWithConfig(t *testing.T, cfg webSuiteConfig) *WebSuite {
})
require.NoError(t, err)

proxyGitServerWatcher, err := services.NewGitServerWatcher(s.ctx, services.GitServerWatcherConfig{
ResourceWatcherConfig: services.ResourceWatcherConfig{
Component: teleport.ComponentProxy,
Client: s.proxyClient,
},
GitServerGetter: s.proxyClient,
})
require.NoError(t, err)

caWatcher, err := services.NewCertAuthorityWatcher(s.ctx, services.CertAuthorityWatcherConfig{
ResourceWatcherConfig: services.ResourceWatcherConfig{
Component: teleport.ComponentProxy,
Expand All @@ -410,6 +419,7 @@ func newWebSuiteWithConfig(t *testing.T, cfg webSuiteConfig) *WebSuite {
DataDir: t.TempDir(),
LockWatcher: proxyLockWatcher,
NodeWatcher: proxyNodeWatcher,
GitServerWatcher: proxyGitServerWatcher,
CertAuthorityWatcher: caWatcher,
CircuitBreakerConfig: breaker.NoopBreakerConfig(),
LocalAuthAddresses: []string{s.server.TLS.Listener.Addr().String()},
Expand Down Expand Up @@ -8177,6 +8187,15 @@ func createProxy(ctx context.Context, t *testing.T, proxyID string, node *regula
require.NoError(t, err)
t.Cleanup(proxyLockWatcher.Close)

proxyGitServerWatcher, err := services.NewGitServerWatcher(s.ctx, services.GitServerWatcherConfig{
ResourceWatcherConfig: services.ResourceWatcherConfig{
Component: teleport.ComponentProxy,
Client: s.proxyClient,
},
GitServerGetter: s.proxyClient,
})
require.NoError(t, err)

proxyNodeWatcher, err := services.NewNodeWatcher(ctx, services.NodeWatcherConfig{
ResourceWatcherConfig: services.ResourceWatcherConfig{
Component: teleport.ComponentProxy,
Expand All @@ -8202,6 +8221,7 @@ func createProxy(ctx context.Context, t *testing.T, proxyID string, node *regula
DataDir: t.TempDir(),
LockWatcher: proxyLockWatcher,
NodeWatcher: proxyNodeWatcher,
GitServerWatcher: proxyGitServerWatcher,
CertAuthorityWatcher: proxyCAWatcher,
CircuitBreakerConfig: breaker.NoopBreakerConfig(),
LocalAuthAddresses: []string{authServer.Listener.Addr().String()},
Expand Down

0 comments on commit a5cb9a6

Please sign in to comment.